|
|
@ -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) { |
|
|
|
|
|
|
|