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.
Diff: Engine/Engine.cpp
- Revision:
- 13:81573be8fac6
- Parent:
- 12:d3eef5ea3f43
- Child:
- 14:a57a40ff9430
--- a/Engine/Engine.cpp Mon May 07 18:06:50 2018 +0000 +++ b/Engine/Engine.cpp Mon May 07 19:41:09 2018 +0000 @@ -26,11 +26,9 @@ { if (_lvl == 1) { lvlOne(); - } - else if (_lvl == 2) { + } else if (_lvl == 2) { lvlTwo(); - } - else if (_lvl == 3) { + } else if (_lvl == 3) { lvlThree(); } } @@ -171,24 +169,42 @@ _grid[_noodles.getY()][_noodles.getY()] = 2; - if (_grid[_solid.getX(0)][_solid.getY(0)] == 2) { //checks if the head has reached food - if (_solid.getLength()<484) { //checks if the snake can grow any more - - _solid.grow(); //makes snake longer + if (checkFood()) { //checks if the head has reached food + + growSnake(pad); - bool empty = false; //makes a varible for finding an empty square - while (!empty) { //loops until empty square found - _noodles.random(); //randomise position of noodles - if ( _grid[_noodles.getY()][_noodles.getY()] == 0) { - empty = true; //stops looping when free space is found - // no need to set the grid as it will put the noodles in the new location the next time 'update' is called - } + bool empty = false; //makes a varible for finding an empty square + while (!empty) { //loops until empty square found + _noodles.random(); //randomise position of noodles + if ( _grid[_noodles.getY()][_noodles.getY()] == 0) { + empty = true; //stops looping when free space is found + // no need to set the grid as it will put the noodles in the new location the next time 'update' is called } + } } } -int Engine::getScore() +bool Engine::checkFood() +{ + if (_grid[_solid.getX(0)][_solid.getY(0)] == 2) { + return true; + } else { + return false; + } +} + +void Engine::growSnake(Gamepad &pad) +{ + pad.tone(750.0,0.1); + if (_solid.getLength()<484) { //checks if the snake can grow any more + + _solid.grow(); //makes snake longer + + } +} + +float Engine::getScore() { return _score; }