Commit 2aad108b authored by Nelson Phillips's avatar Nelson Phillips

autosave

parent 6ba21b5f
g++ *.cpp -o main.out -pthread -std=c++11 && ./main.outf
\ No newline at end of file
......@@ -5,7 +5,7 @@
#include "Snake.h"
using namespace std;
bool hi = true;
Snake bdy;
vector <Body> parts;
void Snake::movement(char input){
......@@ -54,48 +54,66 @@ vector <Body> 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;
}
......
......@@ -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;
};
......
......@@ -4,16 +4,17 @@
#include "Snake.h"
#include <thread>
#include <vector>
#include <time.h>
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()
......
......@@ -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
g++ *.cpp -o main.out -pthread -std=c++11 && ./main.out
\ No newline at end of file
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