1     #include <SDL.h>
2     #include "cube.h"
3     #include "soundDev.h"
4     #include "view.h"
5     #include "controller.h"
6     #include "mainmenuView.h"
7     #include "mainmenuController.h"
MainMenuController(SDL_Surface * _screen,Cube * _cube)8         NKlein_54321::MainMenuController::MainMenuController(
9                 SDL_Surface* _screen,
10                 Cube* _cube
11             ) : Controller( _cube ),
12                 view( _screen )
13         {
14             this->view.redraw();
15         }
~MainMenuController(void)16         NKlein_54321::MainMenuController::~MainMenuController( void )
17         {
18         }
19         void
setDimension(unsigned int _dims)20         NKlein_54321::MainMenuController::setDimension(
21                 unsigned int _dims
22             )
23         {
24         }
25         void
setSkillLevel(unsigned int _skillLevel)26         NKlein_54321::MainMenuController::setSkillLevel(
27                 unsigned int _skillLevel
28             )
29         {
30         }
31         void
setWrap(bool _wrap)32         NKlein_54321::MainMenuController::setWrap(
33                 bool _wrap
34             )
35         {
36         }
37         void
newGame(void)38         NKlein_54321::MainMenuController::newGame( void )
39         {
40         }
41         void
handleMouseClick(bool isMouseUp,unsigned int xx,unsigned int yy,unsigned int buttonNumber)42         NKlein_54321::MainMenuController::handleMouseClick(
43                 bool isMouseUp,
44                 unsigned int xx,
45                 unsigned int yy,
46                 unsigned int buttonNumber
47             )
48         {
49             unsigned int index;
50             bool hit;
51 
52             hit = this->view.handleMouseClick(
53                         this, isMouseUp, xx, yy, buttonNumber
54                     );
55 
56             if ( !hit ) {
57                     unsigned int maxGame = NKlein_54321::MainMenuView::MAX_GAME;
58                     unsigned int chosen;
59                     for ( unsigned int ii=0; !hit && ii < maxGame; ++ii ) {
60                         if ( this->view.pointInBox( xx, yy, ii ) ) {
61                             chosen = ii;
62                             hit = true;
63                         }
64                     }
65                     {
66                         extern int __counter;
67                         extern int __wonCount;
68 
69                         if ( !hit && xx < NKlein_54321::View::SIDEBAR_X
70                         && __counter == 76 && __wonCount == 1 ) {
71                             chosen = maxGame;
72                             hit = true;
73                             __wonCount = 2;
74                         }
75                     }
76                 if ( hit ) {
77                         SDL_Event change;
78                         change.type = SDL_USEREVENT;
79                         change.user.code = chosen;
80                         ::SDL_PushEvent( &change );
81                 }
82             }
83         }
84