Fixed compiler warnings
This commit is contained in:
BIN
deel2.tar.gz
Normal file
BIN
deel2.tar.gz
Normal file
Binary file not shown.
14
snake.c
14
snake.c
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user