Final prbly
This commit is contained in:
parent
c1be553425
commit
4a50dfd049
@ -1,9 +1,10 @@
|
||||
Resursi
|
||||
|
||||
Ncurses:
|
||||
|
||||
https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/index.html
|
||||
|
||||
https://invidious.einfachzocken.eu/watch?v=pjT5wq11ZSE&list=PL2U2TQ__OrQ8jTf0_noNKtHMuYlyxQl4v
|
||||
|
||||
Compiling:
|
||||
|
||||
g++ -o snakes snakes.cpp -lncurses
|
||||
|
BIN
Snakes/snakes
BIN
Snakes/snakes
Binary file not shown.
@ -9,10 +9,12 @@ const int width = 80;
|
||||
const int height = 20;
|
||||
int X = width/2;
|
||||
int Y = height/2;
|
||||
int TailY[100];
|
||||
int TailX[100];
|
||||
int sLen = 0;
|
||||
int sDir = 0;
|
||||
int score = -1;
|
||||
int count = 0;
|
||||
int tail = 1;
|
||||
bool gameover;
|
||||
WINDOW * win;
|
||||
WINDOW * win2;
|
||||
@ -71,6 +73,7 @@ void fruit(int &fX, int &fY){
|
||||
}
|
||||
if (score == -1 || (fX == X && fY == Y)){
|
||||
score++;
|
||||
sLen++;
|
||||
count++;
|
||||
wrefresh(win2);
|
||||
fX = 3 + (rand() % 75);
|
||||
@ -92,6 +95,21 @@ void RenderField(){
|
||||
}
|
||||
|
||||
void GameUpdate(int &diff, int &fX, int &fY){
|
||||
int prevX=TailX[0];
|
||||
int prevY=TailY[0];
|
||||
int prev2X,prev2Y;
|
||||
TailX[0]=X;
|
||||
TailY[0]=Y;
|
||||
|
||||
for(int i=1; i<sLen; i++){
|
||||
prev2X=TailX[i];
|
||||
prev2Y=TailY[i];
|
||||
TailX[i]=prevX;
|
||||
TailY[i]=prevY;
|
||||
prevX=prev2X;
|
||||
prevY=prev2Y;
|
||||
}
|
||||
|
||||
|
||||
switch(sDir){
|
||||
case 97:
|
||||
@ -120,13 +138,20 @@ case 66:
|
||||
break;
|
||||
}
|
||||
mvwprintw(win, Y, X, "o");
|
||||
for(int i=0;i<sLen;i++){
|
||||
mvwprintw(win, TailY[i], TailX[i],"o");
|
||||
}
|
||||
for(int i=1; i<sLen; i++){
|
||||
if (TailY[i]==Y && TailX[i]==X)
|
||||
gameover=true;
|
||||
}
|
||||
mvwprintw(win2, 1, 3, "Score: %d", score);
|
||||
fruit(fX, fY);
|
||||
wrefresh(win2);
|
||||
wrefresh(win);
|
||||
if (count >= 5 && diff != 50){
|
||||
count = 0;
|
||||
diff -= 30;}
|
||||
diff -= 50;}
|
||||
this_thread::sleep_for(chrono::milliseconds(diff));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user