submit
Dependencies: mbed Gamepad N5110
Finger Class Reference
#include <Finger.h>
Public Member Functions | |
Finger () | |
Constructor. | |
~Finger () | |
Destructor. | |
void | init () |
Initialise the components of snake. | |
void | draw (N5110 &lcd, Gamepad &pad) |
Draw the finger and scores. | |
void | run (N5110 &lcd, Gamepad &pad) |
Run the game. |
Detailed Description
Finger class.
Class for the finger-guess game It was the game I initially wrote However, I thought this game was too easy and then changed to the sanke game But I still want to add this game for a extra scene
- Date:
- April 2019
///////// pre-processor directives //////// #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "Snake.h" #include "Engine.h" #include "Finger.h" /////////////// objects /////////////// N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; Snake snake; Engine engine; Finger finger; ///////////// prototypes /////////////// void init(); void run(); void over(); ///////////// functions //////////////// int main() { int fps = 8; // frames per second snake.hscore = 0; lcd.init(); while(1){ init(); pad.tone(900.0,0.5); engine.welcome(pad,lcd); // show welcome display, waiting for the user to start engine.menu(pad,lcd); // show the select display, waiting for the user to select // choose game and game loop if(engine.game == 0){ while (snake.over == 0) { run(); // run the snake game while (pad.check_event(Gamepad::START_PRESSED) == true){ engine.pause(pad,lcd); // pause the game } wait(engine.p/fps); // and wait for one frame period } over(); // show gameover display, waiting for the user to restart }else if(engine.game == 1){ finger.run(lcd,pad); // run the finger-geuss game } } } // this function draws each frame on the LCD void run() { // clear screen, re-draw and refresh lcd.clear(); int length = snake.get_length(); int direction = engine.get_direction(pad); snake.check_eat(pad); snake.draw(lcd,length); snake.update(direction,length); snake.check_over(lcd); lcd.refresh(); } // initialies all classes and libraries void init() { // need to initialise LCD and Gamepad pad.init(); snake.init(2,3); engine.init(); finger.init(); lcd.clear(); } //gameover screen void over() { int s = snake.get_score(); // get the scores to show at the gameover display int hs = snake.hscore; engine.gameover(pad,lcd,s,hs); }
Definition at line 103 of file Finger.h.
Constructor & Destructor Documentation
Finger | ( | ) |
Constructor.
Definition at line 4 of file Finger.cpp.
~Finger | ( | ) |
Destructor.
Definition at line 9 of file Finger.cpp.
Member Function Documentation
void draw | ( | N5110 & | lcd, |
Gamepad & | pad | ||
) |
Draw the finger and scores.
This function draws the finger and scores.
- Parameters:
-
lcd - N5110 library length - the length of the snake
Definition at line 77 of file Finger.cpp.
void init | ( | ) |
Initialise the components of snake.
This function gets the length of the snake.
Definition at line 69 of file Finger.cpp.
void run | ( | N5110 & | lcd, |
Gamepad & | pad | ||
) |
Run the game.
This function check which wins and adds socres.
- Parameters:
-
lcd - N5110 library length - the length of the snake
Definition at line 108 of file Finger.cpp.
Generated on Wed Jul 27 2022 17:49:31 by 1.7.2