-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,776 additions
and
982 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ build/ | |
old | ||
_*.c | ||
_*.h | ||
.clang-format | ||
.idea | ||
.cores | ||
tmp/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef TINYCOLS_H | ||
#define TINYCOLS_H | ||
|
||
#include "tinycols/color.h" | ||
#include "tinycols/direction.h" | ||
#include "tinycols/game.h" | ||
#include "tinycols/game_utils.h" | ||
#include "tinycols/grid.h" | ||
#include "tinycols/piece.h" | ||
#include "tinycols/result.h" | ||
#include "tinycols/score.h" | ||
|
||
#endif //TINYCOLS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef TINYCOLS_COLOR_H | ||
#define TINYCOLS_COLOR_H | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#include "grid.h" | ||
|
||
#define COLOR_MAX YELLOW | ||
|
||
/** | ||
* color - All the colors of a jewel piece. | ||
*/ | ||
enum color { | ||
TRANSPARENT, | ||
PURPLE, | ||
ORANGE, | ||
BLUE, | ||
RED, | ||
GREEN, | ||
YELLOW | ||
}; | ||
|
||
/** | ||
* get_cell_color() - Get the grid cell color at the given row and column. | ||
* | ||
* @param gr: The grid to inspect. | ||
* @param row: The row of the cell. | ||
* @param col: The column of the cell. | ||
* @return The color of the given cell. | ||
*/ | ||
enum color get_cell_color(const struct grid *gr, int row, int col); | ||
|
||
/** | ||
* set_cell_color() - Set the grid cell color at the given row and column. | ||
* | ||
* @param gr: The grid to inspect. | ||
* @param row: The row of the cell. | ||
* @param col: The column of the cell. | ||
* @param clr: The color to set. | ||
*/ | ||
void set_cell_color(struct grid *gr, int row, int col, enum color clr); | ||
|
||
#endif //TINYCOLS_COLOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef TINYCOLS_DIRECTION_H | ||
#define TINYCOLS_DIRECTION_H | ||
|
||
/** | ||
* direction - The direction a piece can take. | ||
*/ | ||
enum direction { UP, DOWN, LEFT, RIGHT }; | ||
|
||
#endif //TINYCOLS_DIRECTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef TINYCOLS_GAME_H | ||
#define TINYCOLS_GAME_H | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#include "color.h" | ||
#include "piece.h" | ||
#include "score.h" | ||
|
||
#define GAME_DEFAULT_LEVEL 0 | ||
#define GAME_DEFAULT_COLOR_MIN RED | ||
#define GAME_DEFAULT_COLOR_MAX YELLOW | ||
#define GAME_DEFAULT_JEWELS_FOR_LEVEL 30 | ||
#define GAME_SCORE_PER_PIECE 30 | ||
|
||
/** | ||
* game_status - The possible states a game can take. | ||
*/ | ||
enum game_state { GAME_READY, GAME_PAUSED, GAME_OVER, GAME_EXIT }; | ||
|
||
/** | ||
* game_class - The game skill class, mapped to the appropriate colors | ||
*/ | ||
enum game_class { | ||
CLASS_NOVICE = RED, | ||
CLASS_AMATEUR = GREEN, | ||
CLASS_PRO = YELLOW | ||
}; | ||
|
||
/** | ||
* game - A game of Tiny Cols | ||
* | ||
* @param level: The current difficulty level of the game (starts from zero). | ||
* @param score: The current total score. | ||
* @param last_score: The last sub-score that was recorded in-game. | ||
* @param jewels_removed: The total number of jewels that were removed. | ||
* @param status: The current game status. | ||
* @param color_max: The maximum color that can be used in-game. | ||
* This is linked to the difficulty level. | ||
* @param current_piece: The current in-game piece, controlled by the player. | ||
* @param next_piece: The next piece to be played. | ||
* @param grid: The game grid. | ||
*/ | ||
struct game { | ||
unsigned short level; | ||
uint8_t tick; | ||
game_score_t score; | ||
game_score_t last_score; | ||
uint_least16_t jewels_removed; | ||
enum game_state status; | ||
enum color color_max; | ||
struct piece current_piece; | ||
struct piece next_piece; | ||
struct grid *grid; | ||
}; | ||
|
||
/** | ||
* game_alloc() - Allocate memory for a new game. | ||
* | ||
* @return The new grid, or NULL if memory allocation fails. | ||
*/ | ||
struct game *game_alloc(void); | ||
|
||
/** | ||
* game_init() - Initialize a game. | ||
* | ||
* @param gm: The game to initialize. | ||
* @param level: The level at which the game must be started. | ||
* @param class: The skill class of the game | ||
*/ | ||
void game_init(struct game *gm, unsigned int level, enum game_class class); | ||
|
||
/** | ||
* game_adjust() - Adjust the game according to the number of removed jewels. | ||
* | ||
* @param gm: The game to inspect and adjust | ||
* @return Were the game settings changed? | ||
*/ | ||
bool game_adjust(struct game *gm); | ||
|
||
/** | ||
* game_cycle_piece() - Cycle the current and next pieces in a given game. | ||
* | ||
* @param gm: The game to modify. | ||
*/ | ||
void game_cycle_piece(struct game *gm); | ||
|
||
/** | ||
* game_free() - Free the memory allocated for a game. | ||
* | ||
* @param gm: The game to free. | ||
*/ | ||
void game_free(struct game *gm); | ||
#endif //TINYCOLS_GAME_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef TINYCOLS_GAME_UTILS_H | ||
#define TINYCOLS_GAME_UTILS_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "game.h" | ||
|
||
/** | ||
* get_level_by_jewels() - Get the level based on the given number of jewels. | ||
* | ||
* @param num: The current number of jewels removed | ||
* @return The level number | ||
*/ | ||
unsigned short get_level_by_jewels(uint_least16_t num); | ||
|
||
/** | ||
* calc_score() - Compute the score based on the number of jewels removed. | ||
* | ||
* @param jewel_count: The number of jewels that were removed. | ||
* @return The computed score. | ||
*/ | ||
game_score_t calc_score(unsigned int jewel_count); | ||
|
||
#endif //TINYCOLS_GAME_UTILS_H |
Oops, something went wrong.