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 Gamepad N5110
main.cpp@0:5fcd72a90b20, 2019-04-26 (annotated)
- Committer:
- 1012754868
- Date:
- Fri Apr 26 04:47:03 2019 +0000
- Revision:
- 0:5fcd72a90b20
- Child:
- 1:db2a69ca4929
Completed the basic function of the game snake, made the game selection interface, and left the highest historical record of the game undone
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 1012754868 | 0:5fcd72a90b20 | 1 | //屏幕开始有蛇的图标 |
| 1012754868 | 0:5fcd72a90b20 | 2 | //主页过了之后选择菜单菜单包含速度历史记录 |
| 1012754868 | 0:5fcd72a90b20 | 3 | //音乐 |
| 1012754868 | 0:5fcd72a90b20 | 4 | /* |
| 1012754868 | 0:5fcd72a90b20 | 5 | 做选项的步骤 |
| 1012754868 | 0:5fcd72a90b20 | 6 | 把选项打印出来 |
| 1012754868 | 0:5fcd72a90b20 | 7 | 移动光标 |
| 1012754868 | 0:5fcd72a90b20 | 8 | 移动到某一个点击确定跳转到一个界面,点击返回返回到设置 |
| 1012754868 | 0:5fcd72a90b20 | 9 | */ |
| 1012754868 | 0:5fcd72a90b20 | 10 | #include "mbed.h" |
| 1012754868 | 0:5fcd72a90b20 | 11 | #include "N5110.h" |
| 1012754868 | 0:5fcd72a90b20 | 12 | #include "Gamepad.h" |
| 1012754868 | 0:5fcd72a90b20 | 13 | |
| 1012754868 | 0:5fcd72a90b20 | 14 | #include "Snake.h" |
| 1012754868 | 0:5fcd72a90b20 | 15 | |
| 1012754868 | 0:5fcd72a90b20 | 16 | /************************Structs************************/ |
| 1012754868 | 0:5fcd72a90b20 | 17 | struct UserInput { |
| 1012754868 | 0:5fcd72a90b20 | 18 | Direction d; |
| 1012754868 | 0:5fcd72a90b20 | 19 | |
| 1012754868 | 0:5fcd72a90b20 | 20 | }; |
| 1012754868 | 0:5fcd72a90b20 | 21 | |
| 1012754868 | 0:5fcd72a90b20 | 22 | |
| 1012754868 | 0:5fcd72a90b20 | 23 | /************************Objects************************/ |
| 1012754868 | 0:5fcd72a90b20 | 24 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);//set LCD pins |
| 1012754868 | 0:5fcd72a90b20 | 25 | Gamepad pad; |
| 1012754868 | 0:5fcd72a90b20 | 26 | Snake snake; |
| 1012754868 | 0:5fcd72a90b20 | 27 | Direction d; |
| 1012754868 | 0:5fcd72a90b20 | 28 | int SNAKY[11][48] = { |
| 1012754868 | 0:5fcd72a90b20 | 29 | {0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 30 | {0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 31 | {0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 32 | {0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 33 | {0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 34 | {0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 35 | {0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 36 | {0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 37 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 38 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 39 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} |
| 1012754868 | 0:5fcd72a90b20 | 40 | }; |
| 1012754868 | 0:5fcd72a90b20 | 41 | |
| 1012754868 | 0:5fcd72a90b20 | 42 | int _SNAKY[11][48] = { |
| 1012754868 | 0:5fcd72a90b20 | 43 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 44 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 45 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 46 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 47 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 48 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 49 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 50 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 51 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 52 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| 1012754868 | 0:5fcd72a90b20 | 53 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} |
| 1012754868 | 0:5fcd72a90b20 | 54 | }; |
| 1012754868 | 0:5fcd72a90b20 | 55 | |
| 1012754868 | 0:5fcd72a90b20 | 56 | char _Buffer[200]; |
| 1012754868 | 0:5fcd72a90b20 | 57 | /************************Prototypes************************/ |
| 1012754868 | 0:5fcd72a90b20 | 58 | void start_game(); |
| 1012754868 | 0:5fcd72a90b20 | 59 | void game_setting(); |
| 1012754868 | 0:5fcd72a90b20 | 60 | |
| 1012754868 | 0:5fcd72a90b20 | 61 | /************************Variables************************/ |
| 1012754868 | 0:5fcd72a90b20 | 62 | |
| 1012754868 | 0:5fcd72a90b20 | 63 | //int heroChar[4]=(1,1,0,1); |
| 1012754868 | 0:5fcd72a90b20 | 64 | //int bomb[4]=(0,1,0,1); |
| 1012754868 | 0:5fcd72a90b20 | 65 | //int boulderLocation[4][8]={}// set the coordinate for boulder, if 00, boulder does not exist |
| 1012754868 | 0:5fcd72a90b20 | 66 | |
| 1012754868 | 0:5fcd72a90b20 | 67 | /************************Main code************************/ |
| 1012754868 | 0:5fcd72a90b20 | 68 | int main() |
| 1012754868 | 0:5fcd72a90b20 | 69 | { |
| 1012754868 | 0:5fcd72a90b20 | 70 | lcd.init();//initializing display |
| 1012754868 | 0:5fcd72a90b20 | 71 | pad.init(); |
| 1012754868 | 0:5fcd72a90b20 | 72 | //pc.printf("initalized"); |
| 1012754868 | 0:5fcd72a90b20 | 73 | snake.init(25,25,5,3); |
| 1012754868 | 0:5fcd72a90b20 | 74 | start_game(); |
| 1012754868 | 0:5fcd72a90b20 | 75 | game_setting(); |
| 1012754868 | 0:5fcd72a90b20 | 76 | while (1) { |
| 1012754868 | 0:5fcd72a90b20 | 77 | //printf("updated"); |
| 1012754868 | 0:5fcd72a90b20 | 78 | snake.drawsnake(lcd); |
| 1012754868 | 0:5fcd72a90b20 | 79 | snake.snakemov(pad); |
| 1012754868 | 0:5fcd72a90b20 | 80 | } |
| 1012754868 | 0:5fcd72a90b20 | 81 | } |
| 1012754868 | 0:5fcd72a90b20 | 82 | /************************Functions************************/ |
| 1012754868 | 0:5fcd72a90b20 | 83 | |
| 1012754868 | 0:5fcd72a90b20 | 84 | void start_game(){ |
| 1012754868 | 0:5fcd72a90b20 | 85 | lcd.printString(" LI Saiwen",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 86 | lcd.printString(" Press A",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 87 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 88 | |
| 1012754868 | 0:5fcd72a90b20 | 89 | lcd.drawSprite(60,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 90 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 91 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 92 | lcd.drawSprite(60,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 93 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 94 | |
| 1012754868 | 0:5fcd72a90b20 | 95 | lcd.drawSprite(55,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 96 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 97 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 98 | lcd.drawSprite(55,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 99 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 100 | |
| 1012754868 | 0:5fcd72a90b20 | 101 | lcd.drawSprite(50,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 102 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 103 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 104 | lcd.drawSprite(50,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 105 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 106 | |
| 1012754868 | 0:5fcd72a90b20 | 107 | lcd.drawSprite(45,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 108 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 109 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 110 | lcd.drawSprite(45,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 111 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 112 | |
| 1012754868 | 0:5fcd72a90b20 | 113 | lcd.drawSprite(40,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 114 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 115 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 116 | lcd.drawSprite(40,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 117 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 118 | |
| 1012754868 | 0:5fcd72a90b20 | 119 | lcd.drawSprite(35,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 120 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 121 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 122 | lcd.drawSprite(35,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 123 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 124 | |
| 1012754868 | 0:5fcd72a90b20 | 125 | lcd.drawSprite(30,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 126 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 127 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 128 | lcd.drawSprite(30,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 129 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 130 | |
| 1012754868 | 0:5fcd72a90b20 | 131 | lcd.drawSprite(25,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 132 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 133 | wait(0.2); |
| 1012754868 | 0:5fcd72a90b20 | 134 | lcd.drawSprite(25,5,11,48,(int *)_SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 135 | |
| 1012754868 | 0:5fcd72a90b20 | 136 | lcd.drawSprite(20,5,11,48,(int *)SNAKY); |
| 1012754868 | 0:5fcd72a90b20 | 137 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 138 | while ( pad.check_event(Gamepad::A_PRESSED) == false) { |
| 1012754868 | 0:5fcd72a90b20 | 139 | pad.leds_on(); |
| 1012754868 | 0:5fcd72a90b20 | 140 | wait(0.1); |
| 1012754868 | 0:5fcd72a90b20 | 141 | pad.leds_off(); |
| 1012754868 | 0:5fcd72a90b20 | 142 | wait(0.1); |
| 1012754868 | 0:5fcd72a90b20 | 143 | } |
| 1012754868 | 0:5fcd72a90b20 | 144 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 145 | } |
| 1012754868 | 0:5fcd72a90b20 | 146 | |
| 1012754868 | 0:5fcd72a90b20 | 147 | void game_setting() { |
| 1012754868 | 0:5fcd72a90b20 | 148 | lcd.printString(" Menu",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 149 | lcd.printString(" A to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 150 | lcd.printString("set speed <",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 151 | lcd.printString("history ",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 152 | lcd.printString(" press start",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 153 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 154 | int q = 1; |
| 1012754868 | 0:5fcd72a90b20 | 155 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
| 1012754868 | 0:5fcd72a90b20 | 156 | d = pad.get_direction(); |
| 1012754868 | 0:5fcd72a90b20 | 157 | if(d == N || q == 1){ |
| 1012754868 | 0:5fcd72a90b20 | 158 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 159 | lcd.printString(" Menu",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 160 | lcd.printString(" A to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 161 | lcd.printString("set speed <",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 162 | lcd.printString("history ",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 163 | lcd.printString(" press start",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 164 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 165 | if(pad.check_event(Gamepad::A_PRESSED) == true) { |
| 1012754868 | 0:5fcd72a90b20 | 166 | bool IsCheck = false; |
| 1012754868 | 0:5fcd72a90b20 | 167 | int c = 1; |
| 1012754868 | 0:5fcd72a90b20 | 168 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 169 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 170 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 171 | lcd.printString(" Normal <",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 172 | lcd.printString(" Difficult",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 173 | lcd.printString(" Hell",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 174 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 175 | while(IsCheck == false){ |
| 1012754868 | 0:5fcd72a90b20 | 176 | d = pad.get_direction(); |
| 1012754868 | 0:5fcd72a90b20 | 177 | if(d == N && c == 1){ |
| 1012754868 | 0:5fcd72a90b20 | 178 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 179 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 180 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 181 | lcd.printString(" Normal <",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 182 | lcd.printString(" Difficult",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 183 | lcd.printString(" Hell",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 184 | c = 1; |
| 1012754868 | 0:5fcd72a90b20 | 185 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 186 | } |
| 1012754868 | 0:5fcd72a90b20 | 187 | else if(d == S && c == 1 ){ |
| 1012754868 | 0:5fcd72a90b20 | 188 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 189 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 190 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 191 | lcd.printString(" Normal",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 192 | lcd.printString(" Difficult <",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 193 | lcd.printString(" Hell",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 194 | c = 2; |
| 1012754868 | 0:5fcd72a90b20 | 195 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 196 | } |
| 1012754868 | 0:5fcd72a90b20 | 197 | else if(d == N && c == 2){ |
| 1012754868 | 0:5fcd72a90b20 | 198 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 199 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 200 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 201 | lcd.printString(" Normal",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 202 | lcd.printString(" Difficult <",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 203 | lcd.printString(" Hell",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 204 | c = 1; |
| 1012754868 | 0:5fcd72a90b20 | 205 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 206 | } |
| 1012754868 | 0:5fcd72a90b20 | 207 | else if(d == S && c == 2){ |
| 1012754868 | 0:5fcd72a90b20 | 208 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 209 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 210 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 211 | lcd.printString(" Normal",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 212 | lcd.printString(" Difficult",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 213 | lcd.printString(" Hell <",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 214 | c = 3; |
| 1012754868 | 0:5fcd72a90b20 | 215 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 216 | } |
| 1012754868 | 0:5fcd72a90b20 | 217 | else if(d == S && c == 3){ |
| 1012754868 | 0:5fcd72a90b20 | 218 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 219 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 220 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 221 | lcd.printString(" Normal",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 222 | lcd.printString(" Difficult",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 223 | lcd.printString(" Hell <",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 224 | c = 3; |
| 1012754868 | 0:5fcd72a90b20 | 225 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 226 | } |
| 1012754868 | 0:5fcd72a90b20 | 227 | else if(d == N && c == 3){ |
| 1012754868 | 0:5fcd72a90b20 | 228 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 229 | lcd.printString(" Speed set",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 230 | lcd.printString(" B to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 231 | lcd.printString(" Normal",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 232 | lcd.printString(" Difficult <",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 233 | lcd.printString(" Hell",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 234 | c = 2; |
| 1012754868 | 0:5fcd72a90b20 | 235 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 236 | } |
| 1012754868 | 0:5fcd72a90b20 | 237 | wait(0.3); |
| 1012754868 | 0:5fcd72a90b20 | 238 | if(c == 1 && pad.check_event(Gamepad::B_PRESSED) == true) { |
| 1012754868 | 0:5fcd72a90b20 | 239 | snake._speed = 0; |
| 1012754868 | 0:5fcd72a90b20 | 240 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 241 | lcd.printString(" set success!",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 242 | lcd.printString(" Press Back!",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 243 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 244 | } |
| 1012754868 | 0:5fcd72a90b20 | 245 | else if(c == 2 && pad.check_event(Gamepad::B_PRESSED) == true) { |
| 1012754868 | 0:5fcd72a90b20 | 246 | snake._speed = 10; |
| 1012754868 | 0:5fcd72a90b20 | 247 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 248 | lcd.printString(" set success!",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 249 | lcd.printString(" Press Back!",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 250 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 251 | } |
| 1012754868 | 0:5fcd72a90b20 | 252 | else if(c == 3 && pad.check_event(Gamepad::B_PRESSED) == true) { |
| 1012754868 | 0:5fcd72a90b20 | 253 | snake._speed = 50; |
| 1012754868 | 0:5fcd72a90b20 | 254 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 255 | lcd.printString(" set success",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 256 | lcd.printString(" Press Back!",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 257 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 258 | } |
| 1012754868 | 0:5fcd72a90b20 | 259 | if(pad.check_event(Gamepad::BACK_PRESSED) == true){ |
| 1012754868 | 0:5fcd72a90b20 | 260 | IsCheck = true; |
| 1012754868 | 0:5fcd72a90b20 | 261 | } |
| 1012754868 | 0:5fcd72a90b20 | 262 | } |
| 1012754868 | 0:5fcd72a90b20 | 263 | |
| 1012754868 | 0:5fcd72a90b20 | 264 | if(pad.check_event(Gamepad::BACK_PRESSED) == true){ |
| 1012754868 | 0:5fcd72a90b20 | 265 | break; |
| 1012754868 | 0:5fcd72a90b20 | 266 | } |
| 1012754868 | 0:5fcd72a90b20 | 267 | } |
| 1012754868 | 0:5fcd72a90b20 | 268 | |
| 1012754868 | 0:5fcd72a90b20 | 269 | } |
| 1012754868 | 0:5fcd72a90b20 | 270 | if(d == S && q == 1){ |
| 1012754868 | 0:5fcd72a90b20 | 271 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 272 | lcd.printString(" Menu",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 273 | lcd.printString(" A to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 274 | lcd.printString("set speed",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 275 | lcd.printString("history <",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 276 | lcd.printString(" press start",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 277 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 278 | q = 2; |
| 1012754868 | 0:5fcd72a90b20 | 279 | } |
| 1012754868 | 0:5fcd72a90b20 | 280 | if(d == S && q == 2){ |
| 1012754868 | 0:5fcd72a90b20 | 281 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 282 | lcd.printString(" Menu",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 283 | lcd.printString(" A to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 284 | lcd.printString("set speed",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 285 | lcd.printString("history <",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 286 | lcd.printString(" press start",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 287 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 288 | q = 2; |
| 1012754868 | 0:5fcd72a90b20 | 289 | } |
| 1012754868 | 0:5fcd72a90b20 | 290 | if(d == N && q == 2) { |
| 1012754868 | 0:5fcd72a90b20 | 291 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 292 | lcd.printString(" Menu",0,0); |
| 1012754868 | 0:5fcd72a90b20 | 293 | lcd.printString(" A to set",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 294 | lcd.printString("set speed <",0,2); |
| 1012754868 | 0:5fcd72a90b20 | 295 | lcd.printString("history ",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 296 | lcd.printString(" press start",0,5); |
| 1012754868 | 0:5fcd72a90b20 | 297 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 298 | q = 1; |
| 1012754868 | 0:5fcd72a90b20 | 299 | } |
| 1012754868 | 0:5fcd72a90b20 | 300 | |
| 1012754868 | 0:5fcd72a90b20 | 301 | if(q == 2 && pad.check_event(Gamepad::A_PRESSED) == true) { |
| 1012754868 | 0:5fcd72a90b20 | 302 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 303 | sprintf(_Buffer,"%2d",snake.Highest_score); |
| 1012754868 | 0:5fcd72a90b20 | 304 | lcd.printString(_Buffer,24,3); |
| 1012754868 | 0:5fcd72a90b20 | 305 | lcd.printString("Highest score",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 306 | lcd.printString(" Press Back",0,4); |
| 1012754868 | 0:5fcd72a90b20 | 307 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 308 | while(pad.check_event(Gamepad::BACK_PRESSED) == false){ |
| 1012754868 | 0:5fcd72a90b20 | 309 | |
| 1012754868 | 0:5fcd72a90b20 | 310 | } |
| 1012754868 | 0:5fcd72a90b20 | 311 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 312 | lcd.printString("MOVE joystick",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 313 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 314 | } |
| 1012754868 | 0:5fcd72a90b20 | 315 | |
| 1012754868 | 0:5fcd72a90b20 | 316 | pad.leds_on(); |
| 1012754868 | 0:5fcd72a90b20 | 317 | wait(0.1); |
| 1012754868 | 0:5fcd72a90b20 | 318 | pad.leds_off(); |
| 1012754868 | 0:5fcd72a90b20 | 319 | wait(0.1); |
| 1012754868 | 0:5fcd72a90b20 | 320 | } |
| 1012754868 | 0:5fcd72a90b20 | 321 | |
| 1012754868 | 0:5fcd72a90b20 | 322 | |
| 1012754868 | 0:5fcd72a90b20 | 323 | |
| 1012754868 | 0:5fcd72a90b20 | 324 | lcd.clear(); |
| 1012754868 | 0:5fcd72a90b20 | 325 | lcd.printString(" start!!!",0,1); |
| 1012754868 | 0:5fcd72a90b20 | 326 | lcd.printString("Enjoy yourself",0,3); |
| 1012754868 | 0:5fcd72a90b20 | 327 | lcd.refresh(); |
| 1012754868 | 0:5fcd72a90b20 | 328 | wait(2); |
| 1012754868 | 0:5fcd72a90b20 | 329 | } |
| 1012754868 | 0:5fcd72a90b20 | 330 | |
| 1012754868 | 0:5fcd72a90b20 | 331 | |
| 1012754868 | 0:5fcd72a90b20 | 332 | |
| 1012754868 | 0:5fcd72a90b20 | 333 |