A tic tac toe game implemented using Object Oriented Programming best practices and a DRY approach in Ruby.
Tic-tac-toe, noughts and crosses, or Xs and Os/“X’y O’sies”, is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a diagonal, horizontal, or vertical row is the winner. Wikipedia
- Ruby
- A computer with ruby installed.
- gem install rubocop
- to check that code is passing all rubocop checks, run the following command after editing
rubocop --color
- git clone this repo to your local machine and navigate (cd ) to the top directory containing the main.rb file by running the following commands.
git clone https://github.com/KabohaJeanMark/tic-tac-toe/
cd tic-tac-toe
- Rspec is used to run the tests checking both negative and positive edge cases for the public methods in the Player and Board classes.
- Change directory into the main project directory and run the rspec command.
cd tic-tac-toe
rspec
git clone this repo to your local machine and navigate (cd ) to the top directory containing the main.rb file by running the following commands.
git clone https://github.com/KabohaJeanMark/tic-tac-toe/
cd tic-tac-toe
bin/main.rb
Welcome runs on terminal to get player names and designate tokens
Choose a valid number from 1 to 9 (asking player 1). For example player 1 selects 1 and it turns into an X. See next image step how 1 is X.
Next player's turn (player 2)
If you select a wrong input such as 11, 12 or a string like "cw1" the following message returns telling you what exactly you did wrong and asking you to submit a number from 1 to 9.
If you select a cell which has already been used to place in X or O, for example, 1, the following message is displayed telling you which cell has already been used and prompting you to choose another one.
WIN
The image below shows an example of a win because there are 3 X's in a diagonal line from the bottom left to top right. As long as there is a line going either vertically, horizontally or diagonally containing 3 same tokens, the game is won and the user with those is the winner.
TIE
The image below is of a game that ended in a tie/ draw because there are no 3 tokens (X's or O's) in a straight line whether diagonal, horizontal or vertical.
GAME OVER
When the game has ended you can either choose to continue by pressing 'y' on their keyboard or opt out by pressing 'x'.
👤 Kaboha Jean Mark
- GitHub: @KabohaJeanMark
- Twitter: @jean_quintus
- LinkedIn: LinkedIn
👤 Francis Obeta
- GitHub: @chasscepts
- Twitter: @ofChass
- LinkedIn: LinkedIn
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
- Hat tip to Microverse and the Odin project.
This project is MIT licensed.