Commit ac635381 authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 962b4c8a
...@@ -8,7 +8,6 @@ using namespace std; ...@@ -8,7 +8,6 @@ using namespace std;
Snake bdy; Snake bdy;
vector <Body> parts; vector <Body> parts;
void Snake::movement(char input){ void Snake::movement(char input){
if((input == 'w'|| input == 'W')&& direction != 3 ) if((input == 'w'|| input == 'W')&& direction != 3 )
direction = 1; direction = 1;
...@@ -48,8 +47,8 @@ vector <Body> parts; ...@@ -48,8 +47,8 @@ vector <Body> parts;
parts[0].changeY(0); parts[0].changeY(0);
} }
for (int count = 0; count < parts.size() - 1; count++){ for (int count = 0; count < parts.size(); count++){
if (count != 0) if (count != 0)
parts[count].follow(count); parts[count].follow(count);
} }
} }
...@@ -58,29 +57,26 @@ vector <Body> parts; ...@@ -58,29 +57,26 @@ vector <Body> parts;
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 < 1)x++; if (x < 1)bdy.over();
if (y < 1)y++; if (y < 1)bdy.over();
if (x > 11)x--; if (x > 11)bdy.over();
if (y > 28)y--; if (y > 28)bdy.over();
grid[i][q] = whtSpace;
if (h == i || o == q) if (h == i || o == q)
grid[h][o] = '*'; grid[h][o] = '*';
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){ if (i == 12 || i == 0 || q == 0 || q == 29){
grid[i][q] = 'O'; 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';
} }
}
if (i == x && q == y)
grid[x][y] = 'S';
}
} }
...@@ -100,7 +96,6 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -100,7 +96,6 @@ if (grid [x][y] == grid[h][o] ){
bdy.lengthed(); bdy.lengthed();
bdy.newBody(); bdy.newBody();
} }
} }
int Snake::snekoScore(){ int Snake::snekoScore(){
return score; return score;
...@@ -129,7 +124,14 @@ if (grid [x][y] == grid[h][o] ){ ...@@ -129,7 +124,14 @@ if (grid [x][y] == grid[h][o] ){
Body segment (x,y); Body segment (x,y);
parts.push_back(segment); parts.push_back(segment);
} }
void Snake::over(){
quitbool = true;
}
bool Snake::quit(){
return quitbool;
}
......
...@@ -18,6 +18,9 @@ class Snake { ...@@ -18,6 +18,9 @@ class Snake {
void newBody(); void newBody();
void lengthed(); void lengthed();
int getLeng(); int getLeng();
void over();
bool quit();
private: private:
int x = 5, y = 5, i = 0, q = 0, score = 0, int x = 5, y = 5, i = 0, q = 0, score = 0,
h = (rand() % 14), o = (rand() % 14); h = (rand() % 14), o = (rand() % 14);
...@@ -26,6 +29,7 @@ class Snake { ...@@ -26,6 +29,7 @@ class Snake {
char whtSpace = ' '; char whtSpace = ' ';
int direction = 5; int direction = 5;
int length = -1; int length = -1;
bool quitbool = false;
}; };
......
...@@ -13,7 +13,7 @@ Thread Sneko; ...@@ -13,7 +13,7 @@ Thread Sneko;
ReadInput inputRead; ReadInput inputRead;
void charCall() { void charCall() {
while (1){ while (!BrdSet.quit()){
BrdSet.input = inputRead.collectInput(); BrdSet.input = inputRead.collectInput();
if (BrdSet.input == 'q' || BrdSet.input == 'Q') if (BrdSet.input == 'q' || BrdSet.input == 'Q')
break; break;
...@@ -22,7 +22,7 @@ void charCall() { ...@@ -22,7 +22,7 @@ void charCall() {
} }
void snakePrint(){ void snakePrint(){
while (1){ while (!BrdSet.quit()){
Sneko.Sleep(1); Sneko.Sleep(1);
system("stty cooked"); system("stty cooked");
......
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