示例#1
0
  public void drawSketch(Graphics2D g2d, Sketch sketch, Symbol symbol) {

    List<List<SketchPoint>> allPoints = sketch.getAllPoints();
    Point2D.Float loc = new Float();
    Point2D.Float prevLoc = new Float();
    BasicStroke stroke;
    Color strokeColor = null;
    if (symbol.getClassName().equalsIgnoreCase("box")) {
      strokeColor = new Color(255, 0, 0, 255);
    } else if (symbol.getClassName().contains("arrow")) {
      strokeColor = new Color(0, 255, 0, 255);
    } else if (Character.isDigit(symbol.getClassName().charAt(0))) {
      strokeColor = new Color(0, 0, 255, 255);
    } else {
      strokeColor = new Color(255, 128, 0, 255);
    }
    for (int i = 0; i < allPoints.size(); i++) {
      List<SketchPoint> currentStroke = allPoints.get(i);
      loc.x = currentStroke.get(0).x;
      loc.y = currentStroke.get(0).y;
      for (int j = 1; j < currentStroke.size(); j++) {
        prevLoc.x = loc.x;
        prevLoc.y = loc.y;

        loc.x = currentStroke.get(j).x;
        loc.y = currentStroke.get(j).y;

        g2d.setColor(strokeColor);
        stroke = new BasicStroke(0.5f * 5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
        g2d.setStroke(stroke);
        g2d.draw(new Line2D.Float(prevLoc, loc));
      }
    }
  }
示例#2
0
  public int moveLevelTwo(Symbol symbol, int row, int column) {

    if (!gameBoard
        .isFull()) { // check the game has finished with condition of all the boxes are filled
      Status state = Status.EMPTY;

      if (symbol.getStatus() == Status.CROSS) {
        state = Status.RING;
      } else if (symbol.getStatus() == Status.RING) {
        state = Status.CROSS;
      }

      for (int m = 0; m < 3; m++) {
        for (int n = 0; n < 3; n++) {

          if (gameBoard.checkCellAvailability(m, n)) {

            if (gameBoard.setSymbol(
                new Symbol(state), m, n)) { // check wether other player wins at his move
              gameBoard.setEmpty(row, column);
              gameBoard.setEmpty(m, n);
              return -10;
            }
            gameBoard.setEmpty(m, n);
          }
        }
      }
    }

    return 0;
  }
示例#3
0
  public int moveLevelThree(Symbol symbol, int row, int column) {

    int ans = 0;
    int win;
    int tie;
    boolean isWin = false;
    boolean isTie = false;

    Status state = Status.EMPTY;

    if (!gameBoard.isFull()) {
      if (symbol.getStatus() == Status.CROSS) {
        state = Status.RING;
      } else if (symbol.getStatus() == Status.RING) {
        state = Status.CROSS;
      }

      for (int m = 0; m < 3; m++) {
        for (int n = 0; n < 3; n++) {

          if (gameBoard.checkCellAvailability(m, n)) {

            if (gameBoard.setSymbol(
                new Symbol(state), m, n)) { // check wether other player wins at his move
              gameBoard.setEmpty(row, column);
              gameBoard.setEmpty(m, n);
              return -10;
            } else {
              win = -10;
              tie = -10;
              int temp;

              for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {

                  temp = decideNext(new Symbol(symbol.getStatus()), i, j);

                  if (temp == 10) {
                    win = 10;
                    break;
                  } else if (temp == 0) {
                    tie = 0;
                  }
                  ans += temp;
                }
              }
              if (win < 0 && tie < 0) {
                gameBoard.setEmpty(m, n);
                gameBoard.setEmpty(row, column);
                return -10;
              } else if (win < 0) {
                isTie = true;
              } else {
                isWin = true;
              }
            }
            gameBoard.setEmpty(m, n);
          }
        }
      }

      gameBoard.setEmpty(row, column);

      if (isTie) {
        return 0;
      }
      if (isWin) {
        return 10;
      }
    }
    return ans;
  }
示例#4
0
 public void drawSymbol(Graphics2D g2d, Symbol newSymbol) {
   Rectangle pos = newSymbol.getPosition();
   g2d.drawImage(getImage(newSymbol.getClassName()), pos.x, pos.y, pos.width, pos.height, null);
 }