Commit 48429465 authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent cfc1469c
......@@ -8,111 +8,127 @@ using namespace std;
bool hi = true;
Snake bdy;
vector <Body> parts;
void Snake::movement(char input){
if((input == 'w'|| input == 'W')&& direction != 3 )
void Snake::movement(char input){
// simple get input to change direction of snake.
if((input == 'w'|| input == 'W')&& direction != 3 )
direction = 1;
else
if((input == 'a'|| input == 'A')&& direction != 2 )
else
if((input == 'a'|| input == 'A')&& direction != 2 )
direction = 4;
else
if((input == 's'|| input == 'S')&& direction != 1 )
else
if((input == 's'|| input == 'S')&& direction != 1 )
direction = 3;
else
if((input == 'd'|| input == 'D')&& direction != 4 )
else
if((input == 'd'|| input == 'D')&& direction != 4 )
direction = 2;
if(direction == 1){
// moves the first body part that exists on top of the head
if(direction == 1){
x--;
parts[0].changeX(1);
}
else
if(direction == 4){
}
else
if(direction == 4){
y--;
parts[0].changeY(1);
}
else
if(direction == 3){
}
else
if(direction == 3){
x++;
parts[0].changeX(0);
}
else
if(direction == 2){
}
else
if(direction == 2){
y++;
parts[0].changeY(0);
}
}
for (int count = 0; count < parts.size(); count++){
if (count != 0)
parts[count].follow(count);
}
}
}
bool Snake::draw(){
for (int i = 0; i < 29; i++){
cout << "Your score is : " << score << endl;
for (int i = 0; i < 29; i++){
for (int q = 0; q < 60; q++){
if (x < 1)return false;
if (x < 1)return false; // end the loop if it hits a wall
if (y < 1)return false;
if (x > 26)return false;
if (y > 57)return false;
grid[i][q] = whtSpace;
if (h == i || o == q)
grid[i][q] = whtSpace; // each square is set to a white space
if (h == i || o == q) // displayes the apple
grid[h][o] = '*';
if (i == 27 || i == 0)
if (i == 27 || i == 0)// top and bottom wall
grid[i][q] = '-';
if(q == 0 || q == 59)
if(q == 0 || q == 59)// side walls
grid[i][q] = '|';
for ( int count = 0; count < parts.size(); count++){
if (grid[parts[0].getX()][parts[0].getY()] == '-') return false;
if (count == 0){
for ( int count = 0; count < parts.size(); count++){
if (grid[parts[0].getX()][parts[0].getY()] == '-') return false; // if a body connects with another you lose
if (count == 0){// display for head
if( direction == 2)
grid[parts[count].getX()][parts[count].getY()] = '>';
else
if ( direction == 3)
grid[parts[count].getX()][parts[count].getY()] = 'v';
else
if( direction == 4)
grid[parts[count].getX()][parts[count].getY()] = '<';
else
if( direction == 1)
grid[parts[count].getX()][parts[count].getY()] = '^';
else
grid[parts[count].getX()][parts[count].getY()] = 'O';
}
else
else // body parts look like
grid[parts[count].getX()][parts[count].getY()] = '-';
}
}
}
}
// this is to clear screen for now
for (int i = 0; i < 29; i++){
cout << endl;
for (int q = 0; q < 60; q++){
cout << grid[i][q] << " ";
}
for (int q = 0; q < 60; q++){
cout << grid[i][q] << " ";
}
}
if (grid [x][y] == grid[h][o] ){
if (grid [x][y] == grid[h][o] ){ // randomizes the apples
h = (rand() % 26) + 1;
o = (rand() % 57) + 1;
score++;
bdy.newBody();
bonusBody = bonusBody + 5;
} else if (bonusBody > 0){
bdy.newBody();
bonusBody--;
}
return hi;
}else if (bonusBody > 0){ // adds body parts every loop after picking up apples
bdy.newBody();
bonusBody--;
}
return hi;
}
int Snake::snekoScore(){
return score;
}
......@@ -124,15 +140,17 @@ return hi;
}
int Snake::getX(){
return x;
return x;
}
int Snake::getY(){
return y;
return y;
}
void Snake::newBody(){
void Snake::newBody(){
Body segment (x,y);
parts.push_back(segment);
}
}
void Snake::GameOver(){
for (int p = 0; p < 40; p++){
......@@ -149,9 +167,9 @@ return hi;
void Body::changeX(bool updown){
lastX = x;
lastY = y;
void Body::changeX(bool updown){
lastX = x;
lastY = y;
if (updown)
x--;
else
......@@ -159,15 +177,14 @@ return hi;
}
void Body::changeY(bool updown){
lastX = x;
lastY = y;
if (updown)
y--;
lastX = x;
lastY = y;
if (updown)
y--;
else
y++;
}
}
Body::Body(int xCord, int yCord){
x = xCord;
......@@ -175,21 +192,24 @@ return hi;
}
int Body::getX(){
return x;
return x;
}
int Body::getY(){
return y;
return y;
}
int Body::getlastX(){
return lastX;
return lastX;
}
int Body::getlastY(){
return lastY;
return lastY;
}
void Body::follow(int count){
lastX = x;
lastY = y;
lastX = x;
lastY = y;
x = parts[count - 1].getlastX();
y = parts[count - 1].getlastY();
}
\ No newline at end of file
......@@ -35,8 +35,6 @@ void charCall() {
BrdSet.clrScreen();
cout << "Your score is : " << BrdSet.snekoScore() << endl;
hello = BrdSet.draw();
if (hello == false)
BrdSet.GameOver();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment