![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Stage.cpp
- Committer:
- th_mbed
- Date:
- 2016-12-13
- Revision:
- 42:d7798a204c3d
- Parent:
- 41:1a7c4d4d6bcd
- Child:
- 43:73afa890c336
File content as of revision 42:d7798a204c3d:
#include "point.h" #include "models.h" #include "mbed.h" #include <stdlib.h> #include <stdio.h> #define MAX_LEN ONE_STEP_SIZE*3 Stage::Stage(){ length = LCD_X; for(int i = 0; i < LCD_X; i++){ stage[i] = 1; } } int* Stage::getStage(){ if((length % ONE_STEP_SIZE) == 0){ //get new step for(int i = 0; i < LCD_X;i++){ if(i == LCD_X - 1){ //make random int r = nextStep(); //TODO stage[i] = r; }else{ //slide stage[i] = stage[i+1]; } } }else{ //simly slide stage for(int i = 0; i < LCD_X;i++){ if(i == LCD_X - 1){ //the same height stage[i] = stage[i-1]; }else{ //slide stage[i] = stage[i+1]; } } } length++; return stage; } int Stage::nextStep(){ if(stage[LCD_X - 1] == stage[LCD_X - 2 - ONE_STEP_SIZE]){ return stage[LCD_X - 1] + 4; }else{ int start = stage[LCD_X - 1] - 5; if(start < 0){ start = 0; } int end = stage[LCD_X - 1] + 5; int tmp = start + rand()%(start - end + 1); if(tmp % 2 == 0){ tmp++; } return tmp; } } int Stage::getLength(){ return length - 128; }