Skip to content

Commit ea49de0

Browse files
committed
TicTacToe game
1 parent 28f2f8b commit ea49de0

File tree

4 files changed

+97
-7
lines changed

4 files changed

+97
-7
lines changed

Java-Mini-Projects/game/pong/PongGame.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
package game.pong;
2-
3-
import java.awt.*;
4-
import java.awt.event.*;
5-
import java.util.*;
6-
import javax.swing.*;
7-
82
public class PongGame {
93
public static void main(String[] args) {
104

Java-Mini-Projects/game/snake/SnakeGame.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package game.snake;
2-
32
public class SnakeGame {
43
public static void main(String[] args) {
54

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package game.tictactoe;
2+
3+
public class Main {
4+
5+
public static void main(String[] args)
6+
{
7+
TicTacToe ticTacToe = new TicTacToe();
8+
}
9+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package game.tictactoe;
2+
3+
import java.awt.*;
4+
import java.awt.event.*;
5+
import java.util.*;
6+
import javax.swing.*;
7+
8+
public class TicTacToe implements ActionListener{
9+
10+
Random random = new Random();
11+
JFrame frame = new JFrame();
12+
JPanel title_panel = new JPanel();
13+
JPanel button_panel = new JPanel();
14+
JLabel textfield = new JLabel();
15+
JButton[] buttons = new JButton[9];
16+
boolean player1_turn;
17+
// boolean player2_turn;
18+
19+
TicTacToe()
20+
{
21+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22+
frame.setSize(800, 800);
23+
frame.getContentPane().setBackground(new Color(50, 50, 50));
24+
frame.setLayout(new BorderLayout());
25+
frame.setVisible(true);
26+
27+
textfield.setBackground(new Color(25,25,25));
28+
textfield.setForeground(new Color(25,255,0));
29+
textfield.setFont(new Font("Ink Free", Font.BOLD, 75));
30+
textfield.setHorizontalAlignment(JLabel.CENTER);
31+
textfield.setText("Tic-Tac-Toe");
32+
textfield.setOpaque(true);
33+
34+
title_panel.setLayout(new BorderLayout());
35+
title_panel.setBounds(0, 0, 800, 800);
36+
37+
button_panel.setLayout(new GridLayout(3, 3));
38+
button_panel.setBackground(new Color(150,150,150));
39+
40+
title_panel.add(textfield);
41+
frame.add(title_panel, BorderLayout.NORTH);
42+
frame.add(button_panel);
43+
44+
for (int i = 0; i < 9; i++) {
45+
buttons[i] = new JButton();
46+
button_panel.add(buttons[i]);
47+
buttons[i].setFont(new Font("MV Boli", Font.BOLD, 120));
48+
buttons[i].setFocusable(false);
49+
buttons[i].addActionListener(this);
50+
}
51+
}
52+
53+
@Override
54+
public void actionPerformed(ActionEvent e)
55+
{
56+
//TODO Auto-generated method stub
57+
}
58+
59+
public void firstTurn()
60+
{
61+
try {
62+
Thread.sleep(2000);
63+
} catch (InterruptedException e) {
64+
e.printStackTrace();
65+
}
66+
67+
if (random.nextInt(2) == 0) {
68+
player1_turn = true;
69+
textfield.setText("X turn");
70+
} else {
71+
player1_turn = false;
72+
textfield.setText("O turn");
73+
}
74+
}
75+
76+
public void check() {
77+
78+
}
79+
80+
public void xWins(int a, int b, int c) {
81+
82+
}
83+
84+
public void oWins(int a, int b, int c)
85+
{
86+
87+
}
88+
}

0 commit comments

Comments
 (0)