| View previous topic :: View next topic |
| Author |
Message |
eagles358 Expert Cheater
Reputation: 0
Joined: 10 Apr 2007 Posts: 174
|
Posted: Wed Jul 04, 2007 3:21 pm Post subject: Tic Tac Toe Game (made in C++) |
|
|
Im still pretty new to c++, but i made this tac tac toe game. I thought id post it to see what people think of it and to get some suggestions on ways to improve it. Thanks in advanced for checking it out.
I used Dev-C++ compiler, heres a link for the exe
http://rapidshare.com/files/41093810/eagles358_s_tic_tac_toe.exe
| Code: | #include <iostream>
#include <string.h>
using namespace std;
string board[9] = {"[ ]","[ ]","[ ]","[ ]","[ ]","[ ]","[ ]","[ ]","[ ]"};
void show_board();
void p1_turn();
void p2_turn();
int main() {
int i=0;
cout<< "***Welcome to Eagles358's 2 player Tic-Tac-Toe Game!***\n\n";
string p1;
string p2;
cout<<"Player 1 enter your name: \n";
cin>>p1;
cout<<"Player 2 enter your name: \n";
cin>>p2;
int a;
while (1) {
for(int t=0;t<9;t++)
board[t]="[ ]";
cout<<"Have you played this before? (1 for yes, 2 for no, 0 to exit)";
cin>>a;
if (a==1)
cout<<"Enjoy the game!\n\n";
else if (a==2){
cout<<"\n\nHere are the instructions:\n\n";
cout<<"Player 1 is X's and player 2 is O's.\n";
cout<<"Player 1 goes first.\n";
cout<<"To specify a box to mark, enter its number.\n\n";
cout<<"These are the numbers for each box: \n";
cout<<"[1][2][3]\n[4][5][6]\n[7][8][9]\n\n";
cout<<"Ex: X would be at box 3 \n\n";
cout<<"[ ][ ][X]\n[ ][ ][ ]\n[ ][ ][ ]\n\n";
cout<<"Ex: O would be at box 5 \n\n";
cout<<"[ ][ ][ ]\n[ ][O][ ]\n[ ][ ][ ]\n\n";
cout<<"To win a player must mark 3 boxes that are in a row.\n";
cout<<"Ex: O's would win in this game\n\n";
cout<<"[O][X][X]\n[X][O][X]\n[O][X][O]\n";
cout<<"Those are the instructions. Enjoy the game!\n\n";
}
else
return 0;
while (1) {
p1_turn();
i++;
if ( (board[0]=="[X]")&&(board[0]==board[1])&&(board[2]==board[1]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[1])&&(board[2]==board[1]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]=="[X]")&&(board[0]==board[3])&&(board[3]==board[6]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[3])&&(board[3]==board[6]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[3]=="[X]")&&(board[4]==board[3])&&(board[3]==board[5]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[3]=="[O]")&&(board[4]==board[3])&&(board[3]==board[5]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[6]=="[X]")&&(board[6]==board[7])&&(board[6]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[6]=="[O]")&&(board[6]==board[7])&&(board[6]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[1]=="[X]")&&(board[1]==board[4])&&(board[4]==board[7]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[1]=="[O]")&&(board[1]==board[4])&&(board[4]==board[7]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[2]=="[X]")&&(board[2]==board[5])&&(board[5]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[2]=="[O]")&&(board[2]==board[5])&&(board[5]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]=="[X]")&&(board[0]==board[4])&&(board[4]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[4])&&(board[4]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[2]=="[X]")&&(board[2]==board[4])&&(board[4]==board[6]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[2]=="[O]")&&(board[2]==board[4])&&(board[4]==board[6]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]!="[ ]")&&(board[1]!="[ ]")&&(board[2]!="[ ]")&&(board[3]!="[ ]")&&(board[4]!="[ ]")&&(board[5]!="[ ]")&&(board[6]!="[ ]")&&(board[7]!="[ ]")&&(board[8]!="[ ]")){
cout<<"Its a tie!\n";
cout<<"Eagles358 OWNED "<<p1<<" and "<<p2<<"!";
break;
}
else if (i==9) {
cout<<"Its a tie!\n";
cout<<"Eagles358 OWNED "<<p1<<" and "<<p2<<"!";
break;
}
p2_turn();
i++;
if ( (board[0]=="[X]")&&(board[0]==board[1])&&(board[2]==board[1]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[1])&&(board[2]==board[1]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]=="[X]")&&(board[0]==board[3])&&(board[3]==board[6]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[3])&&(board[3]==board[6]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[3]=="[X]")&&(board[4]==board[3])&&(board[3]==board[5]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[3]=="[O]")&&(board[4]==board[3])&&(board[3]==board[5]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[6]=="[X]")&&(board[6]==board[7])&&(board[6]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[6]=="[O]")&&(board[6]==board[7])&&(board[6]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[1]=="[X]")&&(board[1]==board[4])&&(board[4]==board[7]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[1]=="[O]")&&(board[1]==board[4])&&(board[4]==board[7]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[2]=="[X]")&&(board[2]==board[5])&&(board[5]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[2]=="[O]")&&(board[2]==board[5])&&(board[5]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]=="[X]")&&(board[0]==board[4])&&(board[4]==board[8]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[0]=="[O]")&&(board[0]==board[4])&&(board[4]==board[8]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[2]=="[X]")&&(board[2]==board[4])&&(board[4]==board[6]) ){
show_board();
cout<<p1<<" OWNED "<<p2<<"!";
break;
}
else if ( (board[2]=="[O]")&&(board[2]==board[4])&&(board[4]==board[6]) ){
show_board();
cout<<p2<<" OWNED "<<p1<<"!";
break;
}
else if ( (board[0]!="[ ]")&&(board[1]!="[ ]")&&(board[2]!="[ ]")&&(board[3]!="[ ]")&&(board[4]!="[ ]")&&(board[5]!="[ ]")&&(board[6]!="[ ]")&&(board[7]!="[ ]")&&(board[8]!="[ ]")){
cout<<"Its a tie!\\nn";
cout<<"Eagles358 OWNED "<<p1<<" and "<<p2<<"!";
break;
}
}
cout<<"\n\n***THANKS FOR PLAYING!***\n\n\n";
}
}
void show_board(){
for(int i=0;i<3;i++)
cout<<board[i];
cout<<endl;
for(int i=3;i<6;i++)
cout<<board[i];
cout<<endl;
for(int i=6;i<9;i++)
cout<<board[i];
cout<<endl;
}
void p1_turn() {
int n;
cout<<"Its player 1's turn. Please Enter a box to mark.\n";
cout<<"The board currently looks like this: \n";
show_board();
cin>>n;
if ( (n<1)||(n>9) ){
cout<<"Please enter a valid spot (0-8)\n";
p1_turn();
}
else if(board[n-1]!="[ ]") {
cout<<"Spot taken, try again.\n";
p1_turn();
}
else
board[n-1]="[X]";
}
void p2_turn() {
int n;
cout<<"Its player 2's turn. Please Enter a box to mark.\n";
cout<<"The board currently looks like this: \n";
show_board();
cin>>n;
if ( (n<1)||(n>9) ){
cout<<"Please enter a valid spot (0-8)\n";
p2_turn();
}
if(board[n-1]!="[ ]") {
cout<<"Spot taken, try again.\n";
p2_turn();
}
else
board[n-1]="[O]";
}
|
Last edited by eagles358 on Wed Jul 04, 2007 10:14 pm; edited 11 times in total |
|
| Back to top |
|
 |
Kevin Grandmaster Cheater Supreme
Reputation: 0
Joined: 07 Mar 2007 Posts: 1139 Location: Spiderman-World
|
Posted: Wed Jul 04, 2007 4:03 pm Post subject: |
|
|
lets try it ?
|
|
| Back to top |
|
 |
Simsgy Grandmaster Cheater
Reputation: 0
Joined: 07 May 2007 Posts: 581 Location: My new avatar <3
|
Posted: Wed Jul 04, 2007 5:20 pm Post subject: |
|
|
Can't you attach it?
_________________
|
|
| Back to top |
|
 |
eagles358 Expert Cheater
Reputation: 0
Joined: 10 Apr 2007 Posts: 174
|
Posted: Wed Jul 04, 2007 5:27 pm Post subject: |
|
|
| Simsgy wrote: | | Can't you attach it? |
do you mean the exe?
if so, i added it.
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Jul 04, 2007 6:04 pm Post subject: |
|
|
lool nice one
|
|
| Back to top |
|
 |
eagles358 Expert Cheater
Reputation: 0
Joined: 10 Apr 2007 Posts: 174
|
Posted: Wed Jul 04, 2007 6:10 pm Post subject: |
|
|
thanks
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Jul 04, 2007 7:17 pm Post subject: |
|
|
| Here's a tip: It makes the game less confusing if the boxes start at 1.
|
|
| Back to top |
|
 |
eagles358 Expert Cheater
Reputation: 0
Joined: 10 Apr 2007 Posts: 174
|
Posted: Wed Jul 04, 2007 9:57 pm Post subject: |
|
|
| fixed it so it starts at 1 and goes to 9. was easier than i thought. put a new link.
|
|
| Back to top |
|
 |
Yukitohacker Newbie cheater
Reputation: 0
Joined: 04 Jul 2007 Posts: 10 Location: Argentina
|
Posted: Fri Jul 06, 2007 9:22 am Post subject: |
|
|
| The game is nice
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Fri Jul 06, 2007 9:57 am Post subject: |
|
|
Nice try on stealing credits loser
go pick up a book fag
Token from - Here
Or just google and you'll see many results,im quit sure you didnt made it.
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Fri Jul 06, 2007 10:11 am Post subject: |
|
|
| Kaspersky wrote: | Nice try on stealing credits loser  |
Oh ok let's see what this code thief has to say about code thieving.
| Kaspersky wrote: | | go pick up a book fag |
Sounds like someone's insecure about their sexuality.
| Kaspersky wrote: | Token from - Here
Or just google and you'll see many results,im quit sure you didnt made it. |
Kaspersky, did you even look at the source code on the site you posted? Completely different. Shame on you.
|
|
| Back to top |
|
 |
BoRed Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Apr 2007 Posts: 1176 Location: ╞|ous█
|
Posted: Fri Jul 06, 2007 12:22 pm Post subject: |
|
|
Tic tac toe. Nice. Always been a classic.
_________________
I got my old name back.......=)
Working on making website for stealth trainers (almonst done just having technical troubles)
Stealth forums will be down for 8 days or more starting august 2 saturday. |
|
| Back to top |
|
 |
eagles358 Expert Cheater
Reputation: 0
Joined: 10 Apr 2007 Posts: 174
|
Posted: Fri Jul 06, 2007 3:28 pm Post subject: |
|
|
| Kaspersky wrote: | Nice try on stealing credits loser
go pick up a book fag
Token from - Here
Or just google and you'll see many results,im quit sure you didnt made it. |
Im sure you didnt even look at the source code. Why dont you shut the hell up and dont accuse someone of somthing if you have no clue what you are talking about. I made this 100% by myself.
|
|
| Back to top |
|
 |
Nicholas Newbie cheater
Reputation: 0
Joined: 06 Jun 2006 Posts: 22
|
Posted: Sat Jul 07, 2007 1:46 pm Post subject: Re: Tic Tac Toe Game (made in C++) |
|
|
| eagles358 wrote: | | I used Dev-C++ compiler |
Dev-C++ is an integrated development environment (IDE) that uses the gcc compiler by default.
I don't know why people still choose to use Dev-C++ when it was last updated on February 22, 2005 and there are better IDEs available. Code::Blocks is free and still actively developed. You should try out the nightly builds available on their forum because the 1.0rc2 release on the Downloads page is extremely old (Oct 25, 2005) and the developers say the nightly builds are much more stable and have many more features.
Another option is the free Microsoft Visual C++ Express Edition.
_________________
| pirateninja wrote: | | Unsatisfied with the Cheat Engine's trainer maker, I decided to use the addresses I found using CE to make my own trainer in VB. |
| Dark Byte wrote: | | hehe, nice joke |
|
|
| Back to top |
|
 |
Bomiheko Newbie cheater
Reputation: 0
Joined: 30 Jun 2007 Posts: 21 Location: Wherever
|
Posted: Sat Jul 07, 2007 2:14 pm Post subject: |
|
|
Can someone please scan this?
_________________
By reading what I have just wrote down you have wasted about 5 seconds of your entire life =), |
|
| Back to top |
|
 |
|