Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

WinLoose/WinLoose.cpp

Committer:
AhmedPlaymaker
Date:
2019-04-26
Revision:
46:dc7dccae9f9e
Parent:
44:cd10d07ea1e5
Child:
49:441c32f6603e

File content as of revision 46:dc7dccae9f9e:

#include "WinLoose.h"

WinLoose::WinLoose()
{

}

WinLoose::~WinLoose()
{

}

int WinLoose::LevelComplete(N5110 &lcd, Gamepad &pad, 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();
    pad.init(); //to fix an issue with debouncing.
    while (pad.check_event(Gamepad::START_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();
        wait(0.1);
    }
    lcd.clear();
    sprintf(bufferlevel,"%d",level);
    lcd.printString("Level:",25,1);
    lcd.printString(bufferlevel,40,3);
    lcd.refresh();
    wait(2);
    return level;
}
    
void WinLoose::GameOver(N5110 &lcd, Gamepad &pad)
{
    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);
    }
    NVIC_SystemReset(); //Software Reset. //change this condition to loosing screen.
}