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.
Snek/Snek.cpp
- Committer:
- Andrew_M
- Date:
- 2018-04-29
- Revision:
- 4:6353f829c56c
- Parent:
- 3:6253a2d374fa
- Child:
- 5:a3a9e0417e04
File content as of revision 4:6353f829c56c:
#include "Snek.h" // nothing doing in the constructor and destructor Snek::Snek() { } Snek::~Snek() { } void Snek::init(int x, int y) { //Inital values for variables printf ("floats: %i %i \n", _x, _y); _length = 3; for (int i = 0; i < _length; i++) { _x[i] = x; _y[i] = y; } } void Snek::update(Direction d) { if (d == N) { _y[0] -= 1; _oldDirection = 'N'; } else if (d == S) { _y[0] += 1; _oldDirection = 'S'; } else if (d == E) { _x[0] += 1; _oldDirection = 'E'; } else if (d == W) { _x[0] -= 1; _oldDirection = 'W'; } else { if (_oldDirection == 'N') { _y[0] -= 1; } else if (_oldDirection == 'S') { _y[0] += 1; } else if (_oldDirection == 'E') { _x[0] += 1; } else if (_oldDirection == 'W') { _x[0] -= 1; } } for (int i = _length; i >= 1; i--) { _x[i] = _x[i-1]; _y[i] = _y[i-1]; } } int Snek::getX(int ref) { return _x[ref]; } int Snek::getY(int ref) { return _y[ref]; } int Snek::getLength() { return _length; }