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

aiturn

parent aa03e77a
No related branches found
No related tags found
1 merge request!2Fehler fix
......@@ -13,7 +13,7 @@ public class SceneController {
private Actor player;
private Actor enemy;
public boolean playerTurn = true;
public int playerTurn = 1;
public void initData(Board board, Actor player, Actor enemy) {
this.board = board;
......@@ -22,7 +22,7 @@ public class SceneController {
}
public void playerTurn(){
this.playerTurn = true;
this.playerTurn = 1;
turnlabel.setText("Your Turn");
}
......@@ -53,12 +53,30 @@ public class SceneController {
buttonList.add(button9);
}
public void aiTurn(int col, int row){
public void aiTurn(){
// AI's Turn
playerTurn = 0;
turnlabel.setText("AI's Turn");
int[] coordinates = enemy.makeMove(board);
// DEBUG
System.out.println("Enemy: " + coordinates[0] + ", " + coordinates[1]);
initialize();
buttonList.get(col + row).setText("o");
buttonList.get(coordinates[0] + coordinates[1]).setText("o");
playerTurn();
}
public void over(){
if(board.checkForWin()){
System.out.println("Game is over!");
if(playerTurn == 0){
turnlabel.setText("You win!");
}else if(playerTurn == 1){
turnlabel.setText("You lose!");
}
playerTurn = -1;
}
}
// Diese Funktion wird beim Button-Click aufgerufen
@FXML
......@@ -71,15 +89,16 @@ public class SceneController {
int row = GridPane.getRowIndex(pressedButton); // Zeilen-Koordinate
int col = GridPane.getColumnIndex(pressedButton); // Spalten-Koordinate
if(buttonText.equals(" ") && playerTurn) {
over();
if(buttonText.equals(" ") && playerTurn == 1) {
// Setze X
pressedButton.setText("X");
player.makeMove(board, col, row);
over();
// AI's Turn
playerTurn = false;
turnlabel.setText("AI's Turn");
aiTurn();
}
}
......
......@@ -42,30 +42,6 @@ public class TicTacToe extends Application {
launch(args);
while (!board.checkForWin()){
if (sceneController.playerTurn) {
// TODO Spieler ist am Zug
continue;
} else {
// TODO Gegner ist am Zug
int[] coordinates = enemy.makeMove(board);
// DEBUG
System.out.println("Enemy: " + coordinates[0] + ", " + coordinates[1]);
sceneController.aiTurn(coordinates[0], coordinates[1]);
}
// TODO Spielablauf
}
// TODO Spiel beenden
// TODO Gewinner verkünden
// TODO Option zum Neustart
}
}
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