Init commit
This commit is contained in:
commit
83e6c9e1f0
41 changed files with 1455 additions and 0 deletions
54
code-samples/frogger/inc/defines.h
Normal file
54
code-samples/frogger/inc/defines.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef DEFINES_H
|
||||
#define DEFINES_H
|
||||
|
||||
#define WIN_INIT(time) {\
|
||||
initscr();\
|
||||
noecho();\
|
||||
curs_set(0);\
|
||||
keypad(stdscr, TRUE);\
|
||||
timeout(time);\
|
||||
}
|
||||
|
||||
#define GET_USER_INPUT getch()
|
||||
|
||||
#define PRINT_FROG(x, y) mvprintw(BOARDS_BEGIN + (y), BOARDS_BEGIN + (x), "@")
|
||||
#define MVPRINTW(y, x, ...) mvprintw(BOARDS_BEGIN + (y), BOARDS_BEGIN + (x), __VA_ARGS__)
|
||||
#define MVADDCH(y, x, c) mvaddch(BOARDS_BEGIN + (y), BOARDS_BEGIN + (x), c)
|
||||
#define CLEAR_BACKPOS(y, x) mvaddch(BOARDS_BEGIN + (y), BOARDS_BEGIN + (x), ' ')
|
||||
|
||||
#define YOU_WON "tests/game_progress/you_won.txt"
|
||||
#define YOU_LOSE "tests/game_progress/you_lose.txt"
|
||||
#define LEVEL_DIR "tests/levels/level_"
|
||||
#define INTRO_MESSAGE "Press ENTER to start!"
|
||||
#define INTRO_MESSAGE_LEN 21
|
||||
#define LEVEL_CNT 5
|
||||
#define LEVELNAME_MAX 25
|
||||
|
||||
#define MAX_WIN_COUNT 10
|
||||
|
||||
#define ROWS_MAP 21
|
||||
#define COLS_MAP 90
|
||||
|
||||
#define BOARDS_BEGIN 2
|
||||
|
||||
#define FROGSTART_X (BOARD_M / 2)
|
||||
#define FROGSTART_Y (BOARD_N)
|
||||
#define INITIAL_TIMEOUT 150
|
||||
|
||||
#define BOARD_N (ROWS_MAP + MAP_PADDING * 2)
|
||||
#define BOARD_M 30
|
||||
#define HUD_WIDTH 12
|
||||
#define MAP_PADDING 3
|
||||
|
||||
#define BANNER_N 10
|
||||
#define BANNER_M 100
|
||||
|
||||
#define SUCCESS 0
|
||||
#define ERROR 1
|
||||
|
||||
#define NO_INPUT -1
|
||||
|
||||
#define ESCAPE 27
|
||||
#define ENTER_KEY 10
|
||||
|
||||
#endif
|
||||
20
code-samples/frogger/inc/frog_backend.h
Normal file
20
code-samples/frogger/inc/frog_backend.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef FROGGER_BACKEND_H
|
||||
#define FROGGER_BACKEND_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "defines.h"
|
||||
#include "objects.h"
|
||||
#include "string.h"
|
||||
|
||||
int lvlproc(board_t *map, game_stats_t *stats);
|
||||
void add_proggress(board_t *map);
|
||||
void stats_init(game_stats_t *stats);
|
||||
void frogpos_init(player_pos *frog);
|
||||
void fill_finish(char *finish_line);
|
||||
void shift_map(board_t *map);
|
||||
|
||||
bool check_collide(player_pos *frog, board_t *map);
|
||||
bool check_finish_state(player_pos *frog, board_t *map);
|
||||
bool check_level_compl(board_t *map);
|
||||
|
||||
#endif
|
||||
17
code-samples/frogger/inc/frog_frontend.h
Normal file
17
code-samples/frogger/inc/frog_frontend.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef FROGGER_FRONTEND_H
|
||||
#define FROGGER_FRONTEND_H
|
||||
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
#include "objects.h"
|
||||
|
||||
void print_overlay(void);
|
||||
void print_rectangle(int top_y, int bottom_y, int left_x, int right_x);
|
||||
void print_stats(game_stats_t *stats);
|
||||
void print_board(board_t *game, player_pos *frog);
|
||||
void print_cars(board_t *game);
|
||||
void print_finished(board_t *game);
|
||||
void print_banner(game_stats_t *stats);
|
||||
int read_banner(game_stats_t *stats, banner_t *banner);
|
||||
|
||||
#endif
|
||||
11
code-samples/frogger/inc/frogger.h
Normal file
11
code-samples/frogger/inc/frogger.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef FROGGER_H
|
||||
#define FROGGER_H
|
||||
|
||||
#include <locale.h>
|
||||
#include "fsm.h"
|
||||
#include "frog_backend.h"
|
||||
#include "frog_frontend.h"
|
||||
|
||||
void game_loop();
|
||||
|
||||
#endif
|
||||
35
code-samples/frogger/inc/fsm.h
Normal file
35
code-samples/frogger/inc/fsm.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef FSM_H
|
||||
#define FSM_H
|
||||
|
||||
#include "defines.h"
|
||||
#include "objects.h"
|
||||
#include "frog_backend.h"
|
||||
#include "frog_frontend.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
START = 0,
|
||||
SPAWN,
|
||||
MOVING,
|
||||
SHIFTING,
|
||||
REACH,
|
||||
COLLIDE,
|
||||
GAMEOVER,
|
||||
EXIT_STATE
|
||||
} frog_state;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MOVE_UP = 0,
|
||||
MOVE_DOWN,
|
||||
MOVE_RIGHT,
|
||||
MOVE_LEFT,
|
||||
ESCAPE_BTN,
|
||||
ENTER_BTN,
|
||||
NOSIG
|
||||
} signals;
|
||||
|
||||
signals get_signal(int user_input);
|
||||
void sigact(signals sig, frog_state *state, game_stats_t *stats, board_t *map, player_pos *frog_pos);
|
||||
|
||||
#endif
|
||||
33
code-samples/frogger/inc/objects.h
Normal file
33
code-samples/frogger/inc/objects.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef OBJECTS_H
|
||||
#define OBJECTS_H
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "defines.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} player_pos;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char finish[BOARD_M + 2];
|
||||
char ways[ROWS_MAP + 2][COLS_MAP + 2];
|
||||
} board_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int score;
|
||||
int level;
|
||||
int speed;
|
||||
int lives;
|
||||
int won;
|
||||
} game_stats_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char matrix[BANNER_N + 1][BANNER_M + 1];
|
||||
} banner_t;
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue