Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:83459533ff72
- Parent:
- 0:1465fd20e75b
- Child:
- 2:23b20cbd3330
diff -r 1465fd20e75b -r 83459533ff72 main.cpp
--- a/main.cpp Wed Apr 26 16:38:33 2017 +0000
+++ b/main.cpp Mon May 01 15:20:26 2017 +0000
@@ -3,48 +3,394 @@
#include "Gamepad.h"
#include "Treasure.h"
#include "hole.h"
+#include "human.h"
+#include "interface.h"
+
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Treasure treasure;
hole Blackhole;
+human person;
+interface Interface;
+void bool_check();
+void A_bomb();
+void B_bomb();
+void X_bomb();
+void Y_bomb();
+void end();
+void welcome();
+void render();
+
+
+void welcome() {
+
+ lcd.printString(" Bomb! ",0,1);
+ lcd.printString(" Press Start ",0,4);
+ lcd.refresh();
+
+ // wait flashing LEDs until start button is pressed
+ while ( pad.check_event(Gamepad::START_PRESSED) == false) {
+ pad.leds_on();
+ wait(0.1);
+ pad.leds_off();
+ wait(0.1);
+ }
+
+}
+
+void render()
+{
+ // clear screen, re-draw and refresh
+ lcd.clear();
+
+ lcd.refresh();
+}
+
int main()
{
+ double x;
+ double y;
+
lcd.init();
pad.init();
lcd.clear();
lcd.normalMode(); // normal colour mode
lcd.setBrightness(0.5); // put LED backlight on 50%
+
+
treasure.treasure_place();
Blackhole.hole_place();
+
+ //printf("First stage\n");
+
+ welcome();
+
+
+ while (1) {
+//
+
+ int four = ((rand())%4)+1;
+ printf("%i\n", four);
+ x = person.humanX();
+ //printf("Pass one ");
+ y = person.humanY();
+ //printf("Pass two");
+ person.print_human();
+
+ Blackhole.hole_show();
+ lcd.refresh();
+ lcd.clear();
- while (1) {
-
- if( pad.check_event(Gamepad::START_PRESSED) == true){
- treasure.treasure_place();
- Blackhole.hole_place();
- lcd.clear();
- lcd.refresh();
+ printf("check 1\n");
+ bool check = Blackhole.test(x,y);
+ printf("%i\n",four);
+ if( pad.check_event(Gamepad::R_PRESSED) == true && check )
+ {
+ printf("taoweixi");
+ switch (four){
+
+ case 1 :
+ printf ("bomb_A\n");
+ A_bomb();
+
+ break;
+ case 2 : B_bomb();
+ printf ("bomb_B");
+
+ break;
+ case 3 : X_bomb();
+ printf ("bomb_X");
+
+ break;
+ case 4 : Y_bomb();
+ printf ("bomb_Y");
+
+ break;
+ }
+
+
+
}
- Blackhole.hole_show();
- treasure.treasure_show();
- lcd.drawRect(40,20,3,3,FILL_BLACK); //head
- lcd.drawLine(41,23,41,26,1); //right hand
- lcd.drawLine(40,26,42,26,1);// body2
- lcd.drawLine(40,26,40,29,1);// body1
- lcd.drawLine(42,26,42,29,1);// right leg
- lcd.drawLine(38,24,42,24,1);//
- lcd.drawLine(42,24,43,25,1);// right hand
- lcd.drawLine(38,22,38,25,1);
- lcd.drawLine(37,22,37,25,1);
lcd.refresh();
+ lcd.clear();
+ }
+
+}
+
+void bool_check()
+{
+
+}
+
+void A_bomb()
+{
+ bool first = true;
+ bool second = true;
+ bool third = true;
+ bool fourth = true;
+
+ bool check1 = false;
+ bool check2 = false;
+ bool check3 = false;
+
+ bool_check();
+ while(1)
+ {
+ if(pad.check_event(Gamepad::B_PRESSED) == true)
+ {
+ second = false;
+ check1 = true;
+ }
+ else if(pad.check_event(Gamepad::X_PRESSED) == true)
+ {
+ third = false;
+ check2 = true;
+ }
+ else if(pad.check_event(Gamepad::Y_PRESSED) == true)
+ {
+ fourth = false;
+ check3 = true;
+ }
+ else if(pad.check_event(Gamepad::A_PRESSED) == true) // bomb A
+ {
+ end();
+ }
+ lcd.refresh();
+ lcd.clear();
+ if(first)
+ {
+ Interface.A();
+ }
+ if(second)
+ {
+ Interface.B();
+
+ }
+ if(third)
+ {
+ Interface.X();
+
+ }
+ if(fourth)
+ {
+ Interface.Y();
+ }
+ if(check1 && check2 && check3)
+ {
+ main();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of A press
+}
+void B_bomb()
+{
+ bool first = true;
+ bool second = true;
+ bool third = true;
+ bool fourth = true;
+
+ bool check1 = false;
+ bool check2 = false;
+ bool check3 = false;
+
+ bool_check();
+ while(1)
+ {
+ if(pad.check_event(Gamepad::A_PRESSED) == true)
+ {
+ second = false;
+ check1 = true;
+ }
+ else if(pad.check_event(Gamepad::X_PRESSED) == true)
+ {
+ third = false;
+ check2 = true;
+ }
+ else if(pad.check_event(Gamepad::Y_PRESSED) == true)
+ {
+ fourth = false;
+ check3 = true;
+ }
+ else if(pad.check_event(Gamepad::B_PRESSED) == true) // bomb B
+ {
+ end();
+ }
+ lcd.refresh();
+ lcd.clear();
+ if(first)
+ {
+ Interface.B();
+ }
+ if(second)
+ {
+ Interface.A();
+
+ }
+ if(third)
+ {
+ Interface.X();
-
- }
-}
\ No newline at end of file
+ }
+ if(fourth)
+ {
+ Interface.Y();
+ }
+ if(check1 && check2 && check3)
+ {
+ main();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of B press
+}
+
+void X_bomb()
+{
+ bool first = true;
+ bool second = true;
+ bool third = true;
+ bool fourth = true;
+
+ bool check1 = false;
+ bool check2 = false;
+ bool check3 = false;
+
+ bool_check();
+ while(1)
+ {
+ if(pad.check_event(Gamepad::A_PRESSED) == true)
+ {
+ second = false;
+ check1 = true;
+ }
+ else if(pad.check_event(Gamepad::B_PRESSED) == true)
+ {
+ third = false;
+ check2 = true;
+ }
+ else if(pad.check_event(Gamepad::Y_PRESSED) == true)
+ {
+ fourth = false;
+ check3 = true;
+ }
+ else if(pad.check_event(Gamepad::X_PRESSED) == true) // bomb X
+ {
+ end();
+ }
+ lcd.refresh();
+ lcd.clear();
+ if(first)
+ {
+ Interface.X();
+ }
+ if(second)
+ {
+ Interface.A();
+
+ }
+ if(third)
+ {
+ Interface.B();
+
+ }
+ if(fourth)
+ {
+ Interface.Y();
+ }
+ if(check1 && check2 && check3)
+ {
+ main();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of X press
+}
+
+void Y_bomb()
+{
+ bool first = true;
+ bool second = true;
+ bool third = true;
+ bool fourth = true;
+
+ bool check1 = false;
+ bool check2 = false;
+ bool check3 = false;
+
+ bool_check();
+ while(1)
+ {
+ if(pad.check_event(Gamepad::A_PRESSED) == true)
+ {
+ second = false;
+ check1 = true;
+ }
+ else if(pad.check_event(Gamepad::B_PRESSED) == true)
+ {
+ third = false;
+ check2 = true;
+ }
+ else if(pad.check_event(Gamepad::X_PRESSED) == true)
+ {
+ fourth = false;
+ check3 = true;
+ }
+ else if(pad.check_event(Gamepad::Y_PRESSED) == true) // bomb Y
+ {
+ end();
+ }
+ lcd.refresh();
+ lcd.clear();
+ if(first)
+ {
+ Interface.Y();
+ }
+ if(second)
+ {
+ Interface.A();
+
+ }
+ if(third)
+ {
+ Interface.B();
+
+ }
+ if(fourth)
+ {
+ Interface.X();
+ }
+ if(check1 && check2 && check3)
+ {
+ main();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of Y press
+}
+
+ void end()
+{
+ while (1){
+
+ lcd.printString(" Game Over ",0,2);
+ lcd.refresh();
+ lcd.clear();
+ }
+}
+
+
+
+
+
\ No newline at end of file