title: C++ & SDL TicTacToe - Changing Turns
body: <p>I am having problems with changing turns between players in my game. It seems it goes in any order when I run it. And because of that, the text that shows whose turn it is, is messed up.</p>
  
  <pre><code>            #include &lt;iostream&gt;
              #include "SDLSetup.h"
              using namespace std;
  
              int p = 1;
  
              void Player1()
              {
                  Player = TTF_RenderText_Solid(font, "Player 1", textColor);
                  apply_surface(0, 630, Player, screen);
                  SDL_Flip(screen);
                  p = 2;
              }
  
              void Player2()
              {
                  Player = TTF_RenderText_Solid(font, "Player 2", textColor);
                  apply_surface(0, 630, Player, screen);
                  SDL_Flip(screen);
                  p = 1;
              }
  
              int main(int argc, char* args[])
              {
                  bool quit = false;
  
  if(init() == false)
      return 1;
  
  if(load_files() == false)
      return 1;
  
  apply_surface(0, 0, board, screen);
  
  if(SDL_Flip(screen) == -1)
              return 1;
  turn:
  
  do{
      if(SDL_PollEvent(&amp;event))
      {
          if(event.type == SDL_QUIT)
              quit=true;
      }
  
          if(event.type == SDL_MOUSEBUTTONDOWN)
                  {
                      if(event.button.button == SDL_BUTTON_LEFT)
                      {
                          //Top Left
                          if(event.button.x &lt; 175 &amp;&amp; event.button.y &lt; 175)
                          {
                              if(p == 1)
                              {
                                  apply_surface(45, 40, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(45, 40, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Top Middle
                          else if(event.button.x &gt; 175 &amp;&amp; event.button.x &lt; 375 &amp;&amp; event.button.y &lt; 175)
                          {
                              if(p == 1)
                              {
                                  apply_surface(250, 40, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(250, 40, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Top Right
                          else if(event.button.x &gt; 375 &amp;&amp; event.button.x &lt; 600 &amp;&amp; event.button.y &lt; 175)
                          {
                              if(p == 1)
                              {
                                  apply_surface(450, 40, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(450, 40, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Middle Left
                          else if(event.button.x &lt; 175 &amp;&amp; event.button.y &gt; 175 &amp;&amp; event.button.y &lt; 380)
                          {
                              if(p == 1)
                              {
                                  apply_surface(45, 240, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(45, 235, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Center
                          else if(event.button.x &gt; 175 &amp;&amp; event.button.x &lt; 375 &amp;&amp; event.button.y &gt; 175 &amp;&amp; event.button.y &lt; 380)
                          {
                              if(p == 1)
                              {
                                  apply_surface(250, 235, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(250, 235, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Middle Right
                          else if(event.button.x &gt; 375 &amp;&amp; event.button.x &lt; 600 &amp;&amp; event.button.y &gt;175 &amp;&amp; event.button.y &lt; 380)
                          {
                              if(p == 1)
                              {
                                  apply_surface(450, 235, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(450, 235, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Bottom Left
                          else if(event.button.x &lt; 175 &amp;&amp; event.button.y &gt; 380 &amp;&amp; event.button.y &lt; 600)
                          {
                              if(p == 1)
                              {
                                  apply_surface(45, 450, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(45, 450, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Bottom Middle
                          else if(event.button.x &gt; 175 &amp;&amp; event.button.x &lt; 375 &amp;&amp; event.button.y &gt; 380 &amp;&amp; event.button.y &lt; 600)
                          {
                              if(p == 1)
                              {
                                  apply_surface(250, 450, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(250, 450, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
                          //Bottom Right
                          else if(event.button.x &gt; 375 &amp;&amp; event.button.x &lt; 600 &amp;&amp; event.button.y &gt; 380 &amp;&amp; event.button.y &lt; 600)
                          {
                              if(p == 1)
                              {
                                  apply_surface(450, 450, X, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                              else if(p == 2)
                              {
                                  apply_surface(450, 450, O, screen);
                                  SDL_Flip(screen);
                                  goto turn;
                              }
                          }
  
                      }
                  }
  
          if(p == 1)
              Player1();
          else
              Player2();
  
  } while(quit == false);
  
  
  
  
  clean_up();
  
  return 0;
              }
  </code></pre>