The following repository contains an implementation of the Tic-Tac-Toe game in Java, utilizing the Swing and AWT libraries. The game is created within a single class called KolkoKrzyzyk, which implements the ActionListener interface.
- The game uses JFrame as the main window, as well as JPanel for the title and buttons.
- Informational text is displayed using JLabel.
- The game buttons are represented by a JButton array of size 9, corresponding to a 3x3 grid in Tic-Tac-Toe.
The KolkoKrzyzyk constructor configures the main game window, setting properties like size, background color, and layout of elements. Buttons are initialized, configured, and added to the button panel. The firstTurn() method is called to randomly choose which player starts.
The actionPerformed() method defines the game logic after a button is pressed. It checks which player's turn it is, updates the state of the button, and switches turns.
The check() method verifies the winning conditions for both players. In the event of a player's victory, the relevant buttons are highlighted, and the game ends.
The xWins() and oWins() methods are invoked when one of the players wins. They change the color of the winning buttons and display a victory message.
- Install Git on your computer (if you haven't already).
- Open the terminal (Git Bash for Windows, standard terminal for macOS/Linux).
- Type in the terminal:
https://github.com/WiolaWysopal/TicTacToe.git
.
- Launch your IDE (e.g., IntelliJ IDEA, Visual Studio Code).
- Open or import the downloaded game repository.
- Ensure you have Java installed and configured in the IDE.
- Find the main game file (e.g.,
Main
) in the project. - Run project using Run option (or similar).