Yufan Zhong / Mbed 2 deprecated GOLD_MINER

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* 
00002 ELEC2645 Embedded Systems Project 
00003 School of Electronic & Electrical Engineering 
00004 University of Leeds 
00005 
00006 Name: Yufan Zhong
00007 Username: el17yz
00008 Student ID Number: 201199708
00009 Date: May,2020
00010 
00011 */ 
00012  
00013 
00014 ///////// pre-processor directives ////////
00015 #include "mbed.h"
00016 #include "Gamepad.h"
00017 #include "N5110.h"
00018 #include "MinerEngine.h"
00019 
00020 #ifdef DEBUG
00021 # include "tests.h"
00022 #endif
00023 
00024 #define WINCH_WIDTH 12
00025 #define WINCH_HEIGHT 6
00026 #define CLAW_SPEED 3
00027 #define MONSTER_SIZE 3
00028 #define MONSTER_SPEED 1
00029 #define GOLD_NUM 9
00030 /////////////// structs /////////////////
00031 struct UserInput {
00032     Direction d;
00033     float mag;
00034 };
00035 /////////////// objects ///////////////
00036 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00037 Gamepad pad;
00038 MinerEngine miner;
00039 
00040 ///////////// prototypes ///////////////
00041 void init();
00042 
00043 ///////////// functions ////////////////
00044 int main()
00045 {
00046      
00047 #ifdef DEBUG
00048     int number_of_failures = run_all_tests();
00049 
00050     if(number_of_failures > 0) return number_of_failures;
00051 #endif
00052 
00053     init();     // initialise and then display welcome screen...
00054     miner.welcome(pad,lcd);  // waiting for the user to start
00055      
00056     // game loop - switch the state - read input, update the game state and render the display
00057     while (1) {
00058          miner.state_switch(pad,lcd);
00059     }
00060 }
00061 
00062 // initialies all classes and libraries
00063 void init()
00064 {
00065     // need to initialise LCD and Gamepad 
00066     lcd.init();
00067     pad.init();
00068     // initialise the game with correct winch sizes, gold number and monster speed
00069     miner.init(WINCH_WIDTH,WINCH_HEIGHT,GOLD_NUM,MONSTER_SPEED);
00070     miner.init_unchanged_parameter(); //initialise the highest score
00071 }