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: mbed
Game/Game.h@7:8d381315f72c, 2020-05-26 (annotated)
- Committer:
- ale_carb0ni
- Date:
- Tue May 26 22:53:42 2020 +0000
- Revision:
- 7:8d381315f72c
- Parent:
- 6:a2c72def99f9
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ale_carb0ni | 2:7fa08670b1fc | 1 | #ifndef GAME_H |
ale_carb0ni | 2:7fa08670b1fc | 2 | #define GAME_H |
ale_carb0ni | 2:7fa08670b1fc | 3 | |
ale_carb0ni | 2:7fa08670b1fc | 4 | #include "mbed.h" |
ale_carb0ni | 2:7fa08670b1fc | 5 | #include "Gamepad.h" |
ale_carb0ni | 2:7fa08670b1fc | 6 | #include "N5110.h" |
ale_carb0ni | 2:7fa08670b1fc | 7 | #include <vector> |
ale_carb0ni | 2:7fa08670b1fc | 8 | #include "Menu.h" |
ale_carb0ni | 2:7fa08670b1fc | 9 | |
ale_carb0ni | 6:a2c72def99f9 | 10 | /** Game Class |
ale_carb0ni | 6:a2c72def99f9 | 11 | * @brief controls the functioning of the game |
ale_carb0ni | 6:a2c72def99f9 | 12 | * @author Alessandro Carboni |
ale_carb0ni | 6:a2c72def99f9 | 13 | * @date Apr, 2020 |
ale_carb0ni | 6:a2c72def99f9 | 14 | */ |
ale_carb0ni | 6:a2c72def99f9 | 15 | |
ale_carb0ni | 2:7fa08670b1fc | 16 | class Game |
ale_carb0ni | 2:7fa08670b1fc | 17 | { |
ale_carb0ni | 2:7fa08670b1fc | 18 | |
ale_carb0ni | 2:7fa08670b1fc | 19 | private: |
ale_carb0ni | 2:7fa08670b1fc | 20 | |
ale_carb0ni | 2:7fa08670b1fc | 21 | int x; |
ale_carb0ni | 2:7fa08670b1fc | 22 | int y; |
ale_carb0ni | 2:7fa08670b1fc | 23 | int fruitX [16]; |
ale_carb0ni | 2:7fa08670b1fc | 24 | int fruitY [9]; |
ale_carb0ni | 2:7fa08670b1fc | 25 | int score; |
ale_carb0ni | 7:8d381315f72c | 26 | int a; //used to select the direction based ont what button is pressed |
ale_carb0ni | 7:8d381315f72c | 27 | int ntail; //used to increase lenght of the tail |
ale_carb0ni | 2:7fa08670b1fc | 28 | int k; |
ale_carb0ni | 2:7fa08670b1fc | 29 | int rx; |
ale_carb0ni | 2:7fa08670b1fc | 30 | int ry; |
ale_carb0ni | 2:7fa08670b1fc | 31 | char buffer[10]; |
ale_carb0ni | 2:7fa08670b1fc | 32 | int fruitX1; |
ale_carb0ni | 2:7fa08670b1fc | 33 | int fruitY1; |
ale_carb0ni | 2:7fa08670b1fc | 34 | vector <int> x_pos; |
ale_carb0ni | 2:7fa08670b1fc | 35 | vector <int> y_pos; |
ale_carb0ni | 2:7fa08670b1fc | 36 | |
ale_carb0ni | 2:7fa08670b1fc | 37 | public: |
ale_carb0ni | 7:8d381315f72c | 38 | /**Constructor*/ |
ale_carb0ni | 7:8d381315f72c | 39 | Game();//initialises the game |
ale_carb0ni | 2:7fa08670b1fc | 40 | |
ale_carb0ni | 7:8d381315f72c | 41 | /**Reguates the diretion of movement of the snake |
ale_carb0ni | 7:8d381315f72c | 42 | * @param Gamepad class object |
ale_carb0ni | 7:8d381315f72c | 43 | */ |
ale_carb0ni | 2:7fa08670b1fc | 44 | void movement(Gamepad &pad); |
ale_carb0ni | 7:8d381315f72c | 45 | |
ale_carb0ni | 7:8d381315f72c | 46 | /**Regulates the way the snake moves |
ale_carb0ni | 7:8d381315f72c | 47 | */ |
ale_carb0ni | 4:17d5b53b8815 | 48 | void updating_position(); |
ale_carb0ni | 7:8d381315f72c | 49 | |
ale_carb0ni | 7:8d381315f72c | 50 | /**Get value of which button is pressed |
ale_carb0ni | 7:8d381315f72c | 51 | *@ param N5110 class object |
ale_carb0ni | 7:8d381315f72c | 52 | *@ param Gamepad class object |
ale_carb0ni | 7:8d381315f72c | 53 | * @return death value (0,1,2) |
ale_carb0ni | 7:8d381315f72c | 54 | */ |
ale_carb0ni | 3:c61d0c70eda4 | 55 | int death(N5110 &lcd,Gamepad &pad); |
ale_carb0ni | 7:8d381315f72c | 56 | |
ale_carb0ni | 7:8d381315f72c | 57 | /**Draws the game field, the snake and the fruit |
ale_carb0ni | 7:8d381315f72c | 58 | *@ param N5110 class object |
ale_carb0ni | 7:8d381315f72c | 59 | *@ param Gamepad class object |
ale_carb0ni | 7:8d381315f72c | 60 | */ |
ale_carb0ni | 2:7fa08670b1fc | 61 | void draw(N5110 &lcd,Gamepad &pad); |
ale_carb0ni | 7:8d381315f72c | 62 | |
ale_carb0ni | 7:8d381315f72c | 63 | /**Executes what happens when you die |
ale_carb0ni | 7:8d381315f72c | 64 | *@ param N5110 class object |
ale_carb0ni | 7:8d381315f72c | 65 | *@ param Gamepad class object |
ale_carb0ni | 7:8d381315f72c | 66 | */ |
ale_carb0ni | 2:7fa08670b1fc | 67 | void gameover(N5110 &lcd,Gamepad &pad); |
ale_carb0ni | 7:8d381315f72c | 68 | |
ale_carb0ni | 7:8d381315f72c | 69 | /**Increases your points and your lenght when you score |
ale_carb0ni | 7:8d381315f72c | 70 | *@ param N5110 class object |
ale_carb0ni | 7:8d381315f72c | 71 | *@ param Gamepad class object |
ale_carb0ni | 7:8d381315f72c | 72 | */ |
ale_carb0ni | 2:7fa08670b1fc | 73 | void point(N5110 &lcd,Gamepad &pad); |
ale_carb0ni | 2:7fa08670b1fc | 74 | }; |
ale_carb0ni | 4:17d5b53b8815 | 75 | |
ale_carb0ni | 2:7fa08670b1fc | 76 | #endif |