Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: GameEngine/WinLoose/WinLoose.cpp
- Revision:
- 83:329da564799a
- Parent:
- 63:205f0ca48473
- Child:
- 85:d50ba0994676
--- a/GameEngine/WinLoose/WinLoose.cpp Mon May 06 10:49:50 2019 +0000 +++ b/GameEngine/WinLoose/WinLoose.cpp Mon May 06 14:28:35 2019 +0000 @@ -10,47 +10,53 @@ } -int WinLoose::LevelComplete(N5110 &lcd, Gamepad &pad, int level) +void WinLoose::init(N5110 *lcd, Gamepad *pad) +{ + _lcd = lcd; + _pad = pad; +} + +int WinLoose::LevelComplete(int level) { level += 1; - lcd.clear(); - lcd.printString("Level Complete",0,1); - lcd.printString("Press Start",10,3); - lcd.printString("to Proceed",12,4); - lcd.refresh(); + _lcd->clear(); + _lcd->printString("Level Complete",0,1); + _lcd->printString("Press Start",10,3); + _lcd->printString("to Proceed",12,4); + _lcd->refresh(); wait(0.05); //to avoid race condition of skipping the following while loop. - while ((pad.check_event(Gamepad::START_PRESSED) == false)&&(pad.check_event(Gamepad::A_PRESSED) == false)) { - pad.leds_on(); - pad.tone(rand()%1001,0.1); //helps to set max freq for random sound + while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) { + _pad->leds_on(); + _pad->tone(rand()%1001,0.1); //helps to set max freq for random sound wait(0.1); - pad.leds_off(); + _pad->leds_off(); wait(0.1); } - WinLoose::displayLevel(lcd, level); + WinLoose::displayLevel(level); return level; } -void WinLoose::displayLevel(N5110 &lcd, int level) +void WinLoose::displayLevel(int level) { - lcd.clear(); + _lcd->clear(); sprintf(bufferlevel,"%d",level); - lcd.printString("Level:",25,1); - lcd.printString(bufferlevel,40,3); - lcd.refresh(); + _lcd->printString("Level:",25,1); + _lcd->printString(bufferlevel,40,3); + _lcd->refresh(); wait(2); } -void WinLoose::GameOver(N5110 &lcd, Gamepad &pad) +void WinLoose::GameOver() { - //pad.init(); - while ((pad.check_event(Gamepad::BACK_PRESSED) == false)) { - lcd.clear(); - lcd.printString("Game",33,1); - lcd.printString("Over",33,3); - lcd.printString("Press Back",14,5); //Function used to promt the user to Restart. - lcd.refresh(); + //_pad->init(); + while ((_pad->check_event(Gamepad::BACK_PRESSED) == false)) { + _lcd->clear(); + _lcd->printString("Game",33,1); + _lcd->printString("Over",33,3); + _lcd->printString("Press Back",14,5); //Function used to promt the user to Restart. + _lcd->refresh(); wait(0.1); } - lcd.clear(); + _lcd->clear(); //NVIC_SystemReset(); //Software Reset. } \ No newline at end of file