Browse Source

added a function to alter teh difficulty as the snake's getting bigger and bigger

pull/1/head
VissaMoutafis 5 years ago
parent
commit
b58bb207a0
  1. 4
      include/Graphics.h
  2. 1
      src/Controller.cpp
  3. 4
      src/Graphics.cpp
  4. 4
      src/Snack.cpp

4
include/Graphics.h

@ -21,4 +21,6 @@ void refreshScreen(void);
void printChar(int y, int x, graphics_input img); void printChar(int y, int x, graphics_input img);
void printMsg(int y, int x, char *str); void printMsg(int y, int x, char *str);
char readChar(int y, int x); char readChar(int y, int x);
int readInpt();
int readInpt();
void advanceDifficulty(void);

1
src/Controller.cpp

@ -23,6 +23,7 @@ int Controller::act(void){
if (snake->hasBitSnack(this->snack.getY(), this->snack.getX()) == true) if (snake->hasBitSnack(this->snack.getY(), this->snack.getX()) == true)
{ {
advanceDifficulty();
generateSnack(this->snack); generateSnack(this->snack);
this->snake->incSize(); this->snake->incSize();
} }

4
src/Graphics.cpp

@ -75,3 +75,7 @@ int readInpt(){
return getch(); return getch();
} }
void advanceDifficulty(void){
if(sleepTime > 28000000) // we set 28000000 as teh min sleep time
sleepTime -= 1000000;
}

4
src/Snack.cpp

@ -10,8 +10,8 @@ void generateSnack(Point &snack){
int x, y; int x, y;
x = (rand() + 1) % GAME_RIGHT_WALL_X;
y = (rand() + 1) % GAME_BOTTOM_WALL_Y;
x = rand() % GAME_RIGHT_WALL_X + 1;
y = rand() % GAME_BOTTOM_WALL_Y + 1;
snack.setPoint(y, x); snack.setPoint(y, x);

Loading…
Cancel
Save