Commit 19e0fbe5 authored by Nelson Phillips's avatar Nelson Phillips
Browse files

autosave

parent 67be4b9a
#include <iostream>
#include "ReadInput.h"
#include "Threads.h"
#include <thread>
#include <thread>
#include <unistd.h>
#include "Snake.h"
using namespace std;
char grid[15][30];
int x = 0;
int y = 0;
int score = 0;
int randChar = (rand() % 5);
int bodyChar;
int h = (rand() % 14);
int o = (rand() % 30);
char letter = ' ';
ReadInput inputRead;
char input;
void charCall() {
for (int i = 0; i < 5000; i++){
input = inputRead.collectInput();
}
}
Thread Sneko;
void snakePrint(){
for (int i = 0; i < 5000; i++){
Sneko.Sleep(1);
system("stty cooked");
if(input == 'w'|| input == 'W')
void Snake::movement(char input){
if(input == 'w'|| input == 'W')
x--;
else
if(input == 'a'|| input == 'A')
......@@ -42,15 +19,11 @@ Thread Sneko;
else
if(input == 'd'|| input == 'D')
y++;
for (int p = 0; p < 40; p++){
cout << endl;
}
cout << "Your score is : " << score << endl;
for (int i = 0; i < 14; i++){
}
void Snake::draw(){
for (int i = 0; i < 14; i++){
cout << endl;
for (int q = 0; q < 30; q++){
if (x < 0)x++;
......@@ -64,7 +37,7 @@ Thread Sneko;
else if (i != h || o != q)
grid[i][q] = letter;
grid[i][q] = whtSpace;
cout << grid[i][q] << " ";
}
}
......@@ -73,32 +46,14 @@ Thread Sneko;
o = (rand() % 30);
score++;
}
system("stty raw");
}
}
int main()
{
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();
cout << " lkfnwefnwefnwdklfnd";
return 0;
}
//g++ *.cpp -o main.out -pthread -std=c++11 && ./main.out
//echo *.cpp
\ No newline at end of file
}
int Snake::snekoScore(){
return score;
}
void Snake::clrScreen(){
for (int p = 0; p < 40; p++){
cout << endl;
}
}
\ No newline at end of file
#ifndef SNAKE_H
#define SNAKE_H
#include <iostream>
class Snake {
public:
void movement(char input);
void draw();
int snekoScore();
void clrScreen();
char input;
private:
int x = 0, y = 0, i = 0, q = 0, score = 0,
h = (rand() % 14), o = (rand() % 14);
char grid[15][30];
int randChar = (rand() % 5);
char whtSpace = ' ';
};
#endif
\ No newline at end of file
#include <iostream>
#include "ReadInput.h"
#include "Threads.h"
#include "Snake.h"
#include <thread>
using namespace std;
Snake BrdSet;
Thread Sneko;
ReadInput inputRead;
void charCall() {
while (1){
BrdSet.input = inputRead.collectInput();
if (BrdSet.input == 'q' || BrdSet.input == 'Q')
break;
}
}
void snakePrint(){
while (1){
Sneko.Sleep(1);
system("stty cooked");
if (BrdSet.input == 'q' || BrdSet.input == 'Q')
break;
BrdSet.movement(BrdSet.input);
BrdSet.clrScreen();
cout << "Your score is : " << BrdSet.snekoScore() << endl;
BrdSet.draw();
system("stty raw");
}
}
int main()
{
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();
cout << " lkfnwefnwefnwdklfnd";
return 0;
}
//g++ *.cpp -o main.out -pthread -std=c++11 && ./main.out
//echo *.cpp
\ No newline at end of file
Supports Markdown
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