From ac6353817f2104d6043835c817e15b8611f605f5 Mon Sep 17 00:00:00 2001 From: Nelson Phillips Date: Tue, 12 Mar 2019 03:31:46 +0000 Subject: [PATCH] autosave --- Testings/Snake/Snake.cpp | 46 +++++++++++++++++++----------------- Testings/Snake/Snake.h | 4 ++++ Testings/Snake/SnakeTest.cpp | 4 ++-- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Testings/Snake/Snake.cpp b/Testings/Snake/Snake.cpp index d6cbf8b..191f79f 100644 --- a/Testings/Snake/Snake.cpp +++ b/Testings/Snake/Snake.cpp @@ -8,7 +8,6 @@ using namespace std; Snake bdy; vector parts; - void Snake::movement(char input){ if((input == 'w'|| input == 'W')&& direction != 3 ) direction = 1; @@ -48,8 +47,8 @@ vector parts; parts[0].changeY(0); } - for (int count = 0; count < parts.size() - 1; count++){ - if (count != 0) + for (int count = 0; count < parts.size(); count++){ + if (count != 0) parts[count].follow(count); } } @@ -58,29 +57,26 @@ vector parts; void Snake::draw(){ for (int i = 0; i < 14; i++){ for (int q = 0; q < 30; q++){ - if (x < 1)x++; - if (y < 1)y++; - if (x > 11)x--; - if (y > 28)y--; + if (x < 1)bdy.over(); + if (y < 1)bdy.over(); + if (x > 11)bdy.over(); + if (y > 28)bdy.over(); + + grid[i][q] = whtSpace; - if (h == i || o == q) 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){ grid[i][q] = 'O'; } - - for ( int count = 0; count < parts.size(); count++){ - grid[parts[count].getX()][parts[count].getY()] = 'B'; - } - } + + for ( int count = 0; count < parts.size(); count++){ + 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] ){ bdy.lengthed(); bdy.newBody(); } - } int Snake::snekoScore(){ return score; @@ -129,7 +124,14 @@ if (grid [x][y] == grid[h][o] ){ Body segment (x,y); parts.push_back(segment); } - + + void Snake::over(){ + quitbool = true; + } + bool Snake::quit(){ + + return quitbool; +} diff --git a/Testings/Snake/Snake.h b/Testings/Snake/Snake.h index f7455d1..96fa651 100644 --- a/Testings/Snake/Snake.h +++ b/Testings/Snake/Snake.h @@ -18,6 +18,9 @@ class Snake { void newBody(); void lengthed(); int getLeng(); + void over(); + bool quit(); + private: int x = 5, y = 5, i = 0, q = 0, score = 0, h = (rand() % 14), o = (rand() % 14); @@ -26,6 +29,7 @@ class Snake { char whtSpace = ' '; int direction = 5; int length = -1; + bool quitbool = false; }; diff --git a/Testings/Snake/SnakeTest.cpp b/Testings/Snake/SnakeTest.cpp index e2b8bf1..3b894ff 100644 --- a/Testings/Snake/SnakeTest.cpp +++ b/Testings/Snake/SnakeTest.cpp @@ -13,7 +13,7 @@ Thread Sneko; ReadInput inputRead; void charCall() { - while (1){ + while (!BrdSet.quit()){ BrdSet.input = inputRead.collectInput(); if (BrdSet.input == 'q' || BrdSet.input == 'Q') break; @@ -22,7 +22,7 @@ void charCall() { } void snakePrint(){ - while (1){ + while (!BrdSet.quit()){ Sneko.Sleep(1); system("stty cooked"); -- GitLab