jag

snake_c

public

Small snake game in C

Star0
Watch0
96e537edae6d1395366a3373a36ff008ef48c423
2
ssh://git@git.jaglekon.de:30/jag/snake_c.git
source/snake.hC119 lines2.5 KB
1
#ifndef SNAKE_H
2
#define SNAKE_H
3
4
5
#define _POSIX_C_SOURCE 199309L
6
7
#include <termios.h>
8
#include <unistd.h>
9
10
#include <stdbool.h>
11
#include <stdint.h>
12
#include <stdio.h>
13
#include <stdlib.h>
14
15
#include <sys/ioctl.h>
16
#include <sys/stat.h>
17
18
#include <errno.h>
19
20
#include <time.h>
21
22
#include <ctype.h>
23
#include <string.h>
24
25
#include <limits.h>
26
27
#include <jag_parse.h>
28
#include <jag_write.h>
29
30
#include "settings_file/settings_file.h"
31
32
#define RIGHT_CODE 'C'
33
#define LEFT_CODE 'D'
34
#define UP_CODE 'A'
35
#define DOWN_CODE 'B'
36
37
#define WIDTH 20
38
#define HEIGHT 20
39
40
#define MIN_SIZE 10
41
#define MAX_SIZE 100
42
43
#define STRING_LEN 20
44
45
#define SCORE_NUMBER 10
46
47
#define SPEED 50 /* in ms */
48
49
#define MAX_LENGTH 1000
50
#define STARTING_LENGTH 2
51
52
#define SETTINGS_FILE "settings"
53
#define SCORE_FILE "score"
54
#define SETTINGS_FOLDER "snake_c"
55
56
typedef enum { NEW_GAME, SETTINGS, HIGHSCORE, EXIT, MAIN_MENU } main_menu;
57
58
typedef enum {HEIGHT_S, WIDTH_S, SPEED_S, BACK_S, SETTINGS_MENU} settings;
59
60
typedef enum {V_FAST, FAST, AVERAGE, SLOW, V_SLOW, SPEED_L} speed;
61
62
typedef enum {
63
  UP, LEFT, DOWN, RIGHT, DIRECTIONS,
64
  ENTER, P_BUTTON, Q_BUTTON, ESCAPE, DEL
65
} direction;
66
67
typedef enum {
68
  AIR, FRUIT, HEAD_1, HEAD_2, HORIZONTAL, VERTICAL, 
69
  TOP_RIGHT, TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT
70
} board_state;
71
72
typedef struct selected {
73
  int8_t x;
74
  int8_t y;
75
} selected;
76
77
typedef struct snake_part {
78
  selected coords;
79
  direction directions[2];
80
} snake_part;
81
82
typedef struct snake {
83
  snake_part * position;
84
  uint16_t length;
85
} snake;
86
87
88
uint8_t update_snake (selected game_size, snake *my_snake, direction shift);
89
void update_field(snake my_snake, selected game_size, 
90
  board_state **board, bool init);
91
selected new_fruit(selected game_size, board_state **board);
92
93
bool start_animation();
94
95
bool draw_menu(main_menu menu, struct winsize window_size);
96
void draw_settings(settings selected_setting, speed game_speed, selected game_size, struct winsize window_size);
97
98
bool draw_board(selected game_size, board_state **board,
99
  struct winsize window_size, bool redraw, uint8_t pause, uint16_t score);
100
101
void draw_pause(struct winsize window_size, 
102
  uint8_t field_width,uint8_t field_height, uint8_t game_over);
103
void draw_highscore (int16_t new_score, 
104
  highscore leader_board[SCORE_NUMBER], struct winsize window_size);
105
106
bool print_buffer(uint16_t width, char *string);
107
108
char *give_state(board_state square);
109
110
direction read_direction(char *string, bool wasd_enabled);
111
112
uint8_t make_folder(char *path);
113
114
int32_t string_to_num(char* string, int32_t min, int32_t max, int32_t number);
115
116
117
uint8_t parse_parameters(int argc, char *args[]);
118
119
#endif