Commit bb95deef authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent c9918a08
...@@ -47,19 +47,21 @@ vector <Body> parts; ...@@ -47,19 +47,21 @@ vector <Body> parts;
y++; y++;
parts[0].changeY(0); parts[0].changeY(0);
} }
for (int count = 0; count < parts.size() - 1; count++){ for (int count = 0; count < parts.size() - 1; count++){
parts[count + 1].follow(count); if (count != 0)
} parts[count].follow(count);
}
} }
void Snake::draw(){ void Snake::draw(){
for (int i = 0; i < 14; i++){ for (int i = 0; i < 14; i++){
for (int q = 0; q < 30; q++){ for (int q = 0; q < 30; q++){
if (x < 0)x++; if (x < 1)x++;
if (y < 0)y++; if (y < 1)y++;
if (x > 12)x--; if (x > 11)x--;
if (y > 29)y--; if (y > 28)y--;
if (h == i || o == q) if (h == i || o == q)
...@@ -67,9 +69,13 @@ vector <Body> parts; ...@@ -67,9 +69,13 @@ vector <Body> parts;
if (i == x && q == y) if (i == x && q == y)
grid[x][y] = 'S'; grid[x][y] = 'S';
if ((i != h || o != q) && (i != x || q != y)) if ((i != h || o != q) && (i != x || q != y))
grid[i][q] = whtSpace; grid[i][q] = whtSpace;
if (i == 12 || i == 0 || q == 0 || q == 29){
grid[i][q] = 'O';
}
for ( int count = 0; count < parts.size(); count++){ for ( int count = 0; count < parts.size(); count++){
grid[parts[count].getX()][parts[count].getY()] = 'B'; grid[parts[count].getX()][parts[count].getY()] = 'B';
...@@ -88,8 +94,8 @@ vector <Body> parts; ...@@ -88,8 +94,8 @@ vector <Body> parts;
} }
} }
if (grid [x][y] == grid[h][o] ){ if (grid [x][y] == grid[h][o] ){
h = (rand() % 13); h = (rand() % 11) + 1;
o = (rand() % 30); o = (rand() % 21) + 1;
score++; score++;
bdy.lengthed(); bdy.lengthed();
bdy.newBody(); bdy.newBody();
...@@ -120,14 +126,11 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -120,14 +126,11 @@ if (grid [x][y] == grid[h][o] ){
} }
void Snake::newBody(){ void Snake::newBody(){
Body segment (parts[bdy.getLeng()].getX(),parts[bdy.getLeng()].getY()); Body segment (x,y);
parts.push_back(segment); parts.push_back(segment);
} }
void Snake::firstbody(){
Body segment (x, y);
parts.push_back(segment);
}
...@@ -135,8 +138,8 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -135,8 +138,8 @@ if (grid [x][y] == grid[h][o] ){
void Body::changeX(bool updown){ void Body::changeX(bool updown){
lastX = x; lastX = x;
lastY = y;
if (updown) if (updown)
x--; x--;
else else
...@@ -144,12 +147,14 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -144,12 +147,14 @@ if (grid [x][y] == grid[h][o] ){
} }
void Body::changeY(bool updown){ void Body::changeY(bool updown){
lastX = x;
lastY = y; lastY = y;
if (updown) if (updown)
y--; y--;
else else
y++; y++;
} }
Body::Body(int xCord, int yCord){ Body::Body(int xCord, int yCord){
...@@ -170,9 +175,9 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -170,9 +175,9 @@ if (grid [x][y] == grid[h][o] ){
return lastY; return lastY;
} }
void Body::follow(int count){ void Body::follow(int count){
x = parts[count].getlastX(); lastX = x;
y = parts[count].getlastY(); lastY = y;
x = parts[count - 1].getlastX();
y = parts[count - 1].getlastY();
} }
\ No newline at end of file
...@@ -16,7 +16,6 @@ class Snake { ...@@ -16,7 +16,6 @@ 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:
...@@ -34,6 +33,7 @@ class Snake { ...@@ -34,6 +33,7 @@ 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();
...@@ -42,7 +42,11 @@ class Body { ...@@ -42,7 +42,11 @@ class Body {
void follow(int count); void follow(int count);
int getlastX(); int getlastX();
int getlastY(); int getlastY();
void setLast(int count);
private: private:
int x, y; int x, y;
int lastX, lastY; int lastX, lastY;
char piece; char piece;
......
...@@ -43,7 +43,7 @@ void charCall() { ...@@ -43,7 +43,7 @@ void charCall() {
} }
int main() int main()
{ {
BrdSet.firstbody(); BrdSet.newBody();
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