jag

snake_c

public

Small snake game in C

Star0
Watch0
688f9381b99bb2b380957cf892d4c8e1a0e4ed77
2
ssh://git@git.jaglekon.de:30/jag/snake_c.git
source/snake.hC118 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
#include "animation/animation.h"
32
33
#define RIGHT_CODE 'C'
34
#define LEFT_CODE 'D'
35
#define UP_CODE 'A'
36
#define DOWN_CODE 'B'
37
38
#define WIDTH 20
39
#define HEIGHT 20
40
41
#define MIN_SIZE 10
42
#define MAX_SIZE 100
43
44
#define STRING_LEN 20
45
46
#define SCORE_NUMBER 10
47
48
#define SPEED 50 /* in ms */
49
50
#define MAX_LENGTH 1000
51
#define STARTING_LENGTH 2
52
53
#define SETTINGS_FILE "settings"
54
#define SCORE_FILE "score"
55
#define SETTINGS_FOLDER "snake_c"
56
57
typedef enum { NEW_GAME, SETTINGS, HIGHSCORE, EXIT, MAIN_MENU } main_menu;
58
59
typedef enum {HEIGHT_S, WIDTH_S, SPEED_S, BACK_S, SETTINGS_MENU} settings;
60
61
typedef enum {V_FAST, FAST, AVERAGE, SLOW, V_SLOW, SPEED_L} speed;
62
63
typedef enum {
64
  UP, LEFT, DOWN, RIGHT, DIRECTIONS,
65
  ENTER, P_BUTTON, Q_BUTTON, ESCAPE, DEL
66
} direction;
67
68
typedef enum {
69
  AIR, FRUIT, HEAD_1, HEAD_2, HORIZONTAL, VERTICAL, 
70
  TOP_RIGHT, TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT
71
} board_state;
72
73
typedef struct selected {
74
  int8_t x;
75
  int8_t y;
76
} selected;
77
78
typedef struct snake_part {
79
  selected coords;
80
  direction directions[2];
81
} snake_part;
82
83
typedef struct snake {
84
  snake_part * position;
85
  uint16_t length;
86
} snake;
87
88
89
uint8_t update_snake (selected game_size, snake *my_snake, direction shift);
90
void update_field(snake my_snake, selected game_size, 
91
  board_state **board, bool init);
92
selected new_fruit(selected game_size, board_state **board);
93
94
bool start_animation();
95
96
bool draw_menu(main_menu menu, struct winsize window_size);
97
void draw_settings(settings selected_setting, speed game_speed, selected game_size, struct winsize window_size);
98
99
bool draw_board(selected game_size, board_state **board,
100
  struct winsize window_size, bool redraw, uint8_t pause, uint16_t score);
101
102
void draw_pause(struct winsize window_size, 
103
  uint8_t field_width,uint8_t field_height, uint8_t game_over);
104
void draw_highscore (int16_t new_score, 
105
  highscore leader_board[SCORE_NUMBER], struct winsize window_size);
106
107
bool print_buffer(uint16_t width, char *string);
108
109
char *give_state(board_state square);
110
111
direction read_direction(char *string, bool wasd_enabled);
112
113
uint8_t make_folder(char *path);
114
115
116
uint8_t parse_parameters(int argc, char *args[]);
117
118
#endif