fl3kaucicpp/Snakes/snakes.cpp
2024-05-21 10:34:15 +02:00

89 lines
1.6 KiB
C++

#include <iostream>
#include <cstdlib>
#include <ncurses.h>
#include <thread>
using namespace std;
const int width = 80;
const int height = 20;
int snakeX = width/2;
int snakeY = height/2;
bool gameover;
void start(){
gameover=false;
}
void draw(){
//Change "clear" to "cls" if compiling for Windows
system("clear");
for(int i=0; i<width; i++){
cout << "#";
}
cout << endl;
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
if(j==0 || j==width-2){
cout<<"#";
}
if(j==snakeX && i==snakeY)
cout<<"o";
else
cout<<" ";
}cout<<endl;
}
for(int i=0; i<width; i++){
cout << "#";
}
cout<<endl;
}
void GameUpdate(int snakeXmv, WINDOW * win){
int c = getch();
printw("%d", c);
if(c == 97 || c == 68){
for(int i; i < snakeX; snakeXmv--){
curs_set(0);
mvwprintw(win,snakeY,snakeXmv,"o");
mvwprintw(win,snakeY,snakeXmv+1," ");
wrefresh(win);
this_thread::sleep_for(chrono::milliseconds(1000));
}
}
if(c == 67 || c == 100){
for(int i; i < snakeX; snakeXmv++){
curs_set(0);
mvwprintw(win,snakeY,snakeXmv,"o");
mvwprintw(win,snakeY,snakeXmv-1," ");
wrefresh(win);
this_thread::sleep_for(chrono::milliseconds(1000));
}
}
}
int main(){
int snakeXmv = snakeX;
while(!gameover){
start();
initscr();
WINDOW * win = newwin(height, width, 0, 0);
refresh();
box(win, 0, 0);
mvwprintw(win,snakeY,snakeXmv,"o");
wrefresh(win);
GameUpdate(snakeXmv, win);
cout << snakeXmv << endl;
getch();
endwin();
}
return 0;
}