Exemple #1
0
  void getCoordinates() {
    for (int i = 0; i < bst.getOrder(); i++) {
      for (int j = 0; j < bst.getOrder(); j++) {
        data.a[i][j] = new Block();
        data.a[i][j].i = i;
        data.a[i][j].j = j;
        double x = data.a[i][j].x = x0 + r3 * bst.scale * j;
        double y = data.a[i][j].y = y0 + i * bst.scale * 1.5;

        data.a[i][j].polyX =
            new double[] {
              x,
              x - r3 * 0.5 * bst.scale,
              x - r3 * 0.5 * bst.scale,
              x,
              x + r3 * 0.5 * bst.scale,
              x + r3 * 0.5 * bst.scale
            };
        data.a[i][j].polyY =
            new double[] {
              y - bst.scale,
              y - 0.5 * bst.scale,
              y + 0.5 * bst.scale,
              y + bst.scale,
              y + 0.5 * bst.scale,
              y - 0.5 * bst.scale
            };
      }
      x0 -= r3 * 0.5 * bst.scale;
    }
  }
Exemple #2
0
  void newGame() {
    ptm = null;
    NewGame ngd = new NewGame(this);
    ngd.setVisible(true);
    if (ngd.gst == null) {
      if (firstrun) {
        bst = new BoardSettings();
        gst = new GameSettings();
        bst.setOrder(13);
        gst.setType(0);
        gst.swap = false;
        firstrun = false;
      } else return;
    } else {
      bst = ngd.bst;
      gst = ngd.gst;
      firstrun = false;
    }

    bst.findScale(getSize());
    x0 = bst.scale * r3 * (bst.getOrder() + 4) / 2;
    y0 = bst.scale * r3 * 2 + 50;

    data = new GameData(bst.getOrder());
    getCoordinates();
    /*if(gst.ai!=null)
    {
        gst.ai.flush();
        gst.ai.start();
    }*/
    gameActive = true;
    count = 0;
    lmv = null;
    AIMethods.init(bst.getOrder());
    if (gst.getType() == GameSettings.HUMAN_VS_AI) {
      if (gst.ai == null) gst.ai = new MiniMax(bst.getOrder(), (cst == 1) ? 2 : 1);
      gst.ai.init(this);
      userMove = true;
    }
    AePlayWave.q.clear();
    if (gst.audio) AePlayWave.play(AePlayWave.START);
    repaint();
  }
Exemple #3
0
  public void drawHexBoard(Graphics g) {
    g.setColor(Color.BLACK);
    double mx1, mx2, mx3, mx4, my1, my2, my3, my4; // Margin attributes

    mx1 = data.a[0][0].x - bst.scale * (r3 / 2 + 0.5);
    mx2 = data.a[0][bst.getOrder() - 1].x + bst.scale * (r3 + 1);
    mx3 = data.a[bst.getOrder() - 1][0].x - bst.scale * (r3 + 1);
    mx4 = data.a[bst.getOrder() - 1][bst.getOrder() - 1].x + bst.scale * (r3 / 2 + 0.5);
    my1 = data.a[0][0].y - bst.scale * 1.5;
    my2 = data.a[0][bst.getOrder() - 1].y - bst.scale * 1.5;
    my3 = data.a[bst.getOrder() - 1][0].y + bst.scale * 1.5;
    my4 = data.a[bst.getOrder() - 1][bst.getOrder() - 1].y + bst.scale * 1.5;

    g.fillPolygon(
        getIntArray(new double[] {mx1, mx2, mx4, mx3}),
        getIntArray(new double[] {my1, my2, my4, my3}),
        4);
    switch (gst.theme) {
      case 0:
        g.setColor(Color.RED);
        break;
      case 1:
        g.setColor(Color.BLACK);
        break;
      case 2:
        g.setColor(Color.YELLOW);
        break;
    }
    g.fillPolygon(
        getIntArray(new double[] {mx1 + 1, mx3 + 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my1 + 1, my3 - 1, (my2 + my3) / 2}),
        3);
    g.fillPolygon(
        getIntArray(new double[] {mx2 - 1, mx4 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my2 + 1, my4 - 1, (my2 + my3) / 2}),
        3);
    switch (gst.theme) {
      case 0:
        g.setColor(Color.BLUE);
        break;
      case 1:
        g.setColor(new Color(1, 175, 1));
        break;
      case 2:
        g.setColor(Color.lightGray);
    }
    g.fillPolygon(
        getIntArray(new double[] {mx1 + 1, mx2 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my1 + 1, my2 + 1, (my2 + my3) / 2}),
        3);
    g.fillPolygon(
        getIntArray(new double[] {mx3 + 1, mx4 - 1, (mx2 + mx3) / 2}),
        getIntArray(new double[] {my3 - 1, my4 - 1, (my2 + my3) / 2}),
        3);

    for (int i = 0; i < bst.getOrder(); i++)
      for (int j = 0; j < bst.getOrder(); j++) {
        g.setColor(Color.BLACK);
        g.fillPolygon(getIntArray(data.a[i][j].polyX), getIntArray(data.a[i][j].polyY), 6);
        g.setColor(Color.WHITE);
        g.fillPolygon(getIntArray(data.a[i][j].polyXIn()), getIntArray(data.a[i][j].polyYIn()), 6);
        g.setColor(Color.BLACK);
        double x = data.a[i][j].x, y = data.a[i][j].y;
        g.drawLine((int) x, (int) y, (int) x + 1, (int) y + 1);
        circle(g, x, y, data.a[i][j].getState());
      }
    if (ptm == null) return;
    if (ptm.length == 0) return;
    for (int i = 0; i < ptm.length; i++) {
      g.setColor(Color.YELLOW);
      g.fillPolygon(
          getIntArray(data.a[ptm[i][0]][ptm[i][1]].polyXIn()),
          getIntArray(data.a[ptm[i][0]][ptm[i][1]].polyYIn()),
          6);
      g.setColor(Color.BLACK);
      double x = data.a[ptm[i][0]][ptm[i][1]].x, y = data.a[ptm[i][0]][ptm[i][1]].y;
      circle(g, x, y, data.a[ptm[i][0]][ptm[i][1]].getState());
    }
  }