test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Stage.cpp

Committer:
th_mbed
Date:
2016-12-12
Revision:
24:88968d1fc9cb
Parent:
22:5a7399899fe6
Child:
40:ec5c1b305b9a

File content as of revision 24:88968d1fc9cb:

#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 = rand() % (LCD_Y - 5); //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{
        return rand()%(LCD_Y - 5);
    }
}


int Stage::getLength(){
    return length;
}