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.
Dependencies: N5110 PinDetect PowerControl mbed
main.h
00001 /** 00002 @file main.h 00003 @brief Header file for Snake, containing functions prototypes and global variables. 00004 @brief Revision 1.0. 00005 @author Fiifi Mills 00006 @date May 2015 00007 */ 00008 00009 #include "mbed.h" 00010 #include "N5110.h" 00011 #include "PinDetect.h" 00012 #include "PowerControl/PowerControl.h" 00013 #include "PowerControl/EthernetPowerControl.h" 00014 #include <vector> 00015 #include <stdlib.h> /* srand, rand */ 00016 #include <time.h> 00017 00018 /** 00019 Enumerated type used for directions read from joystick 00020 */ 00021 00022 enum DirectionName { 00023 UP, 00024 DOWN, 00025 LEFT, 00026 RIGHT, 00027 CENTRE, 00028 UNKNOWN 00029 }; 00030 00031 DirectionName currentDirection ; /*!< DirectionName variable used to refer to the joystick's current direction */ 00032 DirectionName previousDirection ; /*!< DirectionName variable used to refer to the snake's previous direction */ 00033 00034 /** 00035 Enumerated type used to display different game menu screens 00036 */ 00037 00038 enum GameMenu { 00039 STARTUP, 00040 SELECTSPEED, 00041 GAMEPLAY 00042 }; 00043 00044 GameMenu currentGameMenu ; /*!< GameMenu variable used to refer to the current game menu being displayed */ 00045 00046 /** 00047 Struct used for creating coordinates 00048 */ 00049 00050 struct coordinate { 00051 int x; 00052 int y; 00053 }; 00054 00055 00056 /** 00057 Various flags used in the game for notification of specific events 00058 */ 00059 00060 int printFlag; /*!< print flag set in ISR */ 00061 int Aflag ; /*!< Aflag set in ISR when button A pressed */ 00062 int Bflag ; /*!< Bflag set in ISR when button B pressed */ 00063 int collisionFlag ; /*!< collisionflag set in moveSnake() when snake collides with self */ 00064 int borderFlag ; /*!< borderflag set when snake collides with border in insane mode */ 00065 00066 /** 00067 Global variables 00068 */ 00069 00070 int score; /*!< The score that the user has accumulated throughout the game */ 00071 int xCentre ; /*!< The x coordinate of the centre of the selection circle used in the SELECTSPEED game menu */ 00072 int yCentre ; /*!< The y coordinate of the centre of the selection circle used in the SELECTSPEED game menu */ 00073 bool gameOver ; /*!< Boolean variable signifying whether or not the game is over */ 00074 float speed ; /*!< The wait time used in the moveSnake function */ 00075 00076 00077 /** 00078 Implements the actual game's functionality by moving the snake and checking when certain rules have been broken 00079 */ 00080 void moveSnake(); 00081 00082 /** 00083 Moves the selection circle in the SELECTSPEED game menu either up or down depending on the direction in which the joystick is moved 00084 */ 00085 void speedSelect(); 00086 00087 /** 00088 Vector that contains coordinate structs, represents the snake in game 00089 */ 00090 std::vector<coordinate> Snake; 00091
Generated on Tue Jul 12 2022 22:52:47 by
1.7.2