jag

snake_c

public

Small snake game in C

Star0
Watch0
e118234aa39babbcab57ae071a03988539e0844c
2
ssh://git@git.jaglekon.de:30/jag/snake_c.git
snake.hC93 lines1.8 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
  NO_DIRECTION = -1,
48
  UP = 0,
49
  LEFT = 1,
50
  DOWN = 2,
51
  RIGHT = 3,
52
  DIRECTIONS = 4
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
bool draw_menu(main_menu menu, struct winsize window_size);
83
bool draw_board(selected game_size, board_state **board,
84
  struct winsize window_size, bool redraw, bool paused);
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