jag

snake_c

public

Small snake game in C

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