Skip to content
Snippets Groups Projects
Commit ee702ad9 authored by Nick's avatar Nick
Browse files

Restart und Draw

parent 02d25b6a
No related branches found
No related tags found
1 merge request!2Fehler fix
......@@ -27,18 +27,18 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="button1" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="0" GridPane.halignment="CENTER" GridPane.columnIndex="0" GridPane.valignment="CENTER" />
<Button fx:id="button2" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="0" GridPane.columnIndex="1" />
<Button fx:id="button3" layoutX="115.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="0" GridPane.columnIndex="2" />
<Button fx:id="button4" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="1" GridPane.columnIndex="0" />
<Button fx:id="button5" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="1" GridPane.columnIndex="1" />
<Button fx:id="button6" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="1" GridPane.columnIndex="2" />
<Button fx:id="button7" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="2" GridPane.columnIndex="0" />
<Button fx:id="button8" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="2" GridPane.columnIndex="1" />
<Button fx:id="button9" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.rowIndex="2" GridPane.columnIndex="2" />
<Button fx:id="button1" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="0" GridPane.halignment="CENTER" GridPane.rowIndex="0" GridPane.valignment="CENTER" />
<Button fx:id="button2" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="1" GridPane.rowIndex="0" />
<Button fx:id="button3" layoutX="115.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="2" GridPane.rowIndex="0" />
<Button fx:id="button4" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="0" GridPane.rowIndex="1" />
<Button fx:id="button5" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button fx:id="button6" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="2" GridPane.rowIndex="1" />
<Button fx:id="button7" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="0" GridPane.rowIndex="2" />
<Button fx:id="button8" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Button fx:id="button9" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleButtonClick" prefHeight="133.0" prefWidth="142.0" text=" " GridPane.columnIndex="2" GridPane.rowIndex="2" />
</children>
</GridPane>
<Button layoutX="446.0" layoutY="170.0" mnemonicParsing="false" prefHeight="30.0" prefWidth="82.0" text="Restart" />
<Button layoutX="446.0" layoutY="170.0" mnemonicParsing="false" onAction="#restartGame" prefHeight="30.0" prefWidth="82.0" text="Restart" />
<Label fx:id="turnlabel" alignment="CENTER" contentDisplay="CENTER" layoutX="409.0" layoutY="263.0" prefHeight="30.0" prefWidth="156.0" text="Your Turn" textAlignment="CENTER">
<font>
<Font name="Ink Free" size="25.0" />
......
......@@ -13,6 +13,8 @@ public class SceneController {
private Actor player;
private Actor enemy;
private int moves = 0;
public int playerTurn = 1;
public void initData(Board board, Actor player, Actor enemy) {
......@@ -82,6 +84,17 @@ public class SceneController {
}
}
@FXML
private void restartGame(ActionEvent event) {
initData( new Board(),this.player, this.enemy);
moves = 0;
playerTurn = 1;
initialize();
for(int i = 0; i < buttonList.size(); i++){
buttonList.get(i).setText(" ");
}
}
// Diese Funktion wird beim Button-Click aufgerufen
@FXML
private void handleButtonClick(ActionEvent event) {
......@@ -98,13 +111,18 @@ public class SceneController {
if(buttonText.equals(" ") && playerTurn == 1) {
// Setze X
pressedButton.setText("X");
moves++;
player.makeMove(board, col, row);
playerTurn = 0;
over();
if(moves == 9){
turnlabel.setText("Draw!");
playerTurn = -1;
}
if(playerTurn == 0){
aiTurn();
moves++;
over();
}
board.printBoard();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment