ulfben

Ways of writing our new Main.cpp

Sep 13th, 2016
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×