Snake game for a 5x5 LED matrix

Dependencies:   MCP23S17 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers snake.h Source File

snake.h

00001 #include "mbed.h"
00002 #include "bodyPiece.h"
00003 #include <list>
00004 #include "ledCube.h"
00005 
00006 #ifndef SNAKE_H
00007 #define SNAKE_H
00008 
00009 // Macros
00010 #define START_DIRECTION Down
00011 #define START_SPEED 10
00012 // Zero indexed number of columns and rows
00013 #define NUM_COLS 4
00014 #define NUM_ROWS 4
00015 
00016 typedef enum {
00017     Up,Down,Left,Right
00018 } Direction;
00019 
00020 class snake
00021 {
00022 public:
00023 
00024     // constructor
00025     snake(char startRow, char startCol);
00026     
00027     // public variables
00028     int movementSpeed; // Speed at which the snake is moving
00029     Direction movementDirection; // Direction in which the snake is moving
00030     int bodySize; // Size of the snake's body
00031     std::list<bodyPiece> snakeBody;
00032     
00033     // Function Prototypes
00034     char moveSnake(ledCube *cube); // Moves the snake by one in the direction of movementDirection
00035                       // Will return 1 if out of bounds or if the head has hit a bodyPiece, 0 if still in the boundaries
00036     void addPiece(); // Adds a bodyPiece to the tail
00037     bool isEating(char foodRow, char foodCol);
00038 
00039 private:
00040     char move(char newHeadRow, char newHeadCol, ledCube *cube);
00041 };
00042 
00043 class food
00044 {
00045 public:
00046     char currRow, currCol;
00047     food(char row, char col);
00048     void moveFood(char row, char col);
00049 };
00050 
00051 #endif // SNAKE_H