Zeyu Feng 201377605
Dependencies: mbed
On Minerva
Interface/Interface.cpp
- Committer:
- el19zf
- Date:
- 2020-05-11
- Revision:
- 11:494cc44777fe
- Child:
- 12:009895f6b6e4
File content as of revision 11:494cc44777fe:
#include "Interface.h" State fsm[3] = { {0,{2,1}}, {1,{0,2}}, {2,{1,0}}, }; const int pointer[3][2] = { {1,0}, {1,1}, {1,0} }; Interface::Interface() { } Interface::~Interface() { } void Interface::init() { } void Interface::Welcome(N5110 &lcd,Gamepad &pad) { lcd.printString(" Welcome! ",0,1); lcd.printString(" Game by ",0,2); lcd.printString(" Z. FENG ",0,3); lcd.refresh(); while (!pad.start_pressed()) { pad.leds_on(); wait(0.1); pad.leds_off(); wait(0.1); } } int Interface::menu(N5110 &lcd,Gamepad &pad,int option_flag) { while (!pad.A_pressed()) { lcd.clear(); lcd.printString(" MENU",0,0); lcd.printString(" Start",0,2); lcd.printString(" Start(Hell)",0,3); lcd.printString(" Exit",0,4); _d = pad.get_direction(); if(_d == N){ option_flag = fsm[option_flag].next_state[0]; } else if(_d == S){ option_flag = fsm[option_flag].next_state[1]; } lcd.drawSprite(0,8*option_flag+18,3,2,(int*)pointer); lcd.refresh(); pad.leds_on(); wait(0.3); //printf("A_pressed\n"); } return option_flag; } void Interface::game_over(N5110 &lcd,Gamepad &pad) { lcd.clear(); while(!pad.B_pressed()){ lcd.printString(" Game over ",0,1); lcd.printString(" Press B to ",0,2); lcd.printString(" try again? ",0,3); lcd.refresh(); wait(0.1); //printf("Not press B\n"); } } int Interface::check_pause(N5110 &lcd,Gamepad &pad,int paused_flag) { if(pad.start_pressed()) paused_flag = 1; //printf("start press\n"); while(paused_flag == 1){ _timer.stop(); lcd.printString("Paused",23,2); lcd.refresh(); if(pad.start_pressed()) paused_flag = 0; } _timer.start(); return paused_flag; } int Interface::count_down(N5110 &lcd,int count_flag) { char buffer[6]; sprintf(buffer,"%d",(int)count_flag/6); lcd.printString(buffer,40,2); //printf("count: %d\n",count_flag); count_flag--; return count_flag; } void Interface::exit(N5110 &lcd,Gamepad &pad) { lcd.clear(); while(!pad.B_pressed()){ lcd.printString(" Press B back ",0,2); lcd.printString(" to menu ",0,3); lcd.refresh(); wait(0.1); } } void Interface::victory(N5110 &lcd,Gamepad &pad) { lcd.clear(); while(!pad.B_pressed()){ lcd.printString(" Victory! ",0,1); lcd.printString(" Press B back ",0,2); lcd.printString(" to menu ",0,3); lcd.refresh(); wait(0.1); } }