FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Writing a tic-tac-toe game

 


seanooi
My assignment is to write a source for the game tic-tac-toe.

it goes something like this

Board layout:
1 2 3
4 5 6
7 8 9

X's move?

So when the user keys in a number from 1-9, the number on the board is replaced with an X, then it's O's turn.

I want to ask, how do I replace the numbers key'd in by the player with an X/O?
deathrabbit
I am assuming this is a console program, and in that case, you should set the curor location to the correct coordinates and overwrite the number, or just display the board all over again.
martindecorte
And since it isn't an application that needs to be ran with a big graphical efficiency, i'd consider redisplaying the whole board, since it'll be easier at first sight.
Nyizsa
Code:
Use a 3 by 3 array. Put the values 1 to 9 into it. Display. Set who to 1.
Repeat nine times:
{
  Read user input. Go through the table. If the value in the table matches the user input:
  {
    Set that value to 10*who.
    set who to 1-who.
  }
  Display the table.
}

In short. Now implement!
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.