main.cc (1007B)
1 #include <cstring> 2 3 #include "Engine.hpp" 4 5 /* Program name */ 6 static char *argv0; 7 8 static void 9 die(const std::string& str) 10 { 11 std::cerr << argv0 << ": " << str << std::endl; 12 exit(1); 13 } 14 15 static void 16 usage() 17 { 18 std::cerr << "usage: " << argv0 << " <map_file> <score_file>" << std::endl; 19 exit(1); 20 } 21 22 int 23 main(int argc, char *argv[]) 24 { 25 Engine *eng; 26 char *mapfile, *scorefile; 27 28 argv0 = *argv++; 29 if (argc < 3) 30 usage(); 31 mapfile = *argv++; 32 scorefile = *argv; 33 34 if (!strcmp(mapfile, scorefile)) 35 die("input files cannot be the same"); 36 /* 37 * We're linking with `lncursesw` so we need to have UTF-8 enabled, 38 * otherwise colors and certain characters might not show up properly 39 * in some terminals. 40 */ 41 if (!setlocale(LC_ALL, "")) 42 die("setlocale"); 43 44 try { 45 eng = new Engine(mapfile, scorefile); 46 } catch (std::string e) { 47 die(e); 48 } 49 while (eng->is_running()) { 50 eng->redraw(); 51 eng->kbd_input(); 52 eng->enemies_move(); 53 eng->collisions(); 54 eng->upd_score(); 55 } 56 delete eng; 57 58 return 0; 59 }