Commit dde00b28 authored by Nelson Phillips's avatar Nelson Phillips

autosave

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