
For now, it's just an empty function that returns null, but it won't be this way for long. Let's start with a top-level Game component that will store the state of our tic-tac-toe game. Tic-tac-toe is a very simple game, and because it's so simple, it makes for a good introduction to some of the principles of grid and turn-based games. In fact, I once was asked to code tic-tac-toe in a job interview, so don't scoff at this post. It's also excellent exercise for your brain and trains you to think algorithmically. I'm going to share the simplest one with you here: tic-tac-toe.īefore we get started, I want to say that even though I don't build games for a living (or even really as a hobby), coding up a game from time to time is a great way to learn some new skills and patterns. Turns out, coding is still fun after all! I decided to do the latter on my staycation and code up a bunch of silly games. Other times, it means coding some silly stuff of no real importance. I was feeling a little burnt out and needed to rest and have some fun. The 'board' 2D array holds the iconic number sign shape of the Tic Tac Toe's board, wihle the for loop updates the board (clearing the entire screen to avoid printing multiple boards).A few weeks ago, I took some time off from work.

Std::cout << "Hi, This is my first C++ game!\nPress the corresponding key to mark a field in the board. Update the board (this is part of a function which reads user input and changes 'board' accordingly.) This is the Tic Tac Toe board (this is declared in main()) I've also read that '\r' can be used to print over a line that has already been used, but I don't know how to apply this to my program. The only solution I´ve found is using system("cls"), but this doesn´t seem like an optimal solution since the program offers initial instructions for the user that I find reduntant to reprint every time a player makes a move (I don't want to clear the entire screen).

I´ve been trying to make Tic Tac Toe in C++ and I can´t seem to figure out how to update the board without printing it all over again in a new line (every time a player makes a move a new board is printed below the previous one).
