diff --git a/Testings/Snake/CLICK TO PLAY.sh b/Testings/Snake/CLICK TO PLAY.sh new file mode 100644 index 0000000000000000000000000000000000000000..de16d29b39937ad9b3b859ce56076c621305f5da --- /dev/null +++ b/Testings/Snake/CLICK TO PLAY.sh @@ -0,0 +1 @@ +g++ *.cpp -o main.out -pthread -std=c++11 && ./main.outf \ No newline at end of file diff --git a/Testings/Snake/Snake.cpp b/Testings/Snake/Snake.cpp index 191f79fdf7e62d950190bf7a311afae65b0f4591..7055a88c99bab231979f8fd63e97e2a69da11bd1 100644 --- a/Testings/Snake/Snake.cpp +++ b/Testings/Snake/Snake.cpp @@ -5,7 +5,7 @@ #include "Snake.h" using namespace std; - +bool hi = true; Snake bdy; vector parts; void Snake::movement(char input){ @@ -54,48 +54,66 @@ vector parts; } - void Snake::draw(){ - for (int i = 0; i < 14; i++){ - for (int q = 0; q < 30; q++){ - if (x < 1)bdy.over(); - if (y < 1)bdy.over(); - if (x > 11)bdy.over(); - if (y > 28)bdy.over(); - + bool Snake::draw(){ + for (int i = 0; i < 29; i++){ + for (int q = 0; q < 60; q++){ + if (x < 1)return false; + if (y < 1)return false; + if (x > 26)return false; + if (y > 57)return false; grid[i][q] = whtSpace; - if (h == i || o == q) grid[h][o] = '*'; - if (i == 12 || i == 0 || q == 0 || q == 29){ - grid[i][q] = 'O'; - } - + if (i == 27 || i == 0) + grid[i][q] = '|'; + if(q == 0 || q == 59) + grid[i][q] = '_'; + + for ( int count = 0; count < parts.size(); count++){ - grid[parts[count].getX()][parts[count].getY()] = 'B'; + if (grid[parts[0].getX()][parts[0].getY()] == '-') return false; + if (count == 0){ + if( direction == 2) + grid[parts[count].getX()][parts[count].getY()] = '>'; + else + if ( direction == 3) + grid[parts[count].getX()][parts[count].getY()] = 'v'; + else + if( direction == 4) + grid[parts[count].getX()][parts[count].getY()] = '<'; + else + if( direction == 1) + grid[parts[count].getX()][parts[count].getY()] = '^'; + else + grid[parts[count].getX()][parts[count].getY()] = 'O'; + } + else + grid[parts[count].getX()][parts[count].getY()] = '-'; + } - - if (i == x && q == y) - grid[x][y] = 'S'; } } - for (int i = 0; i < 14; i++){ + for (int i = 0; i < 29; i++){ cout << endl; - for (int q = 0; q < 30; q++){ + for (int q = 0; q < 60; q++){ cout << grid[i][q] << " "; - grid[i][q] == ' '; } } if (grid [x][y] == grid[h][o] ){ - h = (rand() % 11) + 1; - o = (rand() % 21) + 1; + h = (rand() % 26) + 1; + o = (rand() % 57) + 1; score++; - bdy.lengthed(); bdy.newBody(); + bonusBody = bonusBody + 2; +} else if (bonusBody > 0){ + bdy.newBody(); + bonusBody--; } +return true; } int Snake::snekoScore(){ return score; @@ -113,25 +131,22 @@ if (grid [x][y] == grid[h][o] ){ int Snake::getY(){ return y; } - int Snake::getLeng(){ - return length; - } - void Snake::lengthed(){ - length++; - } - - void Snake::newBody(){ + void Snake::newBody(){ Body segment (x,y); parts.push_back(segment); } - void Snake::over(){ - quitbool = true; + void Snake::GameOver(){ + for (int p = 0; p < 40; p++){ + cout << endl; } - bool Snake::quit(){ - - return quitbool; -} + cout << " _____ ____"<< endl << + " / ____| / __ | " << endl << + " | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __" << endl << + " | | |_ |/ _` | '_ ` _ | / _ | | | | || | / / _ | '__|" << endl << + " | |__| | (_| | | | | | | __/ | |__| || V / __/ |" << endl << + " |_____||__,_|_| |_| |_||___| |____/ |_/ |___|_|" << endl; + } diff --git a/Testings/Snake/Snake.h b/Testings/Snake/Snake.h index 96fa65188d893336c23bc6178361ec1db6b3ecbb..be1a56d62da85d61a5dd5ce155b9e6bbbd115d58 100644 --- a/Testings/Snake/Snake.h +++ b/Testings/Snake/Snake.h @@ -8,7 +8,7 @@ class Snake { public: void movement(char input); - void draw(); + bool draw(); int snekoScore(); void clrScreen(); void bodied(); @@ -16,20 +16,16 @@ class Snake { int getX(); int getY(); void newBody(); - void lengthed(); - int getLeng(); - void over(); - bool quit(); + void GameOver(); private: - int x = 5, y = 5, i = 0, q = 0, score = 0, - h = (rand() % 14), o = (rand() % 14); - char grid[15][30]; - int randChar = (rand() % 5); + + int x = 13, y = 13, i = 0, q = 0, score = 0, + h = 13, o = 23; + char grid[30][60]; char whtSpace = ' '; int direction = 5; - int length = -1; - bool quitbool = false; + int bonusBody = 0; }; diff --git a/Testings/Snake/SnakeTest.cpp b/Testings/Snake/SnakeTest.cpp index 3b894ffed2758eb6a1f550dbdd90464478e2e21a..c755843c8bfe55a38e4291f3ffefb9ce7b152d78 100644 --- a/Testings/Snake/SnakeTest.cpp +++ b/Testings/Snake/SnakeTest.cpp @@ -4,16 +4,17 @@ #include "Snake.h" #include #include +#include using namespace std; - +bool hello = true; Snake BrdSet; Thread Sneko; ReadInput inputRead; void charCall() { - while (!BrdSet.quit()){ + while (hello){ BrdSet.input = inputRead.collectInput(); if (BrdSet.input == 'q' || BrdSet.input == 'Q') break; @@ -22,7 +23,7 @@ void charCall() { } void snakePrint(){ - while (!BrdSet.quit()){ + while (hello){ Sneko.Sleep(1); system("stty cooked"); @@ -36,13 +37,16 @@ void charCall() { cout << "Your score is : " << BrdSet.snekoScore() << endl; - BrdSet.draw(); + hello = BrdSet.draw(); + if (hello == false) + BrdSet.GameOver(); system("stty raw"); } } int main() { + srand(time(NULL)); BrdSet.newBody(); thread first (charCall); // spawn new thread that calls input() diff --git a/Testings/Snake/Threads.cpp b/Testings/Snake/Threads.cpp index 11a107a7626bbe73ce69dd6eefd66baddeb21830..f7e703daa5c7dd8e484db3ea3477da87759a6164 100644 --- a/Testings/Snake/Threads.cpp +++ b/Testings/Snake/Threads.cpp @@ -4,6 +4,6 @@ #include "Threads.h" void Thread::Sleep(float s){ - int sec = int(s*250000); + int sec = int(s*130000); usleep(sec); } \ No newline at end of file diff --git a/Testings/Snake/compile.sh b/Testings/Snake/compile.sh deleted file mode 100644 index 848d26802c948c238c44f5a6415fbe4fbcbe5410..0000000000000000000000000000000000000000 --- a/Testings/Snake/compile.sh +++ /dev/null @@ -1 +0,0 @@ -g++ *.cpp -o main.out -pthread -std=c++11 && ./main.out \ No newline at end of file