Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Wed May 08 16:39:24 2019 +0000
Revision:
87:871d9fecb593
Parent:
85:d50ba0994676
I have changed some variable names so that they have more meaning, and also added some more comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AhmedPlaymaker 44:cd10d07ea1e5 1 #include "WinLoose.h"
AhmedPlaymaker 44:cd10d07ea1e5 2
AhmedPlaymaker 44:cd10d07ea1e5 3 WinLoose::WinLoose()
AhmedPlaymaker 44:cd10d07ea1e5 4 {
AhmedPlaymaker 44:cd10d07ea1e5 5
AhmedPlaymaker 44:cd10d07ea1e5 6 }
AhmedPlaymaker 44:cd10d07ea1e5 7
AhmedPlaymaker 44:cd10d07ea1e5 8 WinLoose::~WinLoose()
AhmedPlaymaker 44:cd10d07ea1e5 9 {
AhmedPlaymaker 44:cd10d07ea1e5 10
AhmedPlaymaker 44:cd10d07ea1e5 11 }
AhmedPlaymaker 44:cd10d07ea1e5 12
AhmedPlaymaker 83:329da564799a 13 void WinLoose::init(N5110 *lcd, Gamepad *pad)
AhmedPlaymaker 83:329da564799a 14 {
AhmedPlaymaker 83:329da564799a 15 _lcd = lcd;
AhmedPlaymaker 83:329da564799a 16 _pad = pad;
AhmedPlaymaker 83:329da564799a 17 }
AhmedPlaymaker 83:329da564799a 18
AhmedPlaymaker 83:329da564799a 19 int WinLoose::LevelComplete(int level)
AhmedPlaymaker 44:cd10d07ea1e5 20 {
AhmedPlaymaker 44:cd10d07ea1e5 21 level += 1;
AhmedPlaymaker 83:329da564799a 22 _lcd->clear();
AhmedPlaymaker 83:329da564799a 23 _lcd->printString("Level Complete",0,1);
AhmedPlaymaker 83:329da564799a 24 _lcd->printString("Press Start",10,3);
AhmedPlaymaker 83:329da564799a 25 _lcd->printString("to Proceed",12,4);
AhmedPlaymaker 83:329da564799a 26 _lcd->refresh();
AhmedPlaymaker 63:205f0ca48473 27 wait(0.05); //to avoid race condition of skipping the following while loop.
AhmedPlaymaker 83:329da564799a 28 while ((_pad->check_event(Gamepad::START_PRESSED) == false)&&(_pad->check_event(Gamepad::A_PRESSED) == false)) {
AhmedPlaymaker 83:329da564799a 29 _pad->leds_on();
AhmedPlaymaker 83:329da564799a 30 _pad->tone(rand()%1001,0.1); //helps to set max freq for random sound
AhmedPlaymaker 44:cd10d07ea1e5 31 wait(0.1);
AhmedPlaymaker 83:329da564799a 32 _pad->leds_off();
AhmedPlaymaker 44:cd10d07ea1e5 33 wait(0.1);
AhmedPlaymaker 44:cd10d07ea1e5 34 }
AhmedPlaymaker 83:329da564799a 35 WinLoose::displayLevel(level);
AhmedPlaymaker 49:441c32f6603e 36 return level;
AhmedPlaymaker 49:441c32f6603e 37 }
AhmedPlaymaker 49:441c32f6603e 38
AhmedPlaymaker 83:329da564799a 39 void WinLoose::displayLevel(int level)
AhmedPlaymaker 49:441c32f6603e 40 {
AhmedPlaymaker 87:871d9fecb593 41 _lcd->clear();
AhmedPlaymaker 44:cd10d07ea1e5 42 sprintf(bufferlevel,"%d",level);
AhmedPlaymaker 83:329da564799a 43 _lcd->printString("Level:",25,1);
AhmedPlaymaker 83:329da564799a 44 _lcd->printString(bufferlevel,40,3);
AhmedPlaymaker 87:871d9fecb593 45 _lcd->refresh();
AhmedPlaymaker 44:cd10d07ea1e5 46 wait(2);
AhmedPlaymaker 44:cd10d07ea1e5 47 }
AhmedPlaymaker 63:205f0ca48473 48
AhmedPlaymaker 83:329da564799a 49 void WinLoose::GameOver()
AhmedPlaymaker 44:cd10d07ea1e5 50 {
AhmedPlaymaker 83:329da564799a 51 //_pad->init();
AhmedPlaymaker 83:329da564799a 52 while ((_pad->check_event(Gamepad::BACK_PRESSED) == false)) {
AhmedPlaymaker 83:329da564799a 53 _lcd->clear();
AhmedPlaymaker 83:329da564799a 54 _lcd->printString("Game",33,1);
AhmedPlaymaker 83:329da564799a 55 _lcd->printString("Over",33,3);
AhmedPlaymaker 83:329da564799a 56 _lcd->printString("Press Back",14,5); //Function used to promt the user to Restart.
AhmedPlaymaker 83:329da564799a 57 _lcd->refresh();
AhmedPlaymaker 44:cd10d07ea1e5 58 wait(0.1);
AhmedPlaymaker 44:cd10d07ea1e5 59 }
AhmedPlaymaker 83:329da564799a 60 _lcd->clear();
AhmedPlaymaker 49:441c32f6603e 61 //NVIC_SystemReset(); //Software Reset.
AhmedPlaymaker 44:cd10d07ea1e5 62 }