jag

snake_c

public

Small snake game in C

Star0
Watch0
9357e6aedfb433987568f86b8ff19611c93ee1a9
2
ssh://git@git.jaglekon.de:30/jag/snake_c.git
snake.hC93 lines1.9 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
35
#define SPEED 50 /* in ms */
36
37
#define MAX_LENGTH 1000
38
#define STARTING_LENGTH 2
39
40
typedef enum { NEW_GAME, SETTINGS, EXIT, MAIN_MENU } main_menu;
41
42
typedef enum {HEIGHT_S, WIDTH_S, SPEED_S, BACK_S, SETTINGS_MENU} settings;
43
44
typedef enum {V_FAST, FAST, AVERAGE, SLOW, V_SLOW, SPEED_L} speed;
45
46
typedef enum {
47
  UP, LEFT, DOWN, RIGHT, DIRECTIONS,
48
  ENTER, P_KEY, Q_KEY, ESCAPE
49
} direction;
50
51
typedef enum {
52
  AIR, FRUIT, HEAD_1, HEAD_2, HORIZONTAL, VERTICAL, 
53
  TOP_RIGHT, TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT
54
} board_state;
55
56
typedef struct selected {
57
  int8_t x;
58
  int8_t y;
59
} selected;
60
61
typedef struct snake_part {
62
  selected coords;
63
  direction directions[2];
64
} snake_part;
65
66
typedef struct snake {
67
  snake_part * position;
68
  uint16_t length;
69
} snake;
70
71
72
uint8_t update_snake (selected game_size, snake *my_snake, direction shift);
73
void update_field(snake my_snake, selected game_size, 
74
  board_state **board, bool init);
75
selected new_fruit(selected game_size, board_state **board);
76
77
bool start_animation();
78
79
bool draw_menu(main_menu menu, struct winsize window_size);
80
void draw_settings(settings selected_setting, speed game_speed, selected game_size);
81
82
bool draw_board(selected game_size, board_state **board,
83
  struct winsize window_size, bool redraw, bool paused);
84
85
void draw_pause(struct winsize window_size, 
86
  uint8_t field_width,uint8_t field_height);
87
88
char *give_state(board_state square);
89
90
direction read_direction(char *string, bool wasd_enabled);
91
92
93
#endif