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:
- 3:6253a2d374fa
- Parent:
- 2:9ca5e1c221c3
- Child:
- 4:6353f829c56c
--- a/Snek/Snek.cpp Mon Apr 16 10:55:00 2018 +0000 +++ b/Snek/Snek.cpp Sun Apr 29 14:19:38 2018 +0000 @@ -16,11 +16,34 @@ //Inital values for variables _x = x; _y = y; + printf ("floats: %i %i \n", _x, _y); } void Snek::update(Direction d) { - _direction = d; + if (d == N) { + _y -= 1; + _oldDirection = 'N'; + } else if (d == S) { + _y += 1; + _oldDirection = 'S'; + } else if (d == E) { + _x += 1; + _oldDirection = 'E'; + } else if (d == W) { + _x -= 1; + _oldDirection = 'W'; + } else { + if (_oldDirection == 'N') { + _y -= 1; + } else if (_oldDirection == 'S') { + _y += 1; + } else if (_oldDirection == 'E') { + _x += 1; + } else if (_oldDirection == 'W') { + _x -= 1; + } + } } int Snek::getX()