Game Modes - Trup10ka/TicTacToe GitHub Wiki
Game Mode interface
Checking whether you can place a symbol, checking whether the game is over, who won, etc. is done by the game mode interface.
When creating a new game session, each session has to have an instance of GameMode object.
Each game mode has to implement the following methods:
canPlaceSymbol- checks whether the symbol can be placed at the given coordinates, and it is done in a very simple matter. The method is provided with a symbol ID number, which is enough to check whether the symbol can be placed.checkWinCondition- checks whether the game is over, and if it is, who won. Takes the playground as method argument.getName- returns the name of the game mode.
The game mode interface is located in the tictactoe directory, in the gamemode subdirectory.
Game Modes
There are 4 game modes:
- Classic
- War
- Jester
- Eternity
Rules of the game modes are described in the README.md of this project.
How GameMode checks the placement
In tictactoe directory, in data subdirectory, there is a Symbol.ts file.
Symbol is an enum of 4 values:
- EMPTY
- X
- Y
- J (jester)
- DAMAGED (this symbol can be placed during War mode, when the symbol is overridden many times; see README.md)
Checking whether the symbol can be placed varies from game modes.
Non - game mode specific checks
There are also some checks that are not game mode specific, which session does by itself.
- Checking whether it is the player's turn
- Checking whether the game session started or not
Session keeps track of the current player, and also the game state, so before the GameMode check is made, session checks these two things and then lets the GameMode check the position.