Snake game for a 5x5 LED matrix
Diff: snake.h
- Revision:
- 1:5fcb94bb03db
- Parent:
- 0:dc906408980e
- Child:
- 2:9c075a0a6d4e
--- a/snake.h Wed Oct 09 16:23:20 2013 +0000
+++ b/snake.h Thu Oct 17 04:32:58 2013 +0000
@@ -1,7 +1,17 @@
#include "mbed.h"
#include "bodyPiece.h"
#include <list>
+#include "ledCube.h"
+#ifndef SNAKE_H
+#define SNAKE_H
+
+// Macros
+#define START_DIRECTION Up
+#define START_SPEED 10
+// Zero indexed number of columns and rows
+#define NUM_COLS 4
+#define NUM_ROWS 4
typedef enum {
Up,Down,Left,Right
@@ -10,15 +20,24 @@
class snake
{
public:
+
+ // constructor
snake(char startRow, char startCol);
- void move(char newHeadRow, char newHeadCol);
- int movementSpeed;
- Direction movementDirection;
- void addPiece();
+
+ // public variables
+ int movementSpeed; // Speed at which the snake is moving
+ Direction movementDirection; // Direction in which the snake is moving
+ int bodySize; // Size of the snake's body
+ std::list<bodyPiece> snakeBody;
+
+ // Function Prototypes
+ char moveSnake(ledCube cube); // Moves the snake by one in the direction of movementDirection
+ // Will return 1 if out of bounds or if the head has hit a bodyPiece, 0 if still in the boundaries
+ void addPiece(); // Adds a bodyPiece to the tail
+ bool isEating(char foodRow, char foodCol);
private:
- std::list<bodyPiece> snakeBody;
- int bodySize;
+ char move(char newHeadRow, char newHeadCol, ledCube cube);
};
class food
@@ -28,3 +47,5 @@
food(char row, char col);
void moveFood(char row, char col);
};
+
+#endif // SNAKE_H
\ No newline at end of file