-
Notifications
You must be signed in to change notification settings - Fork 0
/
k.h
71 lines (59 loc) · 1.97 KB
/
k.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _K_H
#define _K_H
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <ncurses.h>
#include <unistd.h>
// size of the board
#define SIZE 4
struct game {
// game board
char board[SIZE][SIZE];
// current score
int score;
};
bool move_UP(struct game *game);
bool move_DOWN(struct game *game);
bool move_RIGHT(struct game *game);
bool move_LEFT(struct game *game);
int search(char *letters, char letterToFind);
void trace_score(int col, int raw, struct game *game);
void get_input(int *dy, int *dx);
void copy_content(struct game *game, struct game *copy);
/**
* Adds random A or B tile to the game
* This is very dumb function. The board must have at least one empty tile. If
* there is no empty tile, function will end in infinite loop.
* @param game reference to the game object
*/
void add_random_tile(struct game *game);
/**
* Makes move in given direction
* If it is possible, function makes move in given direction, updates the
* current game state (board and score) and returns true. If it is not
* possible to move, returns false.
* @param game reference to the game object
* @param dy movement in y-axe
* @param dx movement in y-axe
* @return true, if game state was updated, false otherwise
*/
bool update(struct game *game, int dy, int dx);
/**
* Checks whether it is possible to make move
* Function checks game board if it is possible to make another move. The
* move is possible, if there are two tiles with the same letter nearby or
* there is at least one empty tile.
* @param game the game object with board to check
* @return true, if another movement is possible, or false otherwise.
*/
bool is_move_possible(const struct game game);
/**
* Checks whether game is already won
* Returns true, if tile with letter 'K' is located on the board. Returns
* false, if it is not.
* @param game the game object with board to check
* @return true, if game is won, or false otherwise.
*/
bool is_game_won(const struct game game);
#endif