Advertisement
ulfben

Ways of writing our new Main.cpp

Sep 13th, 2016
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. /*
  2.     Two examples of how your Main.cpp could look for assignment 2.
  3.     This is all you need in the "main" file - our entry point:
  4. */
  5. //Main.cpp, example 1
  6. #include "Pong.h"
  7. int main(int argc, char* argv[]) { 
  8.     try {  
  9.         Pong game; //init sdl, holds and inits all game objects
  10.         game.run(); //Pong::run implements entire game loop, returns when player quit  
  11.     } //game, and all things in it (incl. sdl), destroyed via dtor
  12.     catch (const std::runtime_error& e) {
  13.         std::cerr << e.what() << std::endl;
  14.         return 1;
  15.     }
  16.     catch(...){
  17.         std::cerr << "terribad error" << std::endl;
  18.         return 1;
  19.     }  
  20.     return 0
  21. }
  22.  
  23. /*or perhaps, if it makes your Pong-class cleaner: */
  24.  
  25. //Main.cpp, example2
  26. #include "Pong.h"
  27. int main(int argc, char* argv[]) {
  28.     try {
  29.         Pong game; //init sdl, init game objects, in ctor
  30.         while (!game.doQuit()) { //controls the game-loop
  31.             game.update(); //Pong::update implements our game-loop *body*
  32.         }
  33.     } //quit sdl and destroy everything game owns, via dtor
  34.     catch (const std::runtime_error& e) {
  35.         std::cerr << e.what() << std::endl;
  36.         return 1;
  37.     }
  38.     catch(...){
  39.         std::cerr << "terribad error" << std::endl;
  40.         return 1;
  41.     }  
  42.     return 0
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement