test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Stage.cpp@63:4c22abbe4727, 2016-12-16 (annotated)
- Committer:
- kaku_jyoko
- Date:
- Fri Dec 16 13:52:36 2016 +0000
- Revision:
- 63:4c22abbe4727
- Parent:
- 53:2dbce16ffdaa
remove led lump
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
th_mbed | 12:c74115744b24 | 1 | #include "point.h" |
th_mbed | 12:c74115744b24 | 2 | #include "models.h" |
th_mbed | 24:88968d1fc9cb | 3 | #include "mbed.h" |
th_mbed | 21:1911f2c4684b | 4 | #include <stdlib.h> |
th_mbed | 21:1911f2c4684b | 5 | #include <stdio.h> |
th_mbed | 12:c74115744b24 | 6 | |
th_mbed | 24:88968d1fc9cb | 7 | #define MAX_LEN ONE_STEP_SIZE*3 |
th_mbed | 24:88968d1fc9cb | 8 | |
th_mbed | 21:1911f2c4684b | 9 | Stage::Stage(){ |
th_mbed | 21:1911f2c4684b | 10 | length = LCD_X; |
th_mbed | 21:1911f2c4684b | 11 | for(int i = 0; i < LCD_X; i++){ |
th_mbed | 21:1911f2c4684b | 12 | stage[i] = 1; |
th_mbed | 15:400760117d9d | 13 | } |
th_mbed | 12:c74115744b24 | 14 | } |
th_mbed | 12:c74115744b24 | 15 | |
th_mbed | 21:1911f2c4684b | 16 | int* Stage::getStage(){ |
th_mbed | 21:1911f2c4684b | 17 | if((length % ONE_STEP_SIZE) == 0){ |
th_mbed | 21:1911f2c4684b | 18 | //get new step |
th_mbed | 21:1911f2c4684b | 19 | for(int i = 0; i < LCD_X;i++){ |
th_mbed | 21:1911f2c4684b | 20 | if(i == LCD_X - 1){ |
th_mbed | 21:1911f2c4684b | 21 | //make random |
th_mbed | 42:d7798a204c3d | 22 | int r = nextStep(); //TODO |
th_mbed | 21:1911f2c4684b | 23 | stage[i] = r; |
th_mbed | 21:1911f2c4684b | 24 | }else{ |
th_mbed | 21:1911f2c4684b | 25 | //slide |
th_mbed | 21:1911f2c4684b | 26 | stage[i] = stage[i+1]; |
th_mbed | 21:1911f2c4684b | 27 | } |
th_mbed | 21:1911f2c4684b | 28 | } |
th_mbed | 21:1911f2c4684b | 29 | }else{ |
th_mbed | 21:1911f2c4684b | 30 | //simly slide stage |
th_mbed | 21:1911f2c4684b | 31 | for(int i = 0; i < LCD_X;i++){ |
th_mbed | 21:1911f2c4684b | 32 | if(i == LCD_X - 1){ |
th_mbed | 21:1911f2c4684b | 33 | //the same height |
th_mbed | 21:1911f2c4684b | 34 | stage[i] = stage[i-1]; |
th_mbed | 21:1911f2c4684b | 35 | }else{ |
th_mbed | 21:1911f2c4684b | 36 | //slide |
th_mbed | 21:1911f2c4684b | 37 | stage[i] = stage[i+1]; |
th_mbed | 21:1911f2c4684b | 38 | } |
th_mbed | 15:400760117d9d | 39 | } |
th_mbed | 15:400760117d9d | 40 | } |
th_mbed | 21:1911f2c4684b | 41 | length++; |
th_mbed | 21:1911f2c4684b | 42 | return stage; |
th_mbed | 15:400760117d9d | 43 | } |
th_mbed | 21:1911f2c4684b | 44 | |
th_mbed | 24:88968d1fc9cb | 45 | int Stage::nextStep(){ |
th_mbed | 53:2dbce16ffdaa | 46 | if(stage[LCD_X - 1] == 0){ |
th_mbed | 53:2dbce16ffdaa | 47 | int t = rand()%6; |
th_mbed | 53:2dbce16ffdaa | 48 | if(t % 2==0){ |
th_mbed | 53:2dbce16ffdaa | 49 | t++; |
th_mbed | 53:2dbce16ffdaa | 50 | } |
th_mbed | 53:2dbce16ffdaa | 51 | return t; |
th_mbed | 53:2dbce16ffdaa | 52 | } |
th_mbed | 24:88968d1fc9cb | 53 | if(stage[LCD_X - 1] == stage[LCD_X - 2 - ONE_STEP_SIZE]){ |
th_mbed | 24:88968d1fc9cb | 54 | return stage[LCD_X - 1] + 4; |
th_mbed | 24:88968d1fc9cb | 55 | }else{ |
th_mbed | 53:2dbce16ffdaa | 56 | if(rand()%10 == 0){ |
th_mbed | 53:2dbce16ffdaa | 57 | return 0; |
th_mbed | 53:2dbce16ffdaa | 58 | } |
th_mbed | 43:73afa890c336 | 59 | int start = stage[LCD_X - 1] - 8; |
th_mbed | 41:1a7c4d4d6bcd | 60 | if(start < 0){ |
th_mbed | 41:1a7c4d4d6bcd | 61 | start = 0; |
th_mbed | 41:1a7c4d4d6bcd | 62 | } |
th_mbed | 43:73afa890c336 | 63 | int end = stage[LCD_X - 1] + 8; |
th_mbed | 43:73afa890c336 | 64 | if(end > 20){ |
th_mbed | 43:73afa890c336 | 65 | end = 20; |
th_mbed | 43:73afa890c336 | 66 | } |
th_mbed | 41:1a7c4d4d6bcd | 67 | int tmp = start + rand()%(start - end + 1); |
th_mbed | 43:73afa890c336 | 68 | if((tmp % 2 == 0) && (tmp != 0)){ |
th_mbed | 41:1a7c4d4d6bcd | 69 | tmp++; |
th_mbed | 41:1a7c4d4d6bcd | 70 | } |
th_mbed | 41:1a7c4d4d6bcd | 71 | return tmp; |
th_mbed | 24:88968d1fc9cb | 72 | } |
th_mbed | 24:88968d1fc9cb | 73 | } |
th_mbed | 24:88968d1fc9cb | 74 | |
th_mbed | 24:88968d1fc9cb | 75 | |
th_mbed | 21:1911f2c4684b | 76 | int Stage::getLength(){ |
kaku_jyoko | 40:ec5c1b305b9a | 77 | return length - 128; |
th_mbed | 12:c74115744b24 | 78 | } |