|
-
Dec 27th, 2004, 08:03 AM
#1
Frenzied Member
Re: Help Java Tic tac toe
 Originally Posted by System_Error
I can give you an example of a tic tac game if you like. Let me know and I will post the code.
Don't, that way he won't learn anything.
What he should do, however, is:
Make a 2D array storing each field of the game bord. Everytime a brick is placed, set the value of the field the player set the brick to a value depending on if it's player1, or player2(or if a brick was removed). You could use 0, for nothing, 1 for player1, and 2 for player2 - I'd advise using constants for theese values, making them easier to use/remember. When you got this down, you should make a loop. (Almost)Every computer game has a main loop, ensuring that it runs over and over. Inside your loop, you need to dermine what the player wants to do next - if you're using a console, you need to have an inputreader, to get commands from the user, and interpret this; if the user types "Exit" the game should break out of the loop, if the user types "set a,1" a brick should be placed at that location.
I hope this got you on the way... It's fairly simple when you think about it...
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Dec 27th, 2004, 09:06 AM
#2
Frenzied Member
Re: Help Java Tic tac toe
 Originally Posted by vbNeo
Don't, that way he won't learn anything.
What he should do, however, is:
Make a 2D array storing each field of the game bord. Everytime a brick is placed, set the value of the field the player set the brick to a value depending on if it's player1, or player2(or if a brick was removed). You could use 0, for nothing, 1 for player1, and 2 for player2 - I'd advise using constants for theese values, making them easier to use/remember. When you got this down, you should make a loop. (Almost)Every computer game has a main loop, ensuring that it runs over and over. Inside your loop, you need to dermine what the player wants to do next - if you're using a console, you need to have an inputreader, to get commands from the user, and interpret this; if the user types "Exit" the game should break out of the loop, if the user types "set a,1" a brick should be placed at that location.
I hope this got you on the way... It's fairly simple when you think about it...
This is exactly what I did, except I made a GUI. Personally I don't see how he could use the console, but if he can that's great. Anyways, it is easy once you get started. The only thing you would have trouble with is the search algorithms. I know I had to look them up, and if you don't, your very good. But that's the only hard part, and the only part that really requires any thinking.
-
Dec 27th, 2004, 09:41 AM
#3
Frenzied Member
Re: Help Java Tic tac toe
 Originally Posted by System_Error
This is exactly what I did, except I made a GUI. Personally I don't see how he could use the console, but if he can that's great. Anyways, it is easy once you get started. The only thing you would have trouble with is the search algorithms. I know I had to look them up, and if you don't, your very good. But that's the only hard part, and the only part that really requires any thinking.
Search algorithms ? You want to use RegEx for a Tic Tac Toe game ?
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Dec 27th, 2004, 11:51 AM
#4
Frenzied Member
Re: Help Java Tic tac toe
I don't think they had regex when I made mine, but they might have. Here was the algo's that I used:
Code:
private boolean hasWon(int x, int y) {
boolean won;
won = true;
for (int col=0; col<3; col++) {
if (!btn[x][col].getText().equals(player)) {
won = false;
}
}
if (!won) {
won = true;
for (int row=0; row<3; row++) {
if (!btn[row][y].getText().equals(player)) {
won = false;
}
}
}
if (!won) {
won = true;
for (int num=0; num<3; num++) {
if (!btn[num][num].getText().equals(player)) {
won = false;
}
}
}
if (!won) {
won = true;
for (int num=0; num<3; num++) {
if (!btn[2-num][num].getText().equals(player)) {
won = false;
}
}
}
return won;
}
Remember, there is not just one way to solve a problem. I am sure there a ton of different ways to make a tic tac toe game without using regex
-
Dec 27th, 2004, 11:57 AM
#5
Frenzied Member
Re: Help Java Tic tac toe
vbNeo, do you mind showing me an example of using RegEx? I'm not to familar with it and would like to see what your talking about..if you don't mind of course..
-
Dec 27th, 2004, 01:01 PM
#6
Frenzied Member
Re: Help Java Tic tac toe
RegEx is to big a subject to show with a simple example... Look it up on Google
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Dec 27th, 2004, 03:44 PM
#7
Frenzied Member
Re: Help Java Tic tac toe
I didn't mean the whole program...All I was asking for is like a small code snippet of how you would search to see if there was three-in-a-row.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|