/** constructor */ public GoEngine(int size) { int nBlock = promptSIZE(); window.setSize(nBlock * size, nBlock * size); window.add(gGUI); gBoard = new GoBoard(nBlock, nBlock, size); // window.add(gBoard = new GoBoard(nBlock, nBlock, size)); gGUI.initMapLog(gBoard); gGUI.initPlayerInfo(new GoPlayer[] {new GoPlayer(Color.BLACK), new GoPlayer(Color.WHITE)}); for (int row = 0; row < gBoard.HEIGHT; row++) { for (int col = 0; col < gBoard.WIDTH; col++) { gBoard.get(row, col).addActionListener(this); } } window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); window.pack(); }
@Override public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); int r = 0, c = 0; for (int row = 0; row < gBoard.HEIGHT; row++) { for (int col = 0; col < gBoard.WIDTH; col++) { if (gBoard.get(row, col) == button) { r = row; c = col; } } } String name = counter % 2 == 0 ? "Black" : "White"; gGUI.writeLog(name + ": (" + c + ", " + r + ")"); if (button.getBackground() == GoBoard.BOARD_COLOR) { button.setBackground(stoneColors[counter % 2]); for (int i = 1; i >= 0; i--) { for (int row = 0; row < gBoard.HEIGHT; row++) { for (int col = 0; col < gBoard.WIDTH; col++) { LinkedList<JButton> deadStones = findDeadStones(stoneColors[(counter + i) % 2], row, col); if (deadStones != null && deadStones.size() != 0) { for (JButton stone : deadStones) { stone.setBackground(GoBoard.BOARD_COLOR); } System.out.println(deadStones.size() + " was owned"); } } } } counter++; } System.out.println(counter); }