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

autosave

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