Commit 1e61c7ef authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 6317fec5
...@@ -30,32 +30,26 @@ vector <Body> parts; ...@@ -30,32 +30,26 @@ vector <Body> parts;
if(direction == 1){ if(direction == 1){
x--; x--;
for ( int count = 0; count < parts.size(); count++){ parts[0].changeX(1);
parts[count].changeX(1);
}
} }
else else
if(direction == 4){ if(direction == 4){
y--; y--;
parts[0].changeY(1);
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[0].changeX(0);
parts[count].changeX(0);
}
} }
else else
if(direction == 2){ if(direction == 2){
y++; y++;
for ( int count = 0; count < parts.size(); count++){ parts[0].changeY(0);
parts[count].changeY(0);
}
} }
for (int count = 0; count < parts.size() - 1; count++){
parts[count + 1].follow(count);
}
} }
...@@ -126,11 +120,14 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -126,11 +120,14 @@ if (grid [x][y] == grid[h][o] ){
} }
void Snake::newBody(){ void Snake::newBody(){
Body segment (x,y);//parts[bdy.getLeng()].getX(), parts[bdy.getLeng()].getY() Body segment (parts[bdy.getLeng()].getX(),parts[bdy.getLeng()].getY());
parts.push_back(segment); parts.push_back(segment);
} }
void Snake::firstbody(){
Body segment (x, y);
parts.push_back(segment);
}
...@@ -138,6 +135,8 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -138,6 +135,8 @@ if (grid [x][y] == grid[h][o] ){
void Body::changeX(bool updown){ void Body::changeX(bool updown){
lastX = x;
if (updown) if (updown)
x--; x--;
else else
...@@ -145,6 +144,7 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -145,6 +144,7 @@ if (grid [x][y] == grid[h][o] ){
} }
void Body::changeY(bool updown){ void Body::changeY(bool updown){
lastY = y;
if (updown) if (updown)
y--; y--;
else else
...@@ -152,7 +152,7 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -152,7 +152,7 @@ if (grid [x][y] == grid[h][o] ){
} }
Body::Body(int& xCord, int& yCord){ Body::Body(int xCord, int yCord){
x = xCord; x = xCord;
y = yCord; y = yCord;
} }
...@@ -163,5 +163,16 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -163,5 +163,16 @@ if (grid [x][y] == grid[h][o] ){
int Body::getY(){ int Body::getY(){
return y; return y;
} }
int Body::getlastX(){
return lastX;
}
int Body::getlastY(){
return lastY;
}
void Body::follow(int count){
\ No newline at end of file x = parts[count].getlastX();
y = parts[count].getlastY();
}
\ No newline at end of file
...@@ -16,6 +16,7 @@ class Snake { ...@@ -16,6 +16,7 @@ class Snake {
int getX(); int getX();
int getY(); int getY();
void newBody(); void newBody();
void firstbody();
void lengthed(); void lengthed();
int getLeng(); int getLeng();
private: private:
...@@ -25,7 +26,7 @@ class Snake { ...@@ -25,7 +26,7 @@ class Snake {
int randChar = (rand() % 5); int randChar = (rand() % 5);
char whtSpace = ' '; char whtSpace = ' ';
int direction = 5; int direction = 5;
int length = 0; int length = -1;
}; };
...@@ -33,13 +34,17 @@ class Snake { ...@@ -33,13 +34,17 @@ class Snake {
class Body { class Body {
public: public:
Body(int& xCord, int& yCord); Body(int xCord, int yCord);
int getX(); int getX();
int getY(); int getY();
void changeX(bool updown); void changeX(bool updown);
void changeY(bool updown); void changeY(bool updown);
void follow(int count);
int getlastX();
int getlastY();
private: private:
int x, y; int x, y;
int lastX, lastY;
char piece; char piece;
}; };
#endif #endif
\ No newline at end of file
...@@ -43,6 +43,7 @@ void charCall() { ...@@ -43,6 +43,7 @@ void charCall() {
} }
int main() int main()
{ {
BrdSet.firstbody();
thread first (charCall); // spawn new thread that calls input() thread first (charCall); // spawn new thread that calls input()
thread second (snakePrint); // spawn new thread that calls snakePrint(0) thread second (snakePrint); // spawn new thread that calls snakePrint(0)
......
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