Jump to content
• Advertisement

Public Group

# Acid Burnz TicTacToe [AND OTHER C# QUESTIONS]

This topic is 4235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Decided to start up on this again but the thread was retired; so here it is: ====================ORIGINAL POST FROM HERE: Click Me!====================== Hey dudes and dudettes, as some of you know, I'm trying to learn c# with vs2005 express edition. My first self driven learning project is making a basic tic-tac-toe game and then improve it from there. Here is the interface i've chosen to work with: The user is to click on the button and depending on the turn, it will change to an X or an O on letting go of the button. First question: is this possible? If so, how would i do this? The "status" box will display whose turn it is, and maybe an upto date score count for both sides in the future. =========================================================================== [Edited by - acidwillburnyou on December 16, 2006 2:45:18 PM]

#### Share this post

##### Share on other sites
Advertisement
Generally speaking since I don't know C# (only C/C++) you can use a flag to indicate who's turn it is. Then when the user clicks in a valid square to place an X or O you flip the flag again. This process goes back and forth until the game ends. Just remember that you're only flipping the flag if the user makes a valid move (ie: clicks in an empty square).

Tic-tac-toe is actually a very interesting game. After you get it working with 2 players you may want to look into making an AI to play against. It's not too hard, you just need to look into GameTrees and the Minimax algorithm. The entire solution is a bunch of recursive calls.

#### Share this post

##### Share on other sites
Problem:

byte PlayerAge;

Console.Write("Age (years): ");
PlayerAge = Console.Read();

Error:

Error 1 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?) C:\Documents and Settings\Acid Burnz\Desktop\Programs\Mechnet Text RPG\Mechnet Text RPG\Program.cs 22 25 Mechnet Text RPG

Need:
..to know how I can have the user input their age as a number and not have to cast it from a string to an int. Or is that the only way?

Thanks, Acid

#### Share this post

##### Share on other sites
Console.Read() is not what you're looking for. It blocks, reading input one character a time until a newline. It returns the character code (hence the int) of the next character in the STDIN stream.

I suspect you're looking for something more like:

int PlayerAge;try    PlayerAge = Int.Parse(Console.ReadLine());catch(FormatException)    /* User entered something other than the just the string representation of     * an integer */catch(OverflowException)    // User entered a number beyond the bounds of an int

Obviously the two catch statements are being over-cautious to an extent. You can do without them if you wish.

#### Share this post

##### Share on other sites
Since there's only two players, just use a variable like bool firstPlayerTurn or something and switch it accordingly each turn (Set it to true when it's the first player's turn, and false when it isn't), based on that set the button's .Text property to an "X" or an "O". I suggest using Labels and stuff, it'd look neater, and you'd do it in the same way, just add a click event (I think you can just double click on the label to do this), but it's up to you. Also, take a look at the .Net forum section on these boards, more specialized .Net programmers go there. Of course this place is also appropriate because it's for beginners, I'm just saying, if you'd like to ask/talk with other .Net developers, go there :)

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5
• Advertisement

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631768
• Total Posts
3002240
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!