Commit bb95deef authored by Nelson Phillips's avatar Nelson Phillips

autosave

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