Skip to content

A simple command-line based Tic-Tac-Toe game with single and multiplayer mode

Notifications You must be signed in to change notification settings

x-tr4ce/tic-tac-toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tic-Tac-Toe (Student Programming Project December 2023)

How to start the game

To start the game, you have to run the main method in the Main class of the Project.

How to run the Unit Tests

To run the Unit Tests, you can right-click on the test folder and select "Run 'Tests in 'testing''".

Game Instructions

To play the game, you have to enter the number of the field you want to place your symbol in.
The field-numbers are as follows:
"""
+-+--+-+
| 1 | 2 | 3 |
+-+--+-+
| 4 | 5 | 6 |
+-+--+-+
| 7 | 8 | 9 |
+-+--+-+
"""
To change the language, enter these commands:
de --> for german or
en --> for english.
To exit the game, enter:
exit

Game flow

The game starts by asking the user which language is preferred (german / english).
The user can then select if he wants to play in Singleplayer mode or in Multiplayer moder.
In the singelplayer mode the player can choose between two difficulty settings (easy / hard)
After set a playername the player will be play a game against a easy or hard computer opponent.
At the end of each game the player can choose to play another round or to leave the game.
In the multiplayer mode the two player can choose a own name.
Following the two player will play a game against each other.
At the end of each game the two player can choose to play another round or to leave the game.
In case of another round always the player lost the previous round can start the game.
In order to change between the two Gamemodes, the difficulty settings (in Singelplayer mode only) or the playername the game has to be restarted.
In most situations can the command "help" be used to show the Game Instructions and valid inputs.
Also in most situations can the command "exit" be used to leave the game.

Classmodell

Klassenmodell

Difference from the class diagram:

  • The Game class has been fundamentally revised and narrowed down:
    A large part of the content of the Game class was divided and converted into 2 new classes:
    Multiplayer class has the same features as the former Game class.
    Single player class contains some of the same components as the multiplayer class, but also includes the control and management of the of the minimax algorithm (our AI opponent).
  • The game class now only manages the start of the game and the call whether a single player game or a multiplayer game should be played.
  • The Opponent class has been added. It contains the same features as the Player class but optimized for AI. it also includes
    the implementation of the minimax algorithm (which is responsible for the next best move).
  • 4 different test classes were also added:
    Board test includes JUnit test for the behavior of the board class with different input values.
    TranslatorTest contains JUnit tests to test the behavior of the Translator class with different input values.
    UserInputTest contains JUnit tests to test the behavior of the UserInput class with different input values.
    OpponentTest contains JUnit tests to test the behavior of the Opponent class with different input values in different game situations.

Description of the new / changed classes:
- The Game class takes over the administration and the call when starting the Multiplayer & Singleplayer classes.
Game interacts with the classes: UserInput, Singleplayer, Multiplayer and OutputPrinter.

UserInput: Query the input via the UserInput
class OutputPrinter: Delegation of console output
Multiplayer: Call the multiplayer class
Singleplayer: Calling the singleplayer class

- The Multiplayer class takes over the “organization” of the game.
Multiplayer interacts with the classes: Game, Player, Board, UserInput and OutputPrinter.

Game: Called by Game
Player: Query and manage player variables
Board: Control of the playing field
UserInput: Query the input via the UserInput
class OutputPrinter: Delegation of console output

- The Singleplayer class takes over the “organization” of the Singleplayer Spies in combination with the AI.
Singleplayer interacts with the classes: Game, Opponent, Player, Board, UserInput and OutputPrinter.

Game: Called by Game
Opponent: Query and manage player variables
Player: Query and manage player variables
Board: Control of the playing field
UserInput: Query the input via the UserInput
class OutputPrinter: Delegation of console output

- The Opponent class stores the information of the player and the AI, and also contains the implementation of the minimax algorithm.
Opponent Does not interact with any other class. is simply called.

Testingkonzept

Testingkonzept

Note: In this code println together with \n is used.

This is a copy of my group project work, which was carried out at the Zurich University of Applied Sciences (ZHAW)

About

A simple command-line based Tic-Tac-Toe game with single and multiplayer mode

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages