Snake game for a 5x5 LED matrix

Dependencies:   MCP23S17 mbed

Committer:
dhamilton31
Date:
Thu Oct 17 22:09:22 2013 +0000
Revision:
2:9c075a0a6d4e
Parent:
1:5fcb94bb03db
Changed one stupid thing (cube) to (*cube) and it worked :P

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dhamilton31 0:dc906408980e 1 #include "mbed.h"
dhamilton31 0:dc906408980e 2 #include "bodyPiece.h"
dhamilton31 0:dc906408980e 3 #include <list>
dhamilton31 1:5fcb94bb03db 4 #include "ledCube.h"
dhamilton31 0:dc906408980e 5
dhamilton31 1:5fcb94bb03db 6 #ifndef SNAKE_H
dhamilton31 1:5fcb94bb03db 7 #define SNAKE_H
dhamilton31 1:5fcb94bb03db 8
dhamilton31 1:5fcb94bb03db 9 // Macros
dhamilton31 2:9c075a0a6d4e 10 #define START_DIRECTION Down
dhamilton31 1:5fcb94bb03db 11 #define START_SPEED 10
dhamilton31 1:5fcb94bb03db 12 // Zero indexed number of columns and rows
dhamilton31 1:5fcb94bb03db 13 #define NUM_COLS 4
dhamilton31 1:5fcb94bb03db 14 #define NUM_ROWS 4
dhamilton31 0:dc906408980e 15
dhamilton31 0:dc906408980e 16 typedef enum {
dhamilton31 0:dc906408980e 17 Up,Down,Left,Right
dhamilton31 0:dc906408980e 18 } Direction;
dhamilton31 0:dc906408980e 19
dhamilton31 0:dc906408980e 20 class snake
dhamilton31 0:dc906408980e 21 {
dhamilton31 0:dc906408980e 22 public:
dhamilton31 1:5fcb94bb03db 23
dhamilton31 1:5fcb94bb03db 24 // constructor
dhamilton31 0:dc906408980e 25 snake(char startRow, char startCol);
dhamilton31 1:5fcb94bb03db 26
dhamilton31 1:5fcb94bb03db 27 // public variables
dhamilton31 1:5fcb94bb03db 28 int movementSpeed; // Speed at which the snake is moving
dhamilton31 1:5fcb94bb03db 29 Direction movementDirection; // Direction in which the snake is moving
dhamilton31 1:5fcb94bb03db 30 int bodySize; // Size of the snake's body
dhamilton31 1:5fcb94bb03db 31 std::list<bodyPiece> snakeBody;
dhamilton31 1:5fcb94bb03db 32
dhamilton31 1:5fcb94bb03db 33 // Function Prototypes
dhamilton31 2:9c075a0a6d4e 34 char moveSnake(ledCube *cube); // Moves the snake by one in the direction of movementDirection
dhamilton31 1:5fcb94bb03db 35 // Will return 1 if out of bounds or if the head has hit a bodyPiece, 0 if still in the boundaries
dhamilton31 1:5fcb94bb03db 36 void addPiece(); // Adds a bodyPiece to the tail
dhamilton31 1:5fcb94bb03db 37 bool isEating(char foodRow, char foodCol);
dhamilton31 0:dc906408980e 38
dhamilton31 0:dc906408980e 39 private:
dhamilton31 2:9c075a0a6d4e 40 char move(char newHeadRow, char newHeadCol, ledCube *cube);
dhamilton31 0:dc906408980e 41 };
dhamilton31 0:dc906408980e 42
dhamilton31 0:dc906408980e 43 class food
dhamilton31 0:dc906408980e 44 {
dhamilton31 0:dc906408980e 45 public:
dhamilton31 0:dc906408980e 46 char currRow, currCol;
dhamilton31 0:dc906408980e 47 food(char row, char col);
dhamilton31 0:dc906408980e 48 void moveFood(char row, char col);
dhamilton31 0:dc906408980e 49 };
dhamilton31 1:5fcb94bb03db 50
dhamilton31 1:5fcb94bb03db 51 #endif // SNAKE_H