G'Day... so I am about a week into trying to learn C# and have been enjoying it so far. I am learning from a book called "The C# Players Guide" and in it around Chapter 20 is what the author calls a "mid term project". To make my first actual application. A TicTacToe game. This is obviously something very simple but I felt it was a good excuse to try out things and see how it all went.
Tic-Tac-Toe. Create a Tic-Tac-Toe game that meets the requirements listed in this section. You should spend a minimum of 20 minutes on this problem (no matter how stuck you get). This is a much bigger problem than any other Try It Out! so far, so plan on it taking more time. If you find yourself stuck beyond recovery, read ahead and see if part or all of my solution can help you get unstuck enough to continue on.
- The game is console-based. (No requirements for a GUI.)
- Two human players take turns using the same keyboard.
- The players are able to designate which square they want to play in next using the keyboard.
- The game should ensure that only legal moves are made.
- You cannot play in a square that already has something.
- The wrong player cannot take a turn.
- If the player makes an illegal move, the board should remain unchanged.
- The game needs to be able to detect when either player wins, or when a draw (“cat”) happens (the board is full).
- Upon detecting that the game is over the outcome is displayed to the user.
- Only a single round of play is required.
Even though it said to only take 20 minuets I took a lot longer. I wanted to try out things with my short term goals in mind. One of those short term goals is to make a multi-room adventure game as part of my learning process. So I took a lot longer than 20 mins .. in comming up with a FrameBuffer and FramePrinting system that felt modular to me.
I had some real issues working out how to control the game flow through the main loop. The original plan was to have a class that checked the game state and sit out a false when the game was over. This lead to issues with choosing new games and stuff. I ended up adding a "state" variable for each game state that was check in the loop. I think this is not the best way and in my next project I want to try and produce these states as a natural output from the game engine itself.
All in all I am pretty happy with it...
Source Code + Binary
I have started a GITHUB account. I was having problems uploading everything to pasteBin... You can see my code here.. and I know it will be messy nad bad.. but I fell I made a good start. You can also use the download link to download the actual binary to run. I compiled this on Windows 10.. so I guess it has to work in a windows environment.
How to Play
This is kinda redundant for something so simple, but I want to get a "format" working for this blog.
- Q / ESC == Quit at any time
- N == New Game (At Results Screen or During the Game Itself)
- 1-9 / Num1 - Num9 == Place a Player Token.
1st Player will be randomly set to X or O.
See ya next time!