Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 17:2a909f7da973, committed 2018-05-08
- Comitter:
- Andrew_M
- Date:
- Tue May 08 14:52:29 2018 +0000
- Parent:
- 16:4d329ce7b156
- Commit message:
- More comments and debugging tools added
Changed in this revision
--- a/Engine/Engine.cpp Tue May 08 14:41:56 2018 +0000 +++ b/Engine/Engine.cpp Tue May 08 14:52:29 2018 +0000 @@ -18,6 +18,8 @@ _solid.init(10,15); _noodles.init(10,10); _gameOver = false; + + printf("Engine initialised\n"); } void Engine::setLvl(int _levelToSet) { @@ -33,6 +35,7 @@ } else if (_lvl == 3) { lvlThree(); } + printf("Level Loaded\n"); } void Engine::lvlOne() @@ -141,6 +144,7 @@ void Engine::gameOverScreen(N5110 &lcd) { + printf("GameOver\n"); for (int i = 0; i < 22; i++) { //covers every square of the grid for (int j = 0; j < 22; j++) { lcd.drawRect((2 * i) + 2,(2 * j) + 2,2,2,FILL_BLACK); //draws a 2x2 square ontop of whatever is drawn in the cooridnates of the grid at the current time @@ -237,7 +241,7 @@ void Engine::gameTest() { - + printf("Testing...\n"); if (!snakeTest()) { printf("Some game tests failed!\n"); } else if (!foodTest()) { @@ -295,8 +299,8 @@ _noodles.init(7,3); _grid[_noodles.getX()][_noodles.getY()] = 2; //sets the grid value so that the randomise loop will work correctly - - + + bool empty = false; //makes a varible for finding an empty square @@ -310,8 +314,8 @@ // no need to set the grid as it will put the noodles in the new location the next time 'update' is called } - } - + } + if (_noodles.getX() ==7 && _noodles.getY() == 3) { //checks to see if randomised correctly _testState = false; //fail
--- a/Food/Food.cpp Tue May 08 14:41:56 2018 +0000 +++ b/Food/Food.cpp Tue May 08 14:52:29 2018 +0000 @@ -17,6 +17,8 @@ { _x = x; _y = y; + + printf("Food initialised\n"); } int Food::getX()
--- a/Menu/Menu.cpp Tue May 08 14:41:56 2018 +0000 +++ b/Menu/Menu.cpp Tue May 08 14:52:29 2018 +0000 @@ -14,7 +14,7 @@ void Menu::init() { // initialises the default values - + _start = false; _mainSelection = 1; @@ -30,6 +30,8 @@ _buttonPressed = false; _menuScreen = "main"; + + printf("Menu initialised\n"); } void Menu::update() @@ -46,11 +48,11 @@ void Menu::moveArrow() { //each part of the menu has different selection tracker, this means that it will remember what was selected before moving between menu screens - + if (_menuScreen == "main" ) { if (_d == N && _mainSelection > 1) { //checks the menu arrow location and direction wanting to be moved _mainSelection -= 1; //if there is still a postion to be moved to in that direction, the currently selected menu item changes - //all the menu navigation functions in the same way + //all the menu navigation functions in the same way } else if (_d == S && _mainSelection < 3) { _mainSelection += 1; } @@ -74,10 +76,13 @@ if (_menuScreen == "main" ) { //checks the menu screen if (_mainSelection == 1) { //checks what the current selection is _start = true; //applies the needed change depending on the selection + printf("Game Start\n"); } else if (_mainSelection == 2) { _menuScreen = "lvl"; + printf("Menu Screen Changed\n"); } else if (_mainSelection == 3) { _menuScreen = "dif"; + printf("Menu Screen Changed\n"); } } else { //an else is used as the other two menu screen MUST return to the main menu once a selection is made if (_menuScreen == "dif" ) { @@ -101,7 +106,7 @@ } _menuScreen = "main"; //returns to the main menu - + printf("Menu Screen Changed\n"); } } @@ -113,8 +118,12 @@ //checks if any button on the top of the gamepad has been pressed, there is no need to limit the user to one type of button if ( pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::B_PRESSED) || pad.check_event(Gamepad::X_PRESSED) || pad.check_event(Gamepad::Y_PRESSED) ||pad.check_event(Gamepad::BACK_PRESSED)) { _buttonPressed = true; + + printf("Button Pressed\n"); + pad.tone(750.0,0.1); //plays a noise to show the user that the item has been selected - wait(0.1); //waits to reduce 'ghosting' of inputs + wait(0.1); //waits to reduce 'ghosting' of inputs + } _d = pad.get_direction(); //gets the current direction of the joystick for later use @@ -124,7 +133,7 @@ { lcd.drawRect(0,0,84,48,FILL_TRANSPARENT); //draws an outline if (_menuScreen == "main" ) { //checks the currently selected screen - + lcd.printString(" Start",2,1); //draws the related elements lcd.printString(" Level Select",2,2); lcd.printString(" Difficulty",2,3); @@ -178,3 +187,5 @@ { return _level; } + +
--- a/Snek/Snek.cpp Tue May 08 14:41:56 2018 +0000 +++ b/Snek/Snek.cpp Tue May 08 14:52:29 2018 +0000 @@ -15,7 +15,7 @@ { memset(_x, 0, sizeof(_x)); //clears the x coordinate array memset(_y, 0, sizeof(_y)); //clears the y coordinate array - + //Inital values for variables _length = 3; @@ -23,8 +23,10 @@ for (int i = 0; i < _length; i++) { //sets the starting values for the snake coordinates _x[i] = x; //all have the same X coordinate - _y[i] = y + i; //the Y coordinate is incremmented for each tail segment + _y[i] = y + i; //the Y coordinate is incremmented for each tail segment } + + printf("Snake Initialised\n"); } void Snek::update(Direction d) @@ -37,15 +39,19 @@ if (d == N && _oldDirection != 'S') { //checks the new direction so the snake cannot go back on itself _y[0] -= 1; //changes a coordinate of the snake's head _oldDirection = 'N'; //updates the _oldDirection so the snake will travel in the new direction with no play input + printf("Snake has changed North\n"); } else if (d == S && _oldDirection != 'N') { _y[0] += 1; _oldDirection = 'S'; + printf("Snake has changed South\n"); } else if (d == E && _oldDirection != 'W') { _x[0] += 1; _oldDirection = 'E'; + printf("Snake has changed East\n"); } else if (d == W && _oldDirection != 'E') { _x[0] -= 1; _oldDirection = 'W'; + printf("Snake has changed West\n"); } else { //if there is no player input (new direction)... if (_oldDirection == 'N') { //checks the old direction... _y[0] -= 1; //and changes a coordinate of the snake's head depending on the _oldDirection @@ -56,6 +62,7 @@ } else if (_oldDirection == 'W') { _x[0] -= 1; } + printf("Snake hasn't changed direction\n"); } } @@ -77,5 +84,6 @@ void Snek::grow() { _length+=1; //increments the length of the snake + printf("Snake has grown\n"); }