Tic-Tac-Toe Spring is a Java Spring Boot web application developed for educational purposes.
The main function of the application is to allow users to play a Tic-Tac-Toe game locally on the same computer using HTTP requests. The application features a front-end interface that interacts with the back-end API, providing a user-friendly experience for players.
For the front-end of the Tic-Tac-Toe game, you can find the repository here:
Tic-Tac-Toe Front End Repository
- Java (Spring Boot)
- MySQL
- JavaScript
- HTML
- CSS
- IDE for Java (Spring Tool Suite recommended)
- Java 17
-
Clone the Repository
git clone git@github.com:EltonC06/TicTacToeSpring.git
-
Open the Project
- Open the project in a Java IDE with Spring Boot support (Spring Tool Suite is recommended).
-
Configure the Database
- To set up your MySQL database, navigate to
src/main/resources/application.propertiesand enter your datasource URL, username and password.
- To set up your MySQL database, navigate to
-
Run the Application
- In your IDE, click to run the application.
-
Testing the Application
- You can use an HTTP client like Postman to interact with the API endpoints.
The project contains two main entities:
-
TicTacToe: This entity manages the gameplay and logic for each round of the TicTacToe game. It handles the state of the board and determines the winner or if a round ends in a draw. The attributes of the TicTacToe entity include:
id: Unique identifier of the game.firstLine: Represents the current state of the first row of the board.secondLine: Represents the current state of the second row of the board.thirdLine: Represents the current state of the third row of the board.isRunning: Indicates whether the game is currently active.roundWinner: Displays the winner of the round or indicates if it ended in a draw.Match: A OneToOne relationship with theMatchentity.
-
Match: This entity serves as a counter for all the games (rounds) played. It tracks the total number of victories for each player, draws, and the number of rounds played. The attributes of the
Matchentity include:id: Unique identifier of the match.xVictories: Number of victories for player X.oVictories: Number of victories for player O.draws: Number of rounds that ended in a draw.roundsPlayed: Total number of rounds played.ticTacToe: A OneToOne relationship with theTicTacToeentity.
Here are the main endpoints available for interacting with the application:
-
Get Game
- Method:
GET - URL:
<host>:<port>/games/{matchId} - Description: Returns the current Tic-Tac-Toe game. Replace and with your application's host and port. (default: localhost:8080)
- Method:
-
Make Move
- Method:
PUT - URL:
localhost:8080/games/play/{matchId}/{position} - Description: Makes a move and places the piece on the given position. The turn alternates automatically between 'X' and 'O'.
- Method:
-
Restart Game
- Method:
PUT - URL:
localhost:8080/games/restart/{matchId} - Description: Resets the current game, allowing you to play again without creating a new match.
- Method:
-
Get Match
- Method:
GET - URL:
localhost:8080/match/{matchId} - Description: Retrieves the current match details, including the round statistics and linked TicTacToe game.
- Method:
-
Create Match
- Method:
POST - URL:
localhost:8080/match/create - Description: Creates a new match and initializes a Tic-Tac-Toe game. This should be the first endpoint called to start a series of games.
- Method:
-
Reset Match
- Method:
PUT - URL:
localhost:8080/match/reset/{matchId} - Description: Resets the match, clearing the counters for victories, draws, and rounds, and resets the linked TicTacToe game.
- Method:
- The Match Id is returned in response when a Match is created.
- The application is designed for local play and features a front-end interface that interacts with the back-end API.
- The game state and moves are managed entirely through the HTTP requests between the front-end and back-end.
- Enhance the game logic and add additional features, such as improving the match statistics and tracking multiple games.
Elton da Costa Oliveira