[SOLVED] Broken game loop.
Posted: Mon Apr 04, 2011 9:41 pm
This is my ticktacktoe game loop, please criticize if there is anything wrong but its supposed to switch between x and o. X being true and o being false, then alternate but its just giving me random x's or o's not in a pattern like it should
Code: Select all
int main ( int argc, char *args[] )
{
//check for errors
bool quit = false;
if( init() == false ) { return 1;}
if( load_files() == false ) { return 2;}
apply_surface( 0,0,background,screen);
//game loop
while (quit == false)
{
Target myTarget1(2,2,247,119);
Target myTarget2(251,2,247,119);
Target myTarget3(502,2,247,119);
Target myTarget4(2,127,247,119);
Target myTarget5(251,127,247,119);
Target myTarget6(502,127,247,119);
Target myTarget7(2,249,247,119);
Target myTarget8(251,249,247,119);
Target myTarget9(502,249,247,119);
if(SDL_PollEvent(&event))
{
myTarget1.handle_events();
myTarget2.handle_events();
myTarget3.handle_events();
myTarget4.handle_events();
myTarget5.handle_events();
myTarget6.handle_events();
myTarget7.handle_events();
myTarget8.handle_events();
myTarget9.handle_events();
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
if (Turn == true)
{
current_turn = target_X;
Turn = false;
}
else
if (Turn == false)
{
current_turn = target_O;
Turn = true;
}
if (SDL_Flip( screen ) == -1)
{
return 3;
}
}