Li Ruofan 201199450
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:bd7c99a5bd10
- Parent:
- 0:80a59a49d504
--- a/main.cpp Sat May 23 19:01:15 2020 +0000 +++ b/main.cpp Sun May 24 08:16:35 2020 +0000 @@ -21,16 +21,14 @@ Gamepad pad; Snake snake; -int bgm_(); int sound_(); void begin(); void init(Gamepad &pad); -void game_tips(); +void game_rules(); int main() { init(pad); - // game loop while (1) { snake.draw(lcd); snake.update(pad); @@ -45,8 +43,8 @@ begin(); snake.init(25,25,6,1); // initialise parameters of the project - // display tips - game_tips(); + // display rules + game_rules(); } void begin(){ @@ -69,7 +67,7 @@ } -void game_tips(){ +void game_rules(){ lcd.clear(); lcd.printString(" Greedy Snake! ",0,0); lcd.printString(" Move the snake ",0,1); @@ -81,9 +79,9 @@ while (pad.check_event(Gamepad::START_PRESSED) == false) { pad.leds_on(); wait(0.2); - pad.leds_off(); - wait(0.2); -} + } + + lcd.clear(); } int sound_(){ @@ -167,7 +165,6 @@ if(pad.check_event(Gamepad::X_PRESSED) == true){ return 0; } - pad.tone(440.0,0.3); wait(0.3); if(pad.check_event(Gamepad::X_PRESSED) == true){ @@ -178,7 +175,110 @@ if(pad.check_event(Gamepad::X_PRESSED) == true){ return 0; } + pad.tone(659.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ return 0; - }//play the Chinese song "East is Red" - - \ No newline at end of file + } + pad.tone(659.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(587.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(523.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(523.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(659.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(784.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(1046.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(1046.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(1046.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(880.0f,0.5f); + wait(0.5f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(784.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(784.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(880.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(784.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(659.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(523.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(587.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(587.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(659.0f,0.3f); + wait(0.3f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + pad.tone(587.0f,0.2f); + wait(0.2f); + if(pad.check_event(Gamepad::X_PRESSED) == true){ + return 0; + } + return 0; + }//play Chinese song "East is Red" and Australian song "Sheep clippling"