Commit e21e43e9 authored by jordan.dalby's avatar jordan.dalby

+ Added restart button

parent b60e53bf
......@@ -21,7 +21,6 @@ public class Main extends Application
private Turn currentTurn = Turn.CROSSES;
private boolean gameOver = false;
private boolean firstTurn = true;
private Random random = new Random();
......@@ -84,6 +83,20 @@ public class Main extends Application
label.setPrefHeight(128);
label.setPrefWidth(256);
Button button = new Button();
button.setText("Restart");
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent arg0)
{
restart();
}
});
pane.add(button, 128*5, 128*4);
winLabel = label;
pane.add(label, 128*4, 128*4);
......@@ -94,6 +107,17 @@ public class Main extends Application
s.show();
}
public void restart()
{
gameOver = false;
currentTurn = Turn.CROSSES;
for (Button b : buttons)
{
b.setStyle("-fx-font-size:40");
b.setText("");
}
}
public void updateButton(Button button)
{
if (gameOver)
......@@ -172,21 +196,6 @@ public class Main extends Application
{
// AI PRIORITISES AGGRESSION BUT CAN ALSO BE VERY DEFENSIVE
if (firstTurn)
{
firstTurn = false;
int i = -1;
int count = 0;
while (!isSlotAvailable(i) && count < 100000)
{
count ++;
i = random.nextInt(buttons.size());
}
updateButton(buttons.get(i));
}
else
{
String turnCheck = "";
String opponentCheck = "";
......@@ -252,8 +261,6 @@ public class Main extends Application
}
updateButton(buttons.get(i));
}
}
public void checkForWin()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment