Browse Source

Tic Tac Toe creating method to start the game

remotes/origin/develop
fdai6040 2 years ago
parent
commit
08f11d684c
  1. 34
      src/main/java/src/TicTacToeGame.java

34
src/main/java/src/TicTacToeGame.java

@ -10,6 +10,8 @@ public class TicTacToeGame implements ActionListener {
JPanel bt_panel = new JPanel();
JLabel textfield = new JLabel();
JButton[] bton = new JButton[9];
Random random = new Random();
boolean pl1_chance;
// Creating class constructor
@ -49,8 +51,40 @@ public class TicTacToeGame implements ActionListener {
frame.add(t_panel, BorderLayout.NORTH);
frame.add(bt_panel);
startGame();
}
// Creating method to start the game and decide the chance
public void startGame()
{
try
{
textfield.setText("Loading...");
Thread.sleep(4000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
int chance=random.nextInt(100);
if (chance%2 == 0)
{
pl1_chance = true;
textfield.setText("Player X turn");
}
else
{
pl1_chance = false;
textfield.setText("Player O turn");
}
}
//Method for perfoming action after every turn
@Override
public void actionPerformed(ActionEvent e) {

Loading…
Cancel
Save