Skip to content

A tic tac toe game implemented using OOP best practices and a DRY approach in Ruby. Tested using Rspec.

License

Notifications You must be signed in to change notification settings

KabohaJeanMark/tic-tac-toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tic-tac-toe

A tic tac toe game implemented using Object Oriented Programming best practices and a DRY approach in Ruby.

About

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

Built With

  • Ruby

Prerequisites

  • A computer with ruby installed.

Install

  • gem install rubocop
  • to check that code is passing all rubocop checks, run the following command after editing
rubocop --color

INSTRUCTIONS TO RUN THE PROJECT LOCALLY

  • 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

Run tests with Rspec

  • 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

GAMEPLAY INSTRUCTIONS

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.

set up

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

welcome

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.

valid

Next player's turn (player 2)

valid

What happens if an invalid number is chosen?

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.

invalid

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.

invalid

GAME CONCLUSION

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.

invalid

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.

invalid

GAME OVER

invalid

When the game has ended you can either choose to continue by pressing 'y' on their keyboard or opt out by pressing 'x'.

Authors

👤 Kaboha Jean Mark

👤 Francis Obeta

🤝 Contributing

Contributions, issues, and feature requests are welcome!

Feel free to check the issues page.

Show your support

Give a ⭐️ if you like this project!

Acknowledgments

  • Hat tip to Microverse and the Odin project.

📝 License

This project is MIT licensed.

About

A tic tac toe game implemented using OOP best practices and a DRY approach in Ruby. Tested using Rspec.

Resources

License

Stars

Watchers

Forks

Languages