/** * Continues dragging a piece. * * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent) */ @Override public void mouseDragged(MouseEvent e) { int x; int y; if (pieceBeingDragged == null) return; // Don't allow drag outside board boundaries int maxX = board.columnToX(board.getColumns() - 1); int maxY = board.rowToY(board.getRows() - 1); x = e.getX() - board.getCellWidth() / 2; if (x < 0) { x = 0; } else { if (x > maxX) x = maxX; } y = e.getY() - board.getCellHeight() / 2; if (y < 0) { y = 0; } else { if (y > maxY) y = maxY; } pieceBeingDragged.x = x; pieceBeingDragged.y = y; // Track mouse movement pieceBeingDragged.setChanged(); pieceBeingDragged.notifyObservers(); }
public void loadGame() { this.stopped = true; this.board = Globals.game.getBoard(); this.enemies = Globals.game.getEnemies(); this.setBounds(0, 0, board.getColumns() * TILE_WIDTH, board.getRows() * TILE_HEIGHT + 20); newGame(); }
@Override public void setMove(Board board) { int move = 0; board.printBoard(); System.out.print("Computer player " + getPlayerToken() + " make move:"); do { move = randomNumber.nextInt(board.getColumns()); } while ((board.getCell(move, 0) != Token.EMPTY)); board.setCellValue(move, getPlayerToken()); System.out.println(move); }
/** * @param enemies An array of the different enemies * @param board The current board (level) */ public LevelCanvas(Enemy[] enemies, Board board) { super(); this.enemies = enemies; this.player = Globals.game.getPlayer(); this.board = board; this.stopped = false; this.waiting = true; this.addKeyListener(this); this.setIgnoreRepaint(true); this.setBounds(0, 0, board.getColumns() * TILE_WIDTH, board.getRows() * TILE_HEIGHT + 20); this.addFocusListener( new FocusListener() { public void focusLost(FocusEvent e) { update(); } public void focusGained(FocusEvent e) { update(); } }); }