ELEC2645 (2016/17) / Mbed 2 deprecated Bomb_WeixiTao_el16wt

Dependencies:   mbed

main.cpp

Committer:
weixitao
Date:
2017-05-01
Revision:
1:83459533ff72
Parent:
0:1465fd20e75b
Child:
2:23b20cbd3330

File content as of revision 1:83459533ff72:

#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 )
        {
            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;
                }
            
  
            
        }
        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();
     }
}