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

autosave

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