Commit dde00b28 authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 4c19275a
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
using namespace std; using namespace std;
bool hi = 0;
Snake bdy;
vector <Body> parts; vector <Body> parts;
void Snake::movement(char input){ void Snake::movement(char input){
...@@ -26,58 +26,77 @@ vector <Body> parts; ...@@ -26,58 +26,77 @@ vector <Body> parts;
if((input == 'd'|| input == 'D')&& direction != 4 ) if((input == 'd'|| input == 'D')&& direction != 4 )
direction = 2; direction = 2;
if(direction == 1) if(direction == 1){
x--; x--;
for ( int count = 0; count < parts.size(); count++){
parts[count].changeX(1);
}
}
else else
if(direction == 4) if(direction == 4){
y--; y--;
for ( int count = 0; count < parts.size(); count++){
parts[count].changeY(1);
}
}
else else
if(direction == 3) if(direction == 3){
x++; x++;
for ( int count = 0; count < parts.size(); count++){
parts[count].changeX(0);
}
}
else else
if(direction == 2) if(direction == 2){
y++; y++;
for ( int count = 0; count < parts.size(); count++){
parts[count].changeY(0);
}
}
} }
void Snake::draw(){ void Snake::draw(){
for (int i = 0; i < 14; i++){ for (int i = 0; i < 14; i++){
cout << endl;
for (int q = 0; q < 30; q++){ for (int q = 0; q < 30; q++){
if (x < 0)x++; if (x < 0)x++;
if (y < 0)y++; if (y < 0)y++;
if (x > 12)x--; if (x > 12)x--;
if (y > 29)y--; if (y > 29)y--;
for ( int count = 0; count < parts.size(); count++){
if ((parts[count].getX() == x - 1) && (parts[count].getY() == y - 1))
grid[i - 1][q - 1] = 'B';
}
if (i == x && q == y)
grid[x][y] = 'S';
else
if (h == i || o == q) if (h == i || o == q)
grid[h][o] = '*'; grid[h][o] = '*';
else
if (i != h || o != q) if (i == x && q == y)
grid[x][y] = 'S';
if ((i != h || o != q) && (i != x || q != y))
grid[i][q] = whtSpace; grid[i][q] = whtSpace;
for ( int count = 0; count < parts.size(); count++){
grid[parts[count].getX()][parts[count].getY()] = 'B';
}
}
}
for (int i = 0; i < 14; i++){
cout << endl;
for (int q = 0; q < 30; q++){
cout << grid[i][q] << " "; cout << grid[i][q] << " ";
} grid[i][q] == ' ';
}
} }
if (grid [x][y] == grid[h][o] ){ if (grid [x][y] == grid[h][o] ){
h = (rand() % 13); h = (rand() % 13);
o = (rand() % 30); o = (rand() % 30);
score++; score++;
bdy.lengthed();
bdy.newBody();
} }
} }
...@@ -100,13 +119,24 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -100,13 +119,24 @@ if (grid [x][y] == grid[h][o] ){
void Snake::newBody(){ void Snake::newBody(){
Body segment (x, y); Body segment (x - length, y);
cout << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl << x << endl;
parts.push_back(segment); parts.push_back(segment);
} }
void Body::changeX(bool updown){
if (updown)
x--;
else
x++;
}
void Body::changeY(bool updown){
if (updown)
y--;
else
y++;
}
Body::Body(int xCord, int yCord){ Body::Body(int xCord, int yCord){
...@@ -119,4 +149,9 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -119,4 +149,9 @@ if (grid [x][y] == grid[h][o] ){
} }
int Body::getY(){ int Body::getY(){
return y; return y;
} }
\ No newline at end of file
void Snake::lengthed(){
length++;
}
\ No newline at end of file
...@@ -16,13 +16,15 @@ class Snake { ...@@ -16,13 +16,15 @@ class Snake {
int getX(); int getX();
int getY(); int getY();
void newBody(); void newBody();
void lengthed();
private: private:
int x = 0, y = 0, i = 0, q = 0, score = 0, int x = 5, y = 5, i = 0, q = 0, score = 0,
h = (rand() % 14), o = (rand() % 14); h = (rand() % 14), o = (rand() % 14);
char grid[15][30]; char grid[15][30];
int randChar = (rand() % 5); int randChar = (rand() % 5);
char whtSpace = ' '; char whtSpace = ' ';
int direction = 5; int direction = 5;
int length = 0;
}; };
...@@ -33,8 +35,10 @@ class Body { ...@@ -33,8 +35,10 @@ class Body {
Body(int xCord, int yCord); Body(int xCord, int yCord);
int getX(); int getX();
int getY(); int getY();
void changeX(bool updown);
void changeY(bool updown);
private: private:
int x, y,length; int x, y;
char piece; char piece;
}; };
#endif #endif
\ No newline at end of file
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