Manual_dev

Game loop

Jul 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. void Game::GameLoop()
  2. {
  3.  
  4. //Game.turn non sdl2 redendering version use events to not delay rendering
  5.   while((Game_Over == false)&&(quit == false))
  6.   {
  7.     GetGameGrid()->DisplayGrid();
  8.     //turn 1 Player* pos1
  9.     if (total_turns % 2 == 0)
  10.      {
  11.     int p1_turn = PlayerTurn(player_pos_1);
  12.  
  13.        if(p1_turn == 0) break;
  14.      }
  15.         //turn 2 Player* pos or AI - ai inherits player class
  16.     else
  17.      {
  18.       int p2_turn = PlayerTurn(player_pos_2);
  19.  
  20.        if(p2_turn == 0) break;
  21.      }
  22.    //check for win if total_turns > 4
  23.    //total_turns++; add to true case of if square available case
  24.     if(total_turns > 4)
  25.      {
  26.        //scan through list of win cases for match. trigger Game_Over if match is found
  27.        // if player 2 turn is next
  28.        //check numbr matches other playrs turn messup earlier
  29.       if(total_turns % 2 == 1)
  30.         {
  31.            // bool check if player1 won
  32.         if(PlayerWin(player_pos_1))
  33.            {
  34.        std::cout << "Player 1 Wins!" << std::endl;
  35.             Game_Over = true;
  36.           }
  37.         }
  38.       else if(total_turns % 2 == 0)
  39.         {
  40.           // bool check if player2 won
  41.        if(PlayerWin(player_pos_2))
  42.            {
  43.             std::cout << "Player 2 Wins!!" << std::endl;
  44.             Game_Over = true;
  45.           }
  46.         }                
  47.      }  
  48.     if((total_turns > 8)&&(Game_Over == false)){
  49.       //Draw case
  50.  
  51.       Game_Over = true;
  52.      std::cout << "Draw!" << std::endl;
  53.      }
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment