Skip to content

Commit

Permalink
TicTacToe game
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsygn committed Dec 18, 2022
1 parent 28f2f8b commit ea49de0
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 7 deletions.
6 changes: 0 additions & 6 deletions Java-Mini-Projects/game/pong/PongGame.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
package game.pong;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class PongGame {
public static void main(String[] args) {

Expand Down
1 change: 0 additions & 1 deletion Java-Mini-Projects/game/snake/SnakeGame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package game.snake;

public class SnakeGame {
public static void main(String[] args) {

Expand Down
9 changes: 9 additions & 0 deletions Java-Mini-Projects/game/tictactoe/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package game.tictactoe;

public class Main {

public static void main(String[] args)
{
TicTacToe ticTacToe = new TicTacToe();
}
}
88 changes: 88 additions & 0 deletions Java-Mini-Projects/game/tictactoe/TicTacToe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package game.tictactoe;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class TicTacToe implements ActionListener{

Random random = new Random();
JFrame frame = new JFrame();
JPanel title_panel = new JPanel();
JPanel button_panel = new JPanel();
JLabel textfield = new JLabel();
JButton[] buttons = new JButton[9];
boolean player1_turn;
// boolean player2_turn;

TicTacToe()
{
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 800);
frame.getContentPane().setBackground(new Color(50, 50, 50));
frame.setLayout(new BorderLayout());
frame.setVisible(true);

textfield.setBackground(new Color(25,25,25));
textfield.setForeground(new Color(25,255,0));
textfield.setFont(new Font("Ink Free", Font.BOLD, 75));
textfield.setHorizontalAlignment(JLabel.CENTER);
textfield.setText("Tic-Tac-Toe");
textfield.setOpaque(true);

title_panel.setLayout(new BorderLayout());
title_panel.setBounds(0, 0, 800, 800);

button_panel.setLayout(new GridLayout(3, 3));
button_panel.setBackground(new Color(150,150,150));

title_panel.add(textfield);
frame.add(title_panel, BorderLayout.NORTH);
frame.add(button_panel);

for (int i = 0; i < 9; i++) {
buttons[i] = new JButton();
button_panel.add(buttons[i]);
buttons[i].setFont(new Font("MV Boli", Font.BOLD, 120));
buttons[i].setFocusable(false);
buttons[i].addActionListener(this);
}
}

@Override
public void actionPerformed(ActionEvent e)
{
//TODO Auto-generated method stub
}

public void firstTurn()
{
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

if (random.nextInt(2) == 0) {
player1_turn = true;
textfield.setText("X turn");
} else {
player1_turn = false;
textfield.setText("O turn");
}
}

public void check() {

}

public void xWins(int a, int b, int c) {

}

public void oWins(int a, int b, int c)
{

}
}

0 comments on commit ea49de0

Please sign in to comment.