This commit is contained in:
fl3ka 2024-05-21 10:34:15 +02:00
parent dcbc403a8b
commit f65249e597
3 changed files with 53 additions and 7 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
Resursi
Ncurses:
https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html
https://invidious.einfachzocken.eu/watch?v=pjT5wq11ZSE&list=PL2U2TQ__OrQ8jTf0_noNKtHMuYlyxQl4v

Binary file not shown.

View File

@ -1,11 +1,13 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <ncurses.h>
#include <thread>
using namespace std; using namespace std;
const int width = 80; const int width = 80;
const int height = 20; const int height = 20;
int snakeX = width/2;
int snakeY = height/2;
bool gameover; bool gameover;
const int snakeX = width/2;
const int snakeY = height/2;
void start(){ void start(){
@ -22,8 +24,8 @@ for(int i=0; i<width; i++){
} }
cout << endl; cout << endl;
for(int i=0; i<height; i++){ for(int i=0; i<height; i++){
for(int j=0; j<=width; j++){ for(int j=0; j<width; j++){
if(j==0 || j==width){ if(j==0 || j==width-2){
cout<<"#"; cout<<"#";
} }
if(j==snakeX && i==snakeY) if(j==snakeX && i==snakeY)
@ -38,12 +40,47 @@ for(int i=0; i<width; i++){
cout<<endl; 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 main(){
int snakeXmv = snakeX;
while(!gameover) while(!gameover){
draw(); 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; return 0;