My ELEC2645 joystick project Tetris Game NAME: JIANWEI CHEN SID: 200879849
Dependencies: N5110 SDFileSystem mbed
main.cpp@4:463abe5f5135, 2016-05-05 (annotated)
- Committer:
- cjw851102
- Date:
- Thu May 05 09:18:01 2016 +0000
- Revision:
- 4:463abe5f5135
- Parent:
- 3:5494a0fb3a33
Final version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cjw851102 | 0:12a1972fa0d0 | 1 | #include "mbed.h" |
cjw851102 | 0:12a1972fa0d0 | 2 | #include "Patterns.h" |
cjw851102 | 0:12a1972fa0d0 | 3 | #include "N5110.h" |
cjw851102 | 4:463abe5f5135 | 4 | #include "SDFileSystem.h" |
cjw851102 | 4:463abe5f5135 | 5 | #include "Joystick.h" |
cjw851102 | 4:463abe5f5135 | 6 | #include "Game.h" |
cjw851102 | 4:463abe5f5135 | 7 | #include "main.h" |
cjw851102 | 2:f427089e2bfa | 8 | |
cjw851102 | 0:12a1972fa0d0 | 9 | int main() |
cjw851102 | 0:12a1972fa0d0 | 10 | { |
cjw851102 | 4:463abe5f5135 | 11 | init(); |
cjw851102 | 4:463abe5f5135 | 12 | while(1) { |
cjw851102 | 4:463abe5f5135 | 13 | if(g_menuTimer_flag) { |
cjw851102 | 4:463abe5f5135 | 14 | g_menuTimer_flag=0; |
cjw851102 | 0:12a1972fa0d0 | 15 | |
cjw851102 | 4:463abe5f5135 | 16 | if (g_button_flag) {// if button pressed, go to next menu according current state and pointer position input |
cjw851102 | 4:463abe5f5135 | 17 | g_button_flag=0; |
cjw851102 | 4:463abe5f5135 | 18 | state=fsm[state].nextState[pointer_position]; |
cjw851102 | 2:f427089e2bfa | 19 | lcd.clear(); |
cjw851102 | 1:2a758565f691 | 20 | } |
cjw851102 | 2:f427089e2bfa | 21 | |
cjw851102 | 4:463abe5f5135 | 22 | switch(state) { |
cjw851102 | 4:463abe5f5135 | 23 | case 0: // main menu |
cjw851102 | 4:463abe5f5135 | 24 | pointer(); |
cjw851102 | 4:463abe5f5135 | 25 | red_led=0; |
cjw851102 | 4:463abe5f5135 | 26 | green_led=0; |
cjw851102 | 4:463abe5f5135 | 27 | lcd.printString("Tetis Game",10,1); |
cjw851102 | 4:463abe5f5135 | 28 | lcd.printString("START",25,3); |
cjw851102 | 4:463abe5f5135 | 29 | lcd.printString("SCORE",25,4); |
cjw851102 | 4:463abe5f5135 | 30 | lcd.refresh(); |
cjw851102 | 4:463abe5f5135 | 31 | break; |
cjw851102 | 4:463abe5f5135 | 32 | case 1: // game level choosing menu |
cjw851102 | 4:463abe5f5135 | 33 | pointer(); |
cjw851102 | 4:463abe5f5135 | 34 | red_led=0; |
cjw851102 | 4:463abe5f5135 | 35 | green_led=0; |
cjw851102 | 4:463abe5f5135 | 36 | lcd.printString("Game Level",10,1); |
cjw851102 | 4:463abe5f5135 | 37 | lcd.printString("EASY",25,3); |
cjw851102 | 4:463abe5f5135 | 38 | lcd.printString("HARD",25,4); |
cjw851102 | 4:463abe5f5135 | 39 | lcd.printString("Back",60,5); |
cjw851102 | 4:463abe5f5135 | 40 | lcd.refresh(); |
cjw851102 | 4:463abe5f5135 | 41 | break; |
cjw851102 | 4:463abe5f5135 | 42 | case 2: // highest score menu |
cjw851102 | 4:463abe5f5135 | 43 | red_led=0; |
cjw851102 | 4:463abe5f5135 | 44 | green_led=0; |
cjw851102 | 4:463abe5f5135 | 45 | lcd.printString("Highest Score:",1,1); |
cjw851102 | 4:463abe5f5135 | 46 | int top_score; |
cjw851102 | 4:463abe5f5135 | 47 | top_score=read_score_SD(); |
cjw851102 | 4:463abe5f5135 | 48 | char score[14]; |
cjw851102 | 4:463abe5f5135 | 49 | sprintf(score,"%d",top_score); |
cjw851102 | 4:463abe5f5135 | 50 | lcd.printString(score,30,3); |
cjw851102 | 4:463abe5f5135 | 51 | lcd.printString("Press Button",0,4); |
cjw851102 | 4:463abe5f5135 | 52 | lcd.printString("To Exit",0,5); |
cjw851102 | 4:463abe5f5135 | 53 | lcd.refresh(); |
cjw851102 | 4:463abe5f5135 | 54 | break; |
cjw851102 | 4:463abe5f5135 | 55 | case 3: // easy game menu |
cjw851102 | 4:463abe5f5135 | 56 | init_game(); |
cjw851102 | 4:463abe5f5135 | 57 | game.attach(&game_isr,0.2); |
cjw851102 | 4:463abe5f5135 | 58 | lcd.printString("easy",42,1); |
cjw851102 | 4:463abe5f5135 | 59 | tetis_game(); |
cjw851102 | 4:463abe5f5135 | 60 | break; |
cjw851102 | 4:463abe5f5135 | 61 | case 4: // hard game menu |
cjw851102 | 4:463abe5f5135 | 62 | init_game(); |
cjw851102 | 4:463abe5f5135 | 63 | game.attach(&game_isr,0.1); |
cjw851102 | 4:463abe5f5135 | 64 | lcd.printString("hard",42,1); |
cjw851102 | 4:463abe5f5135 | 65 | tetis_game(); |
cjw851102 | 4:463abe5f5135 | 66 | break; |
cjw851102 | 0:12a1972fa0d0 | 67 | } |
cjw851102 | 0:12a1972fa0d0 | 68 | } |
cjw851102 | 4:463abe5f5135 | 69 | sleep(); |
cjw851102 | 2:f427089e2bfa | 70 | } |
cjw851102 | 2:f427089e2bfa | 71 | } |