snake wip
This commit is contained in:
BIN
deel2.tar.gz
BIN
deel2.tar.gz
Binary file not shown.
@@ -48,7 +48,7 @@ void update_grid(rooster *rp, char c, int x, int y) {
|
|||||||
* Clears the console and prints the victory message.
|
* Clears the console and prints the victory message.
|
||||||
*/
|
*/
|
||||||
static void display_victory(void) {
|
static void display_victory(void) {
|
||||||
clear();
|
erase();
|
||||||
mvprintw(2,5, "YOU WON!!!!!");
|
mvprintw(2,5, "YOU WON!!!!!");
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ static void display_victory(void) {
|
|||||||
* Clears the console and prints the GAME OVER message.
|
* Clears the console and prints the GAME OVER message.
|
||||||
*/
|
*/
|
||||||
static void display_loss(void) {
|
static void display_loss(void) {
|
||||||
clear();
|
erase();
|
||||||
mvprintw(2,5, "GAME OVER");
|
mvprintw(2,5, "GAME OVER");
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ static void display_loss(void) {
|
|||||||
* Clears the console and prints the quit message.
|
* Clears the console and prints the quit message.
|
||||||
*/
|
*/
|
||||||
static void display_quit(void) {
|
static void display_quit(void) {
|
||||||
clear();
|
erase();
|
||||||
mvprintw(2,5, "You quit the game");
|
mvprintw(2,5, "You quit the game");
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ static void display_quit(void) {
|
|||||||
* Clears the console and prints the hacker man message.
|
* Clears the console and prints the hacker man message.
|
||||||
*/
|
*/
|
||||||
static void display_hackerman(void) {
|
static void display_hackerman(void) {
|
||||||
clear();
|
erase();
|
||||||
mvprintw(2,5, "The hacker man strikes again...");
|
mvprintw(2,5, "The hacker man strikes again...");
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
@@ -138,6 +138,8 @@ static void init_ncurses() {
|
|||||||
init_pair(MAGENTA, COLOR_BLACK, COLOR_MAGENTA);
|
init_pair(MAGENTA, COLOR_BLACK, COLOR_MAGENTA);
|
||||||
init_pair(YELLOW, COLOR_BLACK, COLOR_YELLOW);
|
init_pair(YELLOW, COLOR_BLACK, COLOR_YELLOW);
|
||||||
init_pair(RED, COLOR_BLACK, COLOR_RED);
|
init_pair(RED, COLOR_BLACK, COLOR_RED);
|
||||||
|
|
||||||
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup_ncurses() {
|
static void cleanup_ncurses() {
|
||||||
|
|||||||
65
snake.c
65
snake.c
@@ -5,12 +5,67 @@
|
|||||||
#include "snake.h"
|
#include "snake.h"
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "grid_game_engine.h"
|
#include "grid_game_engine.h"
|
||||||
|
|
||||||
void snake(void) {
|
/*
|
||||||
clear();
|
* Create a grid for snake with a given height and width.
|
||||||
mvprintw(0,0, "Snake has not yet been created");
|
*
|
||||||
graceful_exit();
|
* Input:
|
||||||
refresh();
|
* height: The height of the map.
|
||||||
|
* width: The width of the map.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* A pointer to the grid.
|
||||||
|
*/
|
||||||
|
static rooster *initialize_snake(void) {
|
||||||
|
int width = 10;
|
||||||
|
int height = 10;
|
||||||
|
const int grid_size = (width + 1) * height + 1;
|
||||||
|
char *map = malloc(grid_size * sizeof(char));
|
||||||
|
if (map == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (width + 1) * height; i++) {
|
||||||
|
int top_line = i < width;
|
||||||
|
int bottom_line = i > grid_size - (width + 2);
|
||||||
|
|
||||||
|
int line_position = modulo(i, width + 1);
|
||||||
|
|
||||||
|
int line_start = line_position == 1;
|
||||||
|
int line_end = line_position == width;
|
||||||
|
|
||||||
|
int newline = line_position == 0;
|
||||||
|
|
||||||
|
if (newline) {
|
||||||
|
map[i] = '\n';
|
||||||
|
} else if (top_line || bottom_line || line_start || line_end) {
|
||||||
|
map[i] = '#';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
map[i] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
map[grid_size - 1] = '\0';
|
||||||
|
|
||||||
|
printf("%s", map);
|
||||||
|
|
||||||
|
rooster *grid = rooster_maak(map);
|
||||||
|
free(map);
|
||||||
|
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void snake(void) {
|
||||||
|
// erase();
|
||||||
|
rooster* const gp = initialize_snake();
|
||||||
|
if (gp == NULL) {
|
||||||
|
printf("Help, initializing the grid failed\n");
|
||||||
|
}
|
||||||
|
// show_grid(gp);
|
||||||
|
// graceful_exit();
|
||||||
|
// refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user