Example #1
0
 public void reset() {
   board = new GameBoard(7, 6);
   control = new Control();
   player1 = new Player(1);
   player2 = null;
   difficulty = 0;
   image.draw(board);
   run();
 }
Example #2
0
  public void run() {
    new AIChooseDialog(this);
    switch (difficulty) {
      case 0:
        player2 = new AIRandom(2);
        break;
      case 1:
        player2 = new AIMedium(2);
        break;
      case 2:
        player2 = new AIHard(2);
        break;
      default:
        player2 = new AIRandom(2);
        break;
    }
    startTime = (int) System.currentTimeMillis() / 1000;
    image.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            int column = 0;
            if (e.getX() < 100) {
              column = 0;
            } else if (e.getX() > 99 && e.getX() < 200) {
              column = 1;
            } else if (e.getX() > 199 && e.getX() < 300) {
              column = 2;
            } else if (e.getX() > 299 && e.getX() < 400) {
              column = 3;
            } else if (e.getX() > 399 && e.getX() < 500) {
              column = 4;
            } else if (e.getX() > 499 && e.getX() < 600) {
              column = 5;
            } else if (e.getX() > 599 && e.getX() < 700) {
              column = 6;
            } else if (e.getX() > 699 && e.getX() < 800) {
              column = 7;
            }
            player1.move(board, control, column);
            checkComplete(board, control, 1);
            player2.move(board, control);
            checkComplete(board, control, 2);
            image.draw(board);
          }

          public void checkComplete(GameBoard board, Control control, int player) {
            if (board.full()) {
              System.out.println("Full");
              new DialogGameDone(false, control, myGame, player, startTime);
            }
            if (control.check_game_win(board)) {
              System.out.println("Won");
              new DialogGameDone(true, control, myGame, player, startTime);
            }
          }

          @Override
          public void mouseEntered(MouseEvent arg0) {}

          @Override
          public void mouseExited(MouseEvent arg0) {}

          @Override
          public void mousePressed(MouseEvent arg0) {}

          @Override
          public void mouseReleased(MouseEvent arg0) {}
        });
    board.setMessage("Please click on the board to place your marker");
    image.draw(board);
  }