What from here?
Posted: Mon Mar 23, 2009 7:57 pm
I just finished my tic-tac-toe game(cpp). (Not when clicked though, I figure easy to add with some sdl events(?))
I was thinking of add a computer to play against I'm definitely making it into arrays instead of the char row1collum1 = '_'; though. Will be easy to choose spots instead of checking two characters with a ton of if's to see where to put it.
After I finish that up any other ideas on small things I can create? I finished this in about 30 minutes.
Also I have a small question on SDL. Is their a way to change camera positioning? Like having two squares with only one fitting on the screen at the time and having the squares move. Or do I have to do it with moving all the sprites around then updating the map?
Meh. 151 lines of very inefficient coding.
I was thinking of add a computer to play against I'm definitely making it into arrays instead of the char row1collum1 = '_'; though. Will be easy to choose spots instead of checking two characters with a ton of if's to see where to put it.
After I finish that up any other ideas on small things I can create? I finished this in about 30 minutes.
Also I have a small question on SDL. Is their a way to change camera positioning? Like having two squares with only one fitting on the screen at the time and having the squares move. Or do I have to do it with moving all the sprites around then updating the map?
Meh. 151 lines of very inefficient coding.
Code: Select all
void ticTacToe(void)
{
system("CLS");
/* Board set up */
char cPlayer = 'X';
char rChoice;
char cChoice;
char r1c1 = '_';
char r1c2 = '_';
char r1c3 = '_';
char r2c1 = '_';
char r2c2 = '_';
char r2c3 = '_';
char r3c1 = '_';
char r3c2 = '_';
char r3c3 = '_';
char Winner = '_';
/* Find player spot */
cout<<123<<endl;
cout<<'1'<<r1c1<<r1c3<<r1c3<<endl<<'2'<<r2c1<<r2c2<<r2c3<<endl<<'3'<<r3c1<<r3c2<<r3c3<<endl;
cout<<"Type the row then the collum player X."<<endl;
for(int i=1;i!=10;i++)
{
cin >> rChoice;
cin >> cChoice;
/* Would of been alot easier with arrays >.< */
if (rChoice=='1')
{
if(cChoice=='1')
{
if (r1c1 == '_')
{
r1c1 = cPlayer;
}
}
if(cChoice=='2')
{
if (r1c2 == '_')
{
r1c2 = cPlayer;
}
}
if(cChoice=='3')
{
if (r1c3 == '_')
{
r1c3 = cPlayer;
}
}
}
if (rChoice=='2')
{
cout << rChoice<<endl;
if(cChoice=='1')
{
if (r2c1 == '_')
{
r2c1 = cPlayer;
}
}
if(cChoice=='2')
{
if (r2c2 == '_')
{
r2c2 = cPlayer;
}
}
if(cChoice=='3')
{
if (r2c3 == '_')
{
r2c3 = cPlayer;
}
}
}
if (rChoice=='3')
{
if(cChoice=='1')
{
if (r3c1 == '_')
{
r3c1 = cPlayer;
}
}
if(cChoice=='2')
{
if (r3c2 == '_')
{
r3c2 = cPlayer;
}
}
if(cChoice=='3')
{
if (r3c3 == '_')
{
r3c3 = cPlayer;
}
}
}
/* Peform a win check. Again easier with rows >.< */
if(r1c1 == r1c2 && r1c2 == r1c3)
{
cout <<"Player:"<<r1c1<<" wins!c:1" <<endl;
Winner = r1c1;
}
if(r2c1 == r2c2 && r2c2 == r2c3 && r2c1!='_')
{
cout <<"Player:"<<r2c1<<" wins!c:2" <<endl;
Winner = r2c1;
}
if(r3c1 == r3c2 && r3c2 == r3c3 && r3c1!='_')
{
cout <<"Player:"<<r1c1<<" wins!c:3" <<endl;
Winner = r3c1;
}
if(r1c1 == r2c2 && r2c2 == r3c3 && r1c1!='_')
{
cout <<"Player:"<<r1c1<<" wins!c:4" <<endl;
Winner = r1c1;
}
if(r1c3 == r2c2 && r2c2 == r3c1 && r1c3!='_')
{
cout <<"Player:"<<r1c1<<" wins!c:5" <<endl;
Winner = r1c3;
}
if(r1c1 == r2c1 && r2c1 == r3c1 && r1c1!='_')
{
cout <<"Player:"<<r1c1<<" wins!c:6" <<endl;
Winner = r1c1;
}
//Swapping players
if (cPlayer == 'X')
{
cPlayer = 'O';
}
else
{
cPlayer = 'X';
}
cout<<r1c1<<r1c2<<r1c3<<endl<<r2c1<<r2c2<<r2c3<<endl<<r3c1<<r3c2<<r3c3<<endl;
if (Winner != '_')
{break;}
else{
cout <<Winner<<endl;
cout<<"Type the row then the collum player "<<cPlayer<<'.'<<endl;
}
}
//Ain't I classy. Any way to get rid of this?
cout << "Performing a input dump. Please type something and press enter. No spaces or it will get hung up.";
string StringDump;
cin >> StringDump;
}