Advertisement
hak8or

Untitled

Dec 7th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*
  2. Function: _exit(Canvas &canvas, int flag)
  3. Description: Based on the input flag, the game gets ended with a win or loss and
  4.     draws onto canvas the end game messesge. Once drawn, exit() gets called
  5.     which tells the OS to safely shut down this program.
  6.  
  7. Input: Canvas object and an intager flag indicated how to exit (won or lost).
  8. Output: Draws to canvas and ends the program.
  9. Error: None
  10. */
  11. void _exit(Canvas &canvas, int flag)
  12. {
  13.     cout << "\t Thank you for playing! \n \t\t Exiting now\n";
  14.  
  15.  
  16.     // Draw the 4 corners of the game done screen.
  17.     int x = 150;
  18.     int y = 150;
  19.     for (int i = 0; i < 4; i++)
  20.     {
  21.         canvas.DrawFillRect(
  22.                 x, // Top left X position
  23.                 y, // Top left Y position
  24.                 60, // Width in pixels
  25.                 60, // Height in pixels
  26.                 0.80, // Red value (0.0 - 1.0)
  27.                 0.80, // Green value (0.0 - 1.0)
  28.                 0.80  // Blue value (0.0 - 1.0)
  29.                 );
  30.         x += 120;
  31.  
  32.         if (i==1)
  33.         {
  34.             x = 150;
  35.             y = 270;
  36.         }
  37.     }
  38.  
  39.     // Light main square
  40.     canvas.DrawFillRect(
  41.             180, // Top left X position
  42.             180, // Top left Y position
  43.             120, // Width in pixels
  44.             120, // Height in pixels
  45.             0.3, // Red value (0.0 - 1.0)
  46.             0.55, // Green value (0.0 - 1.0)
  47.             0.49  // Blue value (0.0 - 1.0)
  48.             );
  49.  
  50.     // Based on what the input flag was, exit the maze with an appropriate
  51.     // phrase.
  52.     switch (flag)
  53.     {
  54.         case 0:
  55.             canvas.DrawText(200,225,"Exiting Now");
  56.             break;
  57.         case 1:
  58.             canvas.DrawText(200,225,"You Win!");
  59.             break;
  60.         case 2:
  61.             canvas.DrawText(200,225,"You Died!");
  62.             break;
  63.     }
  64.  
  65.     // Forces canvas to redraw itself.
  66.     canvas.Invalidate();
  67.  
  68.     // Wait four seconds so user can actually see the screen and
  69.     // the "End Game" box.
  70.     usleep(4000000);
  71.  
  72.     // Signal the OS to safely shut down this maze program.
  73.     exit(0);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement