penguins  1.0.0
interactive.c File Reference

Go to the source code of this file.

Macros

#define ANSI_CSI   "\033["
 
#define ANSI_SGR   "m"
 
#define ANSI_SGR_RESET   "0"
 
#define ANSI_SGR_BOLD   "1"
 
#define ANSI_SGR_FORE_COLOR   "3"
 
#define ANSI_SGR_BACK_COLOR   "4"
 
#define ANSI_SGR_BLACK   "0"
 
#define ANSI_SGR_RED   "1"
 
#define ANSI_SGR_GREEN   "2"
 
#define ANSI_SGR_YELLOW   "3"
 
#define ANSI_SGR_BLUE   "4"
 
#define ANSI_SGR_MAGENTA   "5"
 
#define ANSI_SGR_CYAN   "6"
 
#define ANSI_SGR_WHITE   "7"
 
#define ANSI_RESET   ANSI_CSI ANSI_SGR_RESET ANSI_SGR
 
#define PLAYER_COLORS_COUNT   5
 

Functions

static void clear_screen (void)
 
void print_board (const Game *game)
 
static void display_new_turn_message (Game *game)
 
static void display_error_message (const char *message)
 
void print_player_stats (const Game *game)
 
static bool scan_coords (Coords *out)
 
void print_game_state (const Game *game)
 
static void update_game_state_display (const Game *game)
 
int run_interactive_mode (void)
 
static const char * describe_placement_result (PlacementError result)
 
void interactive_placement (Game *game)
 
void handle_placement_input (Game *game, Coords *selected)
 
static const char * describe_movement_result (MovementError result)
 
void interactive_movement (Game *game)
 
void handle_movement_input (Game *game, Coords *penguin, Coords *target)
 

Variables

static const char *const PLAYER_ANSI_COLORS [PLAYER_COLORS_COUNT]
 
static const char *const PLAYER_COLOR_NAMES [PLAYER_COLORS_COUNT]
 

Macro Definition Documentation

◆ ANSI_CSI

#define ANSI_CSI   "\033["

Definition at line 19 of file interactive.c.

◆ ANSI_SGR

#define ANSI_SGR   "m"

Definition at line 20 of file interactive.c.

◆ ANSI_SGR_RESET

#define ANSI_SGR_RESET   "0"

Definition at line 21 of file interactive.c.

◆ ANSI_SGR_BOLD

#define ANSI_SGR_BOLD   "1"

Definition at line 22 of file interactive.c.

◆ ANSI_SGR_FORE_COLOR

#define ANSI_SGR_FORE_COLOR   "3"

Definition at line 23 of file interactive.c.

◆ ANSI_SGR_BACK_COLOR

#define ANSI_SGR_BACK_COLOR   "4"

Definition at line 24 of file interactive.c.

◆ ANSI_SGR_BLACK

#define ANSI_SGR_BLACK   "0"

Definition at line 25 of file interactive.c.

◆ ANSI_SGR_RED

#define ANSI_SGR_RED   "1"

Definition at line 26 of file interactive.c.

◆ ANSI_SGR_GREEN

#define ANSI_SGR_GREEN   "2"

Definition at line 27 of file interactive.c.

◆ ANSI_SGR_YELLOW

#define ANSI_SGR_YELLOW   "3"

Definition at line 28 of file interactive.c.

◆ ANSI_SGR_BLUE

#define ANSI_SGR_BLUE   "4"

Definition at line 29 of file interactive.c.

◆ ANSI_SGR_MAGENTA

#define ANSI_SGR_MAGENTA   "5"

Definition at line 30 of file interactive.c.

◆ ANSI_SGR_CYAN

#define ANSI_SGR_CYAN   "6"

Definition at line 31 of file interactive.c.

◆ ANSI_SGR_WHITE

#define ANSI_SGR_WHITE   "7"

Definition at line 32 of file interactive.c.

◆ ANSI_RESET

#define ANSI_RESET   ANSI_CSI ANSI_SGR_RESET ANSI_SGR

Definition at line 34 of file interactive.c.

◆ PLAYER_COLORS_COUNT

#define PLAYER_COLORS_COUNT   5

Definition at line 36 of file interactive.c.

Function Documentation

◆ clear_screen()

static void clear_screen ( void  )
static

Definition at line 44 of file interactive.c.

Referenced by run_interactive_mode(), and update_game_state_display().

◆ print_board()

void print_board ( const Game game)

Definition at line 53 of file interactive.c.

Referenced by print_game_state().

◆ display_new_turn_message()

static void display_new_turn_message ( Game game)
static

Definition at line 88 of file interactive.c.

Referenced by interactive_movement(), and interactive_placement().

◆ display_error_message()

static void display_error_message ( const char *  message)
static

Definition at line 98 of file interactive.c.

Referenced by handle_movement_input(), and handle_placement_input().

◆ print_player_stats()

void print_player_stats ( const Game game)

Definition at line 102 of file interactive.c.

Referenced by print_game_state().

◆ scan_coords()

static bool scan_coords ( Coords out)
static

Definition at line 116 of file interactive.c.

Referenced by handle_movement_input(), and handle_placement_input().

◆ print_game_state()

void print_game_state ( const Game game)

Definition at line 122 of file interactive.c.

Referenced by run_autonomous_mode(), and update_game_state_display().

◆ update_game_state_display()

static void update_game_state_display ( const Game game)
static

◆ run_interactive_mode()

int run_interactive_mode ( void  )

Definition at line 133 of file interactive.c.

Referenced by main().

◆ describe_placement_result()

static const char* describe_placement_result ( PlacementError  result)
static

Definition at line 207 of file interactive.c.

Referenced by handle_placement_input().

◆ interactive_placement()

void interactive_placement ( Game game)

Definition at line 220 of file interactive.c.

Referenced by run_interactive_mode().

◆ handle_placement_input()

void handle_placement_input ( Game game,
Coords selected 
)

Definition at line 234 of file interactive.c.

Referenced by interactive_placement().

◆ describe_movement_result()

static const char* describe_movement_result ( MovementError  result)
static

Definition at line 250 of file interactive.c.

Referenced by handle_movement_input().

◆ interactive_movement()

void interactive_movement ( Game game)

Definition at line 267 of file interactive.c.

Referenced by run_interactive_mode().

◆ handle_movement_input()

void handle_movement_input ( Game game,
Coords penguin,
Coords target 
)

Definition at line 282 of file interactive.c.

Referenced by interactive_movement().

Variable Documentation

◆ PLAYER_ANSI_COLORS

const char* const PLAYER_ANSI_COLORS[PLAYER_COLORS_COUNT]
static
Initial value:
= {
}
#define ANSI_SGR_RED
Definition: interactive.c:26
#define ANSI_SGR_BLUE
Definition: interactive.c:29
#define ANSI_SGR_GREEN
Definition: interactive.c:27
#define ANSI_SGR_MAGENTA
Definition: interactive.c:30
#define ANSI_SGR_YELLOW
Definition: interactive.c:28

Definition at line 37 of file interactive.c.

Referenced by display_new_turn_message(), print_board(), print_player_stats(), and run_interactive_mode().

◆ PLAYER_COLOR_NAMES

const char* const PLAYER_COLOR_NAMES[PLAYER_COLORS_COUNT]
static
Initial value:
= {
"red", "green", "yellow", "blue", "magenta"
}

Definition at line 40 of file interactive.c.

Referenced by run_interactive_mode().