1 #include <SDL.h> 2 #include "cube.h" 3 #include "soundDev.h" 4 #include "controller.h" 5 #include "view.h" 6 #include "mazeView.h" 7 #include "maze.h" 8 #include "mazeController.h" MazeController(SDL_Surface * _screen,SoundDev * _sound,Cube * _cube,unsigned int _dims,unsigned int _skillLevel,bool _wrap)9 NKlein_54321::MazeController::MazeController( 10 SDL_Surface* _screen, 11 SoundDev* _sound, 12 Cube* _cube, 13 unsigned int _dims, 14 unsigned int _skillLevel, 15 bool _wrap 16 ) : Controller( _cube, _dims, _skillLevel, _wrap ), 17 view( _screen, _sound, _cube, _dims, _skillLevel, _wrap ), 18 model( 0 ) 19 { 20 this->view.backgroundMusic(); 21 this->reset(); 22 } ~MazeController(void)23 NKlein_54321::MazeController::~MazeController( void ) 24 { 25 this->view.backgroundMusic( true ); 26 delete this->model; 27 } 28 void reset(void)29 NKlein_54321::MazeController::reset( void ) 30 { 31 delete this->model; 32 this->model = new Maze( 33 this->cube, 34 this->dims, 35 this->skillLevel, 36 this->wrap, 37 &this->view 38 ); 39 } 40 void setDimension(unsigned int _dims)41 NKlein_54321::MazeController::setDimension( 42 unsigned int _dims 43 ) 44 { 45 if ( _dims != this->dims ) { 46 this->dims = _dims; 47 this->reset(); 48 } 49 } 50 void setSkillLevel(unsigned int _skillLevel)51 NKlein_54321::MazeController::setSkillLevel( 52 unsigned int _skillLevel 53 ) 54 { 55 if ( _skillLevel != this->skillLevel ) { 56 this->skillLevel = _skillLevel; 57 this->reset(); 58 } 59 } 60 void setWrap(bool _wrap)61 NKlein_54321::MazeController::setWrap( 62 bool _wrap 63 ) 64 { 65 if ( _wrap != this->wrap ) { 66 this->wrap = _wrap; 67 this->reset(); 68 } 69 } 70 void newGame(void)71 NKlein_54321::MazeController::newGame( void ) 72 { 73 this->reset(); 74 } 75 void handleMouseClick(bool isMouseUp,unsigned int xx,unsigned int yy,unsigned int buttonNumber)76 NKlein_54321::MazeController::handleMouseClick( 77 bool isMouseUp, 78 unsigned int xx, 79 unsigned int yy, 80 unsigned int buttonNumber 81 ) 82 { 83 unsigned int index; 84 bool hit; 85 86 hit = this->view.handleMouseClick( 87 this, isMouseUp, xx, yy, buttonNumber 88 ); 89 90 if ( !hit ) { 91 hit = NKlein_54321::View::screenToCell( 92 xx, yy, this->dims, &index 93 ); 94 95 if ( hit && ! isMouseUp ) { 96 this->model->move( index ); 97 } 98 } 99 } 100