jag

snake_c

public

Small snake game in C

Star0
Watch0
8da7b9789c5c75f128e094a74552cd3d98f904a0
2
ssh://git@git.jaglekon.de:30/jag/snake_c.git
snake.hC97 lines2.0 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 <time.h>
19
20
#include <ctype.h>
21
#include <string.h>
22
23
#define RIGHT_CODE 'C'
24
#define LEFT_CODE 'D'
25
#define UP_CODE 'A'
26
#define DOWN_CODE 'B'
27
28
#define WIDTH 20
29
#define HEIGHT 20
30
31
#define MIN_SIZE 10
32
#define MAX_SIZE 100
33
34
#define STRING_LEN 20
35
#define PATH_LEN 200
36
37
#define SPEED 50 /* in ms */
38
39
#define MAX_LENGTH 1000
40
#define STARTING_LENGTH 2
41
42
#define SETTING_FILE "snake_c.settings"
43
44
typedef enum { NEW_GAME, SETTINGS, EXIT, MAIN_MENU } main_menu;
45
46
typedef enum {HEIGHT_S, WIDTH_S, SPEED_S, BACK_S, SETTINGS_MENU} settings;
47
48
typedef enum {V_FAST, FAST, AVERAGE, SLOW, V_SLOW, SPEED_L} speed;
49
50
typedef enum {
51
  UP, LEFT, DOWN, RIGHT, DIRECTIONS,
52
  ENTER, P_KEY, Q_KEY, ESCAPE
53
} direction;
54
55
typedef enum {
56
  AIR, FRUIT, HEAD_1, HEAD_2, HORIZONTAL, VERTICAL, 
57
  TOP_RIGHT, TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT
58
} board_state;
59
60
typedef struct selected {
61
  int8_t x;
62
  int8_t y;
63
} selected;
64
65
typedef struct snake_part {
66
  selected coords;
67
  direction directions[2];
68
} snake_part;
69
70
typedef struct snake {
71
  snake_part * position;
72
  uint16_t length;
73
} snake;
74
75
76
uint8_t update_snake (selected game_size, snake *my_snake, direction shift);
77
void update_field(snake my_snake, selected game_size, 
78
  board_state **board, bool init);
79
selected new_fruit(selected game_size, board_state **board);
80
81
bool start_animation();
82
83
bool draw_menu(main_menu menu, struct winsize window_size);
84
void draw_settings(settings selected_setting, speed game_speed, selected game_size);
85
86
bool draw_board(selected game_size, board_state **board,
87
  struct winsize window_size, bool redraw, bool pause, uint16_t score);
88
89
void draw_pause(struct winsize window_size, 
90
  uint8_t field_width,uint8_t field_height);
91
92
char *give_state(board_state square);
93
94
direction read_direction(char *string, bool wasd_enabled);
95
96
97
#endif