test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Stage.cpp@24:88968d1fc9cb, 2016-12-12 (annotated)
- Committer:
- th_mbed
- Date:
- Mon Dec 12 10:44:00 2016 +0000
- Revision:
- 24:88968d1fc9cb
- Parent:
- 22:5a7399899fe6
- Child:
- 40:ec5c1b305b9a
change make stage algolism
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 | 22:5a7399899fe6 | 22 | int r = rand() % (LCD_Y - 5); //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 | 24:88968d1fc9cb | 46 | if(stage[LCD_X - 1] == stage[LCD_X - 2 - ONE_STEP_SIZE]){ |
th_mbed | 24:88968d1fc9cb | 47 | return stage[LCD_X - 1] + 4; |
th_mbed | 24:88968d1fc9cb | 48 | }else{ |
th_mbed | 24:88968d1fc9cb | 49 | return rand()%(LCD_Y - 5); |
th_mbed | 24:88968d1fc9cb | 50 | } |
th_mbed | 24:88968d1fc9cb | 51 | } |
th_mbed | 24:88968d1fc9cb | 52 | |
th_mbed | 24:88968d1fc9cb | 53 | |
th_mbed | 21:1911f2c4684b | 54 | int Stage::getLength(){ |
th_mbed | 21:1911f2c4684b | 55 | return length; |
th_mbed | 12:c74115744b24 | 56 | } |