public void playerTurn(MouseEvent event) { int spot = -1; String playerMarker = player.getPlayerMarker(); if (event.getSource().equals(lblSpot1)) { lblSpot1.setText(playerMarker); spot = 0; lblSpot1.setDisable(true); } else if (event.getSource() == lblSpot2) { lblSpot2.setText(playerMarker); spot = 1; lblSpot2.setDisable(true); } else if (event.getSource() == lblSpot3) { lblSpot3.setText(playerMarker); spot = 2; lblSpot3.setDisable(true); } else if (event.getSource() == lblSpot4) { lblSpot4.setText(playerMarker); spot = 3; lblSpot4.setDisable(true); } else if (event.getSource() == lblSpot5) { lblSpot5.setText(playerMarker); spot = 4; lblSpot5.setDisable(true); } else if (event.getSource() == lblSpot6) { lblSpot6.setText(playerMarker); spot = 5; lblSpot6.setDisable(true); } else if (event.getSource() == lblSpot7) { lblSpot7.setText(playerMarker); spot = 6; lblSpot7.setDisable(true); } else if (event.getSource() == lblSpot8) { lblSpot8.setText(playerMarker); spot = 7; lblSpot8.setDisable(true); } else if (event.getSource() == lblSpot9) { lblSpot9.setText(playerMarker); spot = 8; lblSpot9.setDisable(true); } playboard.placeMarker(spot, playerInternalMarker); playboard.showBoardStatus(); if (playboard.checkForWin(playerInternalMarker)) { endGame("Human"); } else { computerMove(false); } }
@FXML public void newGame() { hboxNewGame.setVisible(false); hboxMarkerChoice.setVisible(true); hboxUserMessages.setVisible(false); playboard = new Board(); playboard.initPlayingBoard(); player = new Player(); computer = new Computer(); }
public void computerMove(boolean moveFirst) { int spot = -1; String computerMarker = computer.getComputerMarker(); // If computer first pick middle // pause(); if (moveFirst) { spot = 4; playboard.placeMarker(spot, computerInternalMarker); lblSpot5.setText(computerMarker); lblSpot5.setDisable(true); } else { spot = playboard.scanBestMove(); System.out.println(spot); playboard.placeMarker(spot, computerInternalMarker); // pause(); if (spot == 0) { lblSpot1.setText(computerMarker); lblSpot1.setDisable(true); } if (spot == 1) { lblSpot2.setText(computerMarker); lblSpot2.setDisable(true); } if (spot == 2) { lblSpot3.setText(computerMarker); lblSpot3.setDisable(true); } if (spot == 3) { lblSpot4.setText(computerMarker); lblSpot4.setDisable(true); } if (spot == 4) { lblSpot5.setText(computerMarker); lblSpot5.setDisable(true); } if (spot == 5) { lblSpot6.setText(computerMarker); lblSpot6.setDisable(true); } if (spot == 6) { lblSpot7.setText(computerMarker); lblSpot7.setDisable(true); } if (spot == 7) { lblSpot8.setText(computerMarker); lblSpot8.setDisable(true); } if (spot == 8) { lblSpot9.setText(computerMarker); lblSpot9.setDisable(true); } } // playboard.showBoardStatus(); if (playboard.checkForWin(computerInternalMarker)) { System.out.println("I am here"); endGame("Computer"); } else { // Update display to indicate it players turn } }