Skip to content

Commit

Permalink
Tweaks and stuff
Browse files Browse the repository at this point in the history
Added in some very necessary frees() to pair with my mallocs(), along with a confirm menu when choosing to delete your scores.
  • Loading branch information
AidenManuel committed Dec 2, 2022
1 parent 1a52ed2 commit 792d542
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
17 changes: 14 additions & 3 deletions AI-Loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <curses.h>
#include <unistd.h>
#include <string.h>
#define DELAY 100000
#define AIDELAY 100000
#define SCALE 5000
#define SNAKE 1
#define FOOD 2
Expand Down Expand Up @@ -35,7 +35,7 @@ int AIfoodCollide(int fx, int fy, int sx, int sy) {
}

void AILoop() {
int ch;
int ch, speed = 1;

while(ch != '\n'){
// declaring AIsnake variables //
Expand Down Expand Up @@ -100,7 +100,18 @@ void AILoop() {
if(collide(AIsnake) || min_x > sx || sx > max_x || min_y > sx || sy > max_y )
break;

usleep(DELAY);
switch(ch) {
case 't':
if (speed != 20)
speed++;
break;
case 'g':
if (speed != 1)
speed--;
break;
}

usleep(AIDELAY/speed);

sx += dx; // update the head position and start again
sy += dy;
Expand Down
1 change: 1 addition & 0 deletions GP-Loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@ int mainLoop(int difficulty) {
sy += dy;
refresh();
}
free(snake);
return l;
}
11 changes: 8 additions & 3 deletions Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ int main() {
AILoop();
break;
case 4:
fp = fopen("scores.txt", "w");
fprintf(fp, "\n");
fclose(fp);
if(drawConfirm()) {
fp = fopen("scores.txt", "w");
fprintf(fp, "\n");
fclose(fp);
free(nullFella);
struct Player* nullFella = createPlayer(0, 'n', 'f', 0);
}
break;
case 5:
break;
Expand All @@ -118,5 +122,6 @@ int main() {

// End of Program
endwin();
free(nullFella);
return 0;
}
47 changes: 47 additions & 0 deletions Renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,53 @@ int drawDifficulty() {
}
}

///// CLEAR SCORE /////

int drawConfirm() {
selector = 31;
clear();
mainBorder();
mvprintw(1, 13, " C C C s s . N N A K K E E E ");
mvprintw(2, 13, " C s N N N A A K K E ");
mvprintw(3, 13, " C s s s N N N A A A K K E E ");
mvprintw(4, 13, " C s N N A A K K E ");
mvprintw(5, 13, " C C C . S s s N N A A K K E E E ");
mvprintw(9, 13, " ARE YOU SURE?");
mvprintw(12, 34, "NO");
mvprintw(12, 43, "YES");
while(choice == 0){
mvprintw(12, selector, "*");
switch(getch()) {
case 'd':
if(selector != 40){
mvprintw(12, selector, " ");
selector += 9;
}
break;
case 'a':
if(selector != 31){
mvprintw(12, selector, " ");
selector -= 9;
}
break;
case '\n':
switch(selector) {
case 31:
return 0;
break;
case 40:
return 1;
break;
}
break;
refresh();
default:
break;
}
usleep(DELAY);
}
}

///// DRAW BORDER /////

void drawBorder(char* title, int x1, int x2, int y1, int y2) { // Draws the box which is representative of the play area
Expand Down
14 changes: 8 additions & 6 deletions scores.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

2 AM 3300
2 AM 1500
4 AM 800
0 fl 400
0 fl 200
0 AM 100
2 dA 2700
1 AM 2400
4 AM 2200
2 AM 1400
4 dA 1000
4 da 900
1 AM 600
2 aj 100

0 comments on commit 792d542

Please sign in to comment.