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: Snek/Snek.cpp
- Revision:
- 17:2a909f7da973
- Parent:
- 15:130900e5c268
--- 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"); }