Fixed compiler warnings

This commit is contained in:
2025-10-17 15:27:18 +02:00
parent f0e9d5c751
commit a2d4290076
3 changed files with 9 additions and 5 deletions

BIN
deel2.tar.gz Normal file

Binary file not shown.

14
snake.c
View File

@@ -2,6 +2,8 @@
// Created by snapshot112 on 10/15/25. // Created by snapshot112 on 10/15/25.
// //
#define _POSIX_C_SOURCE 199309
#include "snake.h" #include "snake.h"
#include <ncurses.h> #include <ncurses.h>
@@ -240,8 +242,12 @@ static void update_snake(coordinate new_head, snake_action action) {
} }
static void *snake_move(void *arg) { static void *snake_move(void *arg) {
struct timespec timer;
timer.tv_sec = 0;
timer.tv_nsec = 250000000L;
while (rooster_vraag_toestand(GRID) == STATE_AAN_HET_SPELEN) { while (rooster_vraag_toestand(GRID) == STATE_AAN_HET_SPELEN) {
usleep(250000); nanosleep(&timer, NULL);
pthread_mutex_lock(&MUTEX); pthread_mutex_lock(&MUTEX);
coordinate new_head = SNAKE_HEAD; coordinate new_head = SNAKE_HEAD;
switch (CURRENT_DIRECTION) { switch (CURRENT_DIRECTION) {
@@ -332,17 +338,15 @@ void snake(void) {
rooster_zet_toestand(GRID, STATE_AAN_HET_SPELEN); rooster_zet_toestand(GRID, STATE_AAN_HET_SPELEN);
// Allow turning before you let the snake move.
pthread_create(&user_input, NULL, play_snake, NULL);
while (getch() != ' ') {} while (getch() != ' ') {}
// Cleanup the start playing message. // Cleanup the start playing message.
mvaddstr(MESSAGE_LOCATION.y, MESSAGE_LOCATION.x, " "); mvaddstr(MESSAGE_LOCATION.y, MESSAGE_LOCATION.x, " ");
pthread_create(&user_input, NULL, play_snake, NULL);
pthread_create(&game_tick, NULL, snake_move, NULL); pthread_create(&game_tick, NULL, snake_move, NULL);
// Cleanup game thread logic. // Wait until the gamestate is no longer STATE_AAN_HET_SPELEN
pthread_join(game_tick, NULL); pthread_join(game_tick, NULL);
pthread_join(user_input, NULL); pthread_join(user_input, NULL);
pthread_mutex_destroy(&MUTEX); pthread_mutex_destroy(&MUTEX);

BIN
spel

Binary file not shown.