From 34ac98cf7f284bd944c4eaeb6f608a4e72755b26 Mon Sep 17 00:00:00 2001 From: Nelson Phillips Date: Mon, 11 Mar 2019 00:59:01 +0000 Subject: [PATCH] autosave --- Testings/Snake/Snake.cpp | 83 +++++++++++++++++++++++++----------- Testings/Snake/Snake.h | 13 ++++-- Testings/Snake/SnakeTest.cpp | 20 +++++---- 3 files changed, 78 insertions(+), 38 deletions(-) diff --git a/Testings/Snake/Snake.cpp b/Testings/Snake/Snake.cpp index ed9a7a8..ef2d47b 100644 --- a/Testings/Snake/Snake.cpp +++ b/Testings/Snake/Snake.cpp @@ -6,6 +6,10 @@ using namespace std; + + +vector 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 diff --git a/Testings/Snake/Snake.h b/Testings/Snake/Snake.h index 889f2ef..b1fafd9 100644 --- a/Testings/Snake/Snake.h +++ b/Testings/Snake/Snake.h @@ -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; - //vectorparts(); }; + + + 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 diff --git a/Testings/Snake/SnakeTest.cpp b/Testings/Snake/SnakeTest.cpp index 0806f48..e2b8bf1 100644 --- a/Testings/Snake/SnakeTest.cpp +++ b/Testings/Snake/SnakeTest.cpp @@ -3,6 +3,8 @@ #include "Threads.h" #include "Snake.h" #include +#include + 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; } -- GitLab