Commit 34ac98cf authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 541cb824
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
using namespace std; using namespace std;
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;
...@@ -41,31 +45,39 @@ using namespace std; ...@@ -41,31 +45,39 @@ using namespace std;
void Snake::draw(){ void Snake::draw(){
for (int i = 0; i < 14; i++){ for (int i = 0; i < 14; i++){
cout << endl; cout << endl;
for (int q = 0; q < 30; q++){ for (int q = 0; q < 30; q++){
if (x < 0)x++; if (x < 0)x++;
if (y < 0)y++; if (y < 0)y++;
if (x > 12)x--; if (x > 12)x--;
if (y > 29)y--; if (y > 29)y--;
for ( int count = 0; count < parts.size(); count++){
if (h == i || o == q) if ((parts[count].getX() == x - 1) && (parts[count].getY() == y - 1))
grid[h][o] = '*'; grid[i - 1][q - 1] = 'B';
if (i == x && q == y) }
grid[x][y] = 'S'; if (i == x && q == y)
grid[x][y] = 'S';
else if (i != h || o != q) else
grid[i][q] = whtSpace;
cout << grid[i][q] << " "; if (h == i || o == q)
} grid[h][o] = '*';
}
else
if (i != h || o != q)
grid[i][q] = whtSpace;
cout << grid[i][q] << " ";
}
}
if (grid [x][y] == grid[h][o] ){ if (grid [x][y] == grid[h][o] ){
h = (rand() % 13); h = (rand() % 13);
o = (rand() % 30); o = (rand() % 30);
score++; score++;
} }
} }
...@@ -79,13 +91,32 @@ score++; ...@@ -79,13 +91,32 @@ score++;
} }
} }
int Snake::getX(){
return x;
}
int Snake::getY(){
return y;
}
void Snake::bodied(){ void Snake::newBody(){
Body segment (x, y);
parts.push_back(segment);
} }
\ No newline at end of file
Body::Body(int xCord, int yCord){
x = xCord;
y = yCord;
}
int Body::getX(){
return x;
}
int Body::getY(){
return y;
}
\ No newline at end of file
...@@ -13,6 +13,9 @@ class Snake { ...@@ -13,6 +13,9 @@ class Snake {
void clrScreen(); void clrScreen();
void bodied(); void bodied();
char input; char input;
int getX();
int getY();
void newBody();
private: private:
int x = 0, y = 0, i = 0, q = 0, score = 0, int x = 0, y = 0, i = 0, q = 0, score = 0,
h = (rand() % 14), o = (rand() % 14); h = (rand() % 14), o = (rand() % 14);
...@@ -20,14 +23,18 @@ class Snake { ...@@ -20,14 +23,18 @@ class Snake {
int randChar = (rand() % 5); int randChar = (rand() % 5);
char whtSpace = ' '; char whtSpace = ' ';
int direction = 5; int direction = 5;
//vector<Body>parts();
}; };
class Body { class Body {
public: public:
Body(int xCord, int yCord);
int getX();
int getY();
private: private:
int x, y; int x, y,length;
char piece; char piece;
}; };
#endif #endif
\ No newline at end of file
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "Threads.h" #include "Threads.h"
#include "Snake.h" #include "Snake.h"
#include <thread> #include <thread>
#include <vector>
using namespace std; using namespace std;
...@@ -35,22 +37,22 @@ void charCall() { ...@@ -35,22 +37,22 @@ void charCall() {
cout << "Your score is : " << BrdSet.snekoScore() << endl; cout << "Your score is : " << BrdSet.snekoScore() << endl;
BrdSet.draw(); BrdSet.draw();
system("stty raw"); system("stty raw");
} }
} }
int main() int main()
{ {
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)
cout << "Press w,a,s,d to begin."; cout << "Press w,a,s,d to begin.";
// synchronize threads: // synchronize threads:
first.join(); // pauses until first finishes first.join(); // pauses until first finishes
second.join(); second.join();
return 0; return 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