![]() 图1.Asteroid Arena屏幕快照 |
![]() 图2.一个进行中的盒子游戏,得分情况是蓝8/红3 |
| 1 #include <iostream> 2 #include <ClanLib/application.h> 3 #include <ClanLib/core.h> 4 #include <ClanLib/display.h> 5 #include <ClanLib/gl.h> 6 #include <ClanLib/sound.h> 7 #include <ClanLib/vorbis.h> 8 9 const int boardsize = 6, spacing = 50, border = 20; 10 const int numsquares = int(pow(float(boardsize - 1), 2)); 11 12 enum coloursquare { off, blue, red }; 13 struct cursor { 14 int x, y; 15 bool vert; 16 }; 17 18 class Boxes: public CL_ClanApplication { 19 bool ver[boardsize][boardsize - 1]; 20 bool hor[boardsize - 1][boardsize]; 21 coloursquare squares[boardsize - 1][boardsize - 1]; 22 bool redturn; 23 bool fullup; 24 cursor curs; 25 26 void inputHandler(const CL_InputEvent &i); 27 bool findsquares(void); 28 inline int numaroundsquare(int x, int y); 29 void init(); 30 void drawBoard(); 31 void endOfGame(); 32 33 public: 34 virtual int Boxes::main(int, char **); 35 } app; 36 37 using namespace std; 40 41 int Boxes::main(int, char **) 42 { 43 int winsize = spacing * (boardsize - 1) + border * 2; 44 try { 45 Boxes::init(); 46 while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) { 47 Boxes::drawBoard(); 48 if (fullup) break; 49 CL_System::keep_alive(20); 50 } 51 Boxes::endOfGame(); 52 53 CL_SetupVorbis::deinit(); 54 CL_SetupSound::deinit(); 55 CL_SetupGL::deinit(); 56 CL_SetupDisplay::deinit(); 57 CL_SetupCore::deinit(); 58 } 59 catch (CL_Error err) { 60 std::cout << "Exception caught: "<< err.message.c_str() << std::endl; 61 } 62 63 return 0; 64 } |
| 66 void Boxes::init() 67 { 68 CL_SetupCore::init(); 69 CL_SetupDisplay::init(); 70 CL_SetupGL::init(); 71 CL_SetupSound::init(); 72 CL_SetupVorbis::init(); 73 74 CL_DisplayWindow window("Boxes", winsize, winsize); 75 CL_SoundOutput output(44100); //选择44Khz采样 76 77 CL_Surface *cursimg = new CL_Surface("cursor.tga"); 78 cursimg->set_alignment(origin_center); 79 CL_Surface *redpict = new CL_Surface("handtransp.tga"); 80 redpict->set_alignment(origin_center); 81 redpict->set_scale(float(spacing)/float(redpict->get_width()), 82 float(spacing)/float(redpict->get_height())); 83 CL_Surface *bluepict = new CL_Surface("circlehandtransp.tga"); 84 bluepict->set_alignment(origin_center); 85 bluepict->set_scale(float(spacing) / float(bluepict->get_width()), 86 float(spacing) / float(bluepict->get_height())); 87 |
| 89 90 redturn = true; 91 curs.vert = false; 92 fullup = false; 93 curs.x = curs.y = 1; 94 95 srand(CL_System::get_time()); //启动随机数字生成器 96 97 for (int x = 0; x < boardsize - 1; x++) { 98 for (int y = 0; y < boardsize; y++) 99 hor[x][y] = ver[y][x] = false; 100 101 for (int y = 0; y < boardsize - 1; y++) 102 squares[x][y] = off; 103 104 |
关注此文的读者还看过: