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
Revision 3:dd4678a85a1a, committed 2017-05-04
- Comitter:
- weixitao
- Date:
- Thu May 04 13:56:12 2017 +0000
- Parent:
- 2:23b20cbd3330
- Child:
- 4:402c27b212c1
- Commit message:
- befor submit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hole/hole.cpp Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,62 @@
+#include "N5110.h"
+#include "hole.h"
+extern N5110 lcd;
+
+//lot out the screen in four parts and the bomb would produce in random place of four parts
+void hole::hole_place()
+{
+ int four = ((rand())%4)+1;
+ switch(four){
+ case 1:
+ //top left
+ /* @X - the abscissa of circle center
+ * @Y - the ordinate of circle center*/
+ holeX = rand()%27+5;
+ holeY = rand()%14+5;
+ break;
+
+ case 2:
+ // top right
+ holeX = rand()%27+47;
+ holeY = rand()%14+5;
+ break;
+
+ case 3:
+ // bass left
+ holeX = rand()%27+5;
+ holeY = rand()%14+29;
+ break;
+
+ case 4:
+ //bass right
+ holeX = rand()%27+47;
+ holeY = rand()%14+29;
+ break;
+}}
+
+void hole::hole_show()
+{
+
+ lcd.drawCircle(holeX,holeY,3,FILL_BLACK);
+
+}
+
+
+bool hole::test(int _x, int _y)
+{
+ int x = _x;
+ int y = _y;
+
+ bool check = false;
+ //when human touch the hole
+ if(x+41-3 <=holeX && holeX <=41+x+1+3 && y+24-3 <=holeY && y+24+6 >=holeY )
+ {
+ printf("Check");
+ check = true;
+ }
+
+ return check;
+}
+
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hole/hole.h Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,37 @@
+#ifndef HOLE_H
+#define HOLE_H
+
+#include "mbed.h"
+#include "N5110.h"
+/**
+@brief hole class for Bomb. Produce a bomb in the random place on screen.
+@author Weixi Tao
+@date 4 May 2017
+*/
+class hole
+{
+ public :
+
+ void hole_place();
+ void hole_show();
+ bool test(int, int);
+
+ private:
+ int holeX;
+ int holeY;
+
+ int holeX1;
+ int holeY1;
+
+ int holeX2;
+ int holeY2;
+
+ int holeX3;
+ int holeY3;
+
+
+
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Human/human.cpp Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,46 @@
+#include "human.h"
+extern N5110 lcd;
+extern Gamepad pad;
+
+
+double human::humanX()
+{
+ while(1) {
+ Vector2D human_x = pad.get_coord();
+ x = (int)(human_x.x*40); //-1 to 1.
+
+ //printf("The value of x(sight) is %i\n",x);
+
+ return x;
+
+
+ }
+}
+
+
+double human::humanY()
+{
+ while(1) {
+ Vector2D human_y = pad.get_coord();
+ y = (int)(-19*human_y.y)-6; //-1 to 1
+
+ //printf("The value of y(sight) is %i\n",y);
+
+ return y;
+ }
+}
+
+
+void human:: print_human()
+{
+ lcd.drawRect(41+x,24+y,3,3,FILL_BLACK); //head
+ lcd.drawLine(41+x+1,24+y+3,41+x+1,24+y+6,1); //body
+ lcd.drawLine(41+x,24+y+4,41+x+2,24+y+4,1);// hands
+ lcd.drawLine(41+x+1,24+y+6,41+x,24+y+7,1);// left leg
+ lcd.drawLine(41+x+1,24+y+6,41+x+2,24+y+7,1);// right leg
+
+ lcd.refresh();
+
+
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Human/human.h Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,25 @@
+#ifndef HUMAN_H
+#define HUMAN_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+class human
+{
+ public :
+
+ void print_human();
+ double humanX();
+ double humanY();
+
+ private:
+
+ int x;
+ int y;
+
+
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Interface/interface.cpp Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,59 @@
+#include "interface.h"
+extern N5110 lcd;
+extern Gamepad pad;
+
+
+void interface::A()
+{
+ lcd.drawLine(16,15,16,24,1);//left 9
+ lcd.drawLine(16,15,24,15,1);//top 9
+ lcd.drawLine(24,15,24,24,1);//right
+ lcd.drawLine(16,24,24,24,1);//bass
+ lcd.printString("A", 18,2);
+ lcd.drawLine(20,15,20,10,1);
+ lcd.drawLine(20,24,20,40,1);
+}
+
+void interface::B()
+{
+ lcd.drawLine(31,15,31,24,1);
+ lcd.drawLine(31,15,39,15,1);
+ lcd.drawLine(31,24,39,24,1);
+ lcd.drawLine(39,15,39,24,1);
+ lcd.printString("B", 33,2);
+ lcd.drawLine(35,15,35,10,1);
+ lcd.drawLine(35,24,35,40,1);
+}
+
+void interface::X()
+{
+ lcd.drawLine(46,15,46,24,1);
+ lcd.drawLine(46,15,54,15,1);
+ lcd.drawLine(46,24,54,24,1);
+ lcd.drawLine(54,15,54,24,1);
+ lcd.printString("X", 48,2);
+ lcd.drawLine(50,15,50,10,1);
+ lcd.drawLine(50,24,50,40,1);
+
+}
+
+void interface::Y()
+{
+ lcd.drawLine(61,15,61,24,1);
+ lcd.drawLine(61,15,69,15,1);
+ lcd.drawLine(61,24,69,24,1);
+ lcd.drawLine(69,15,69,24,1);
+ lcd.printString("Y", 63,2);
+ lcd.drawLine(65,15,65,10,1);
+ lcd.drawLine(65,24,65,40,1);
+
+}
+
+void interface::border()
+{
+ lcd.drawLine(10,10,76,10,1); //top
+ lcd.drawLine(10,10,10,40,1); //left
+ lcd.drawLine(10,40,76,40,1);//bass
+ lcd.drawLine(76,10,76,40,1);//right
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Interface/interface.h Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,27 @@
+#ifndef INTERFACE_H
+#define INTERFACE_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+class interface
+{
+ public :
+
+ void A();
+ void B();
+ void X();
+ void Y();
+ void border();
+
+ private:
+
+ int x;
+ int y;
+
+
+};
+
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Main/main.cpp Thu May 04 13:56:12 2017 +0000
@@ -0,0 +1,410 @@
+// pre-processor directives //
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "hole.h"
+#include "human.h"
+#include "interface.h"
+
+
+// objects //
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+Gamepad pad;
+hole Blackhole;
+human person;
+interface Interface;
+
+// prototypes //
+void bool_check();
+void A_bomb();
+void B_bomb();
+void X_bomb();
+void Y_bomb();
+void end();
+void welcome();
+void succeed();
+
+// functions //
+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);
+ }
+
+}
+
+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%
+
+ Blackhole.hole_place();
+
+ //printf("First stage\n");
+
+ welcome();
+
+
+ while (1) {
+
+ int four = ((rand())%4)+1; //produce a number between 1 to 4
+ printf("%i\n", four);
+ /*@x - the width of human
+ *@y - the length of human*/
+ x = person.humanX();
+ //printf("Pass one ");
+ y = person.humanY();
+ //printf("Pass two");
+ person.print_human();
+
+ Blackhole.hole_show();
+ lcd.refresh();
+ lcd.clear();
+
+
+ printf("check 1\n");
+ bool check = Blackhole.test(x,y);
+ printf("%i\n",four);
+ pad.check_event(Gamepad::A_PRESSED) == false;
+ pad.check_event(Gamepad::B_PRESSED) == false;
+ pad.check_event(Gamepad::X_PRESSED) == false;
+ pad.check_event(Gamepad::Y_PRESSED) == false;
+ if( pad.check_event(Gamepad::R_PRESSED) == true && check )
+ {
+ //four cases about which button is bomb
+ switch (four){
+
+ case 1 : printf ("bomb_A\n");
+ A_bomb();
+ break;
+
+ case 2 : printf ("bomb_B");
+ B_bomb();
+ break;
+
+ case 3 : printf ("bomb_X");
+ X_bomb();
+ break;
+
+ case 4 : printf ("bomb_Y");
+ Y_bomb();
+ break;
+ }
+
+
+ }
+ lcd.refresh();
+ lcd.clear();
+ }
+
+}
+
+void bool_check()
+{
+
+}
+
+void A_bomb() //when button A is bomb, press A game is over
+{
+ 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;
+ printf("X is pressed");
+ }
+ 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)
+ {
+ succeed();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of A press
+}
+
+
+void B_bomb() // when botton B is bomb, press B game is over
+{
+ 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;
+ printf("X is pressed");
+ }
+ 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();
+ }
+ if(fourth)
+ {
+ Interface.Y();
+ }
+ if(check1 && check2 && check3)
+ {
+ succeed();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of B press
+}
+
+void X_bomb() //when botton X is bomb, press X game is over
+{
+ 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;
+ printf("B is pressed");
+ }
+ 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)
+ {
+ succeed();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of X press
+}
+
+void Y_bomb() // when botton Y is bomb, press Y game is over
+{
+ 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;
+ printf("A is pressed");
+ }
+ 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)
+ {
+ succeed();
+ }
+ Interface.border();
+ lcd.refresh();
+ lcd.clear();
+ } // end of Y press
+}
+
+ void end()//press the wrong button
+{
+ pad.tone(800.0, 1);
+ // wait flashing LEDs until back button is pressed
+ pad.check_event(Gamepad::BACK_PRESSED) == false;
+ while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
+ pad.leds_on();
+ wait(0.1);
+ pad.leds_off();
+ wait(0.1);
+
+ lcd.printString(" Game Over ",0,2);
+ lcd.refresh();
+ lcd.clear();
+ }
+ main();
+}
+
+void succeed() //press three right button
+{
+ lcd.refresh();
+ lcd.clear();
+ // wait flashing LEDs until back button is pressed
+ pad.check_event(Gamepad::BACK_PRESSED) == false;
+ while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
+ pad.leds_on();
+ wait(0.1);
+ pad.leds_off();
+ wait(0.1);
+
+ lcd.printString("Congratulation",0,2);
+ lcd.refresh();
+ lcd.clear();
+ }
+ main();
+
+}
+
+
+
+
\ No newline at end of file
--- a/Treasure.cpp Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#include "Treasure.h"
-#include "N5110.h"
-extern N5110 lcd;
-
-void Treasure::treasure_place()
-{
-
-
- TreasureX = rand()%70+5;
- TreasureY = rand()%30+5;
-
-}
-
-void Treasure::treasure_show()
-{
-
- lcd.drawRect(TreasureX,TreasureY,10,8,FILL_BLACK);
- lcd.drawRect(TreasureX+2,TreasureY+1,6,4,FILL_WHITE);
- lcd.drawRect(TreasureX+4,TreasureY+2,2,2,FILL_BLACK);
- //printf("The treasure is displayed");
-
-}
\ No newline at end of file
--- a/Treasure.h Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#ifndef TREASURE_H
-#define TREASURE_H
-
-#include "mbed.h"
-#include "N5110.h"
-
-class Treasure
-{
- public :
-
- void treasure_place();
- void treasure_show();
-
- private:
- int TreasureX;
- int TreasureY;
-
-};
-
-
-#endif
\ No newline at end of file
--- a/hole.cpp Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-#include "Treasure.h"
-#include "N5110.h"
-#include "hole.h"
-extern N5110 lcd;
-
-void hole::hole_place()
-{
- int four = ((rand())%4)+1;
- switch(four){
- case 1:
- //top left
- holeX = rand()%27+5;
- holeY = rand()%14+5;
- break;
-
- case 2:
- // top right
- holeX = rand()%27+47;
- holeY = rand()%14+5;
- break;
-
- case 3:
- // button left
- holeX = rand()%27+5;
- holeY = rand()%14+29;
- break;
-
- case 4:
- //button right
- holeX = rand()%27+47;
- holeY = rand()%14+29;
- break;
-}}
-
-void hole::hole_show()
-{
-
- lcd.drawCircle(holeX,holeY,3,FILL_BLACK);
-// lcd.drawCircle(holeX1,holeY1,3,FILL_BLACK);
-// lcd.drawCircle(holeX2,holeY2,3,FILL_BLACK);
-// lcd.drawCircle(holeX3,holeY3,3,FILL_BLACK);
-
-
-}
-
-
-bool hole::test(int _x, int _y)
-{
-
- int x = _x;
- int y = _y;
-
- bool check = false;
-
- if(x+41-3 <=holeX && holeX <=41+x+1+3 && y+24-3 <=holeY && y+24+6 >=holeY )
- {
- printf("Check");
- check = true;
- }
-
- return check;
-}
-
-
-
\ No newline at end of file
--- a/hole.h Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#ifndef HOLE_H
-#define HOLE_H
-
-#include "mbed.h"
-#include "N5110.h"
-
-class hole
-{
- public :
-
- void hole_place();
- void hole_show();
- bool test(int, int);
-
- private:
- int holeX;
- int holeY;
-
- int holeX1;
- int holeY1;
-
- int holeX2;
- int holeY2;
-
- int holeX3;
- int holeY3;
-
-
-
-};
-
-
-#endif
\ No newline at end of file
--- a/human.cpp Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-#include "human.h"
-extern N5110 lcd;
-extern Gamepad pad;
-
-
-double human::humanX()
-{
- while(1) {
- Vector2D human_x = pad.get_coord();
- x = (int)(human_x.x*40); //-1 to 1.
-
- //printf("The value of x(sight) is %i\n",x);
-
- return x;
-
-
- }
-}
-
-
-double human::humanY()
-{
- while(1) {
- Vector2D human_y = pad.get_coord();
- y = (int)(-19*human_y.y)-6; //-1 to 1
-
- //printf("The value of y(sight) is %i\n",y);
-
- return y;
- }
-}
-
-
-void human:: print_human()
-{
- lcd.drawRect(41+x,24+y,3,3,FILL_BLACK); //head
- lcd.drawLine(41+x+1,24+y+3,41+x+1,24+y+6,1); //body
- lcd.drawLine(41+x,24+y+4,41+x+2,24+y+4,1);// hands
- lcd.drawLine(41+x+1,24+y+6,41+x,24+y+7,1);// left leg
- lcd.drawLine(41+x+1,24+y+6,41+x+2,24+y+7,1);// right leg
-
- lcd.refresh();
-
-
-
-}
\ No newline at end of file
--- a/human.h Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-#ifndef HUMAN_H
-#define HUMAN_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-class human
-{
- public :
-
- void print_human();
- double humanX();
- double humanY();
-
- private:
-
- int x;
- int y;
-
-
-};
-
-
-#endif
\ No newline at end of file
--- a/interface.cpp Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-#include "interface.h"
-extern N5110 lcd;
-extern Gamepad pad;
-
-
-void interface::A()
-{
- lcd.drawLine(16,15,16,24,1);//left 9
- lcd.drawLine(16,15,24,15,1);//top 9
- lcd.drawLine(24,15,24,24,1);//right
- lcd.drawLine(16,24,24,24,1);//button
- lcd.printString("A", 18,2);
- lcd.drawLine(20,15,20,10,1);
- lcd.drawLine(20,24,20,40,1);
-}
-
-void interface::B()
-{
- lcd.drawLine(31,15,31,24,1);
- lcd.drawLine(31,15,39,15,1);
- lcd.drawLine(31,24,39,24,1);
- lcd.drawLine(39,15,39,24,1);
- lcd.printString("B", 33,2);
- lcd.drawLine(35,15,35,10,1);
- lcd.drawLine(35,24,35,40,1);
-}
-
-void interface::X()
-{
- lcd.drawLine(46,15,46,24,1);
- lcd.drawLine(46,15,54,15,1);
- lcd.drawLine(46,24,54,24,1);
- lcd.drawLine(54,15,54,24,1);
- lcd.printString("X", 48,2);
- lcd.drawLine(50,15,50,10,1);
- lcd.drawLine(50,24,50,40,1);
-
-
-}
-
-void interface::Y()
-{
- lcd.drawLine(61,15,61,24,1);
- lcd.drawLine(61,15,69,15,1);
- lcd.drawLine(61,24,69,24,1);
- lcd.drawLine(69,15,69,24,1);
- lcd.printString("Y", 63,2);
- lcd.drawLine(65,15,65,10,1);
- lcd.drawLine(65,24,65,40,1);
-}
-
-void interface::border()
-{
- lcd.drawLine(10,10,76,10,1); //top
- lcd.drawLine(10,10,10,40,1); //left
- lcd.drawLine(10,40,76,40,1);//button
- lcd.drawLine(76,10,76,40,1);//right
-}
\ No newline at end of file
--- a/interface.h Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#ifndef INTERFACE_H
-#define INTERFACE_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-class interface
-{
- public :
-
- void A();
- void B();
- void X();
- void Y();
- void border();
-
- private:
-
- int x;
- int y;
-
-
-};
-
-
-#endif
\ No newline at end of file
--- a/main.cpp Mon May 01 16:37:53 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,396 +0,0 @@
-#include "mbed.h"
-#include "N5110.h"
-#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();
-
-
- printf("check 1\n");
- bool check = Blackhole.test(x,y);
- printf("%i\n",four);
- if( pad.check_event(Gamepad::R_PRESSED) == true && check )
- {
-
- 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;
- }
-
-
-
- }
- 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();
-
- }
- 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