Пример #1
0
 void setupCanvas() {
   canvas.addMouseListener(
       new MouseAdapter() {
         @Override
         public void mousePressed(MouseEvent e) {
           if (!canvas.board.isGameOver() && canvas.nextIsHuman()) {
             if (e.getPoint().y < HEIGHT && e.getPoint().x < HEIGHT) {
               if (0
                   < (e.getPoint().x - BoardCanvas.CHANGE_POS)
                       * (e.getPoint().y - BoardCanvas.CHANGE_POS)) {
                 int x = (e.getPoint().x - BoardCanvas.CHANGE_POS) / canvas.cell_size;
                 int y = (e.getPoint().y - BoardCanvas.CHANGE_POS) / canvas.cell_size;
                 int side = canvas.board.sideLength;
                 if (0 <= x && x < side && 0 <= y && y < side) canvas.click(x, y);
               }
             } else {
               int padding = 300;
               for (int color = 0; color < 2; color++) {
                 if (canvas.board.getNextPlayer() == color) {
                   if (1330 <= e.getPoint().x
                       && e.getPoint().x <= 1380
                       && 520 - color * padding <= e.getPoint().y
                       && e.getPoint().y <= 620 - color * padding) {
                     canvas.placeStone(Board.PASS_MOVE);
                   } else if (1330 <= e.getPoint().x
                       && e.getPoint().x <= 1380
                       && 620 - color * padding <= e.getPoint().y
                       && e.getPoint().y <= 720 - color * padding) {
                     canvas.placeStone(Board.RESIGN_MOVE);
                   }
                 }
               }
               update();
             }
           }
         }
       });
 }
Пример #2
0
 public void update() {
   canvas.re_display(canvas.getGraphics());
 }