#include #include #include #include #include "Snake.h" using namespace std; Snake bdy; vector parts; void Snake::movement(char input){ if((input == 'w'|| input == 'W')&& direction != 3 ) direction = 1; else if((input == 'a'|| input == 'A')&& direction != 2 ) direction = 4; else if((input == 's'|| input == 'S')&& direction != 1 ) direction = 3; else if((input == 'd'|| input == 'D')&& direction != 4 ) direction = 2; if(direction == 1){ x--; for ( int count = 0; count < parts.size(); count++){ parts[count].changeX(1); } } else if(direction == 4){ y--; for ( int count = 0; count < parts.size(); count++){ parts[count].changeY(1); } } else if(direction == 3){ x++; for ( int count = 0; count < parts.size(); count++){ parts[count].changeX(0); } } else if(direction == 2){ y++; for ( int count = 0; count < parts.size(); count++){ parts[count].changeY(0); } } } void Snake::draw(){ for (int i = 0; i < 14; i++){ 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'; if ((i != h || o != q) && (i != x || q != y)) grid[i][q] = whtSpace; for ( int count = 0; count < parts.size(); count++){ grid[parts[count].getX()][parts[count].getY()] = 'B'; } } } for (int i = 0; i < 14; i++){ cout << endl; for (int q = 0; q < 30; q++){ cout << grid[i][q] << " "; grid[i][q] == ' '; } } if (grid [x][y] == grid[h][o] ){ h = (rand() % 13); o = (rand() % 30); score++; bdy.lengthed(); bdy.newBody(); } } int Snake::snekoScore(){ return score; } void Snake::clrScreen(){ for (int p = 0; p < 40; p++){ cout << endl; } } int Snake::getX(){ return x; } int Snake::getY(){ return y; } int Snake::getLeng(){ return length; } void Snake::lengthed(){ length++; } void Snake::newBody(){ Body segment (x,y);//parts[bdy.getLeng()].getX(), parts[bdy.getLeng()].getY() parts.push_back(segment); } void Body::changeX(bool updown){ if (updown) x--; else x++; } void Body::changeY(bool updown){ if (updown) y--; else y++; } Body::Body(int xCord, int yCord){ x = xCord; y = yCord; } int Body::getX(){ return x; } int Body::getY(){ return y; }