Haunted-Mirror
The game that is 2017-18's project for UE projet Techno
Macros | Typedefs | Enumerations
game.h File Reference

This files describes the programming interface of a puzzle game, named 'Haunted Mirror'. More...

#include <stdbool.h>

Go to the source code of this file.

Macros

#define NB_POSSIBLE_FILLINGS   6
 
#define NB_DIR   4
 

Typedefs

typedef enum content_e content
 possible contents of a square on the board. MIRROR stands for a mirror at +45 degrees (/), ANTIMIRROR at -45 degrees (\) (mnemonic is slash and antislash).
 
typedef enum direction_e direction
 the fourth cardinal directions
 
typedef struct game_s * game
 The structure pointer that stores the game.
 
typedef const struct game_s * cgame
 The structure constant pointer that stores the game That means that it is not possible to modify the game using this pointer. See also: http://www.geeksforgeeks.org/const-qualifier-in-c/ See also this more technical discussion: http://stackoverflow.com/questions/8504411/typedef-pointer-const-weirdness.
 

Enumerations

enum  content_e {
  EMPTY, MIRROR, ANTIMIRROR, VAMPIRE,
  GHOST, ZOMBIE
}
 possible contents of a square on the board. MIRROR stands for a mirror at +45 degrees (/), ANTIMIRROR at -45 degrees (\) (mnemonic is slash and antislash).
 
enum  direction_e { N, S, E, W }
 the fourth cardinal directions
 

Functions

Version 1 of Game API
game new_game ()
 creates an empty game with all squares set to empty, all labels and the number of required monsters set to 0. More...
 
game setup_new_game (int *labels[NB_DIR], content *board, int required_nb_ghosts, int required_nb_vampires, int required_nb_zombies)
 creates a game from a board description. It uses a given board possibly with its mirrors, and a list of labels. More...
 
void add_mirror (game game, int dir, int col, int line)
 adds a mirror on the game board More...
 
void set_required_nb_seen (game game, direction side, int pos, int value)
 sets the label of a game More...
 
void set_required_nb_monsters (game game, content monster, int value)
 modifies the aimed number of a given monster on the board More...
 
game copy_game (cgame g_src)
 Clone the game g_src. More...
 
void delete_game (game g)
 Destroy the game and free allocated memory. More...
 
int required_nb_seen (cgame game, direction side, int pos)
 return the label on the side of the board More...
 
content get_content (cgame game, int col, int line)
 get the content of a square in the board More...
 
int required_nb_monsters (cgame game, content monster)
 indicates the aimed number of a given monster on the board More...
 
bool is_game_over (cgame g)
 Test if the game is over (that is the grid is filled according to the requirements). More...
 
void restart_game (game g)
 Restart a game by cleaning monsters from the board.
 
bool add_monster (game game, content monster, int col, int line)
 adds a monster on the game board. Can also be used to remove any monster by adding EMPTY. This function does not have effect on mirrors so it can be used safely in the course of the game. More...
 
int current_nb_seen (cgame game, direction side, int pos)
 says how many monsters can be seen on the current game board More...
 
int current_nb_monsters (cgame game, content monster)
 counts the current number of monsters of a given type More...
 

Detailed Description

This files describes the programming interface of a puzzle game, named 'Haunted Mirror'.

Function Documentation

void add_mirror ( game  game,
int  dir,
int  col,
int  line 
)

adds a mirror on the game board

Parameters
gamethe game board where to add the mirror
dirthe direction on which to add the mirror: 0 for +45 degrees (/), 1 for -45 degrees (\)
colwhich column to insert the mirror on (0<=col<4)
linewhich line to insert the mirror on (0<=line<4)
bool add_monster ( game  game,
content  monster,
int  col,
int  line 
)

adds a monster on the game board. Can also be used to remove any monster by adding EMPTY. This function does not have effect on mirrors so it can be used safely in the course of the game.

Parameters
gamethe game board where to add the monster
monsterthe type of monster to add
colthe column where to insert the monster
lineand the line where to insert the monster
Returns
false if the monster was not placed since the square was occupied by a mirror.
game copy_game ( cgame  g_src)

Clone the game g_src.

Parameters
g_srcthe game to clone
Returns
the clone of g_src
int current_nb_monsters ( cgame  game,
content  monster 
)

counts the current number of monsters of a given type

Parameters
gamethe game board
monsterthe type of monster
Returns
the total number of monsters of the given type on the board.
int current_nb_seen ( cgame  game,
direction  side,
int  pos 
)

says how many monsters can be seen on the current game board

Parameters
gamethe game board to look at
sidethe side of the board we consider (N, S, W, or E)
posthe coordinate on that side (from S to N or from W to E)
Returns
the number of monsters that can be seen through all the mirrors from a given side at position x
void delete_game ( game  g)

Destroy the game and free allocated memory.

Parameters
gthe game to destroy
content get_content ( cgame  game,
int  col,
int  line 
)

get the content of a square in the board

Parameters
gamethe game we consider
colthe column of the square
linethe line of the square
Returns
the content of the square
bool is_game_over ( cgame  g)

Test if the game is over (that is the grid is filled according to the requirements).

Returns
true if all the constraints are satisfied
game new_game ( )

creates an empty game with all squares set to empty, all labels and the number of required monsters set to 0.

Returns
the created game
int required_nb_monsters ( cgame  game,
content  monster 
)

indicates the aimed number of a given monster on the board

Parameters
gamethe game that you want to collect the information about
monsterthe type of monster (should be GHOST, VAMPIRE or ZOMBIE)
Returns
the number of monsters of that type that should be placed on the game.
int required_nb_seen ( cgame  game,
direction  side,
int  pos 
)

return the label on the side of the board

Parameters
gamethe game we consider
sidethe side of the board we want the label from
posthe position of the label you want (from S to N or from W to E)
void set_required_nb_monsters ( game  game,
content  monster,
int  value 
)

modifies the aimed number of a given monster on the board

Parameters
gamethe game that you want to modify the information about
monsterthe type of monster (should be GHOST, VAMPIRE or ZOMBIE)
valuethe value you want to set to the parameter.
void set_required_nb_seen ( game  game,
direction  side,
int  pos,
int  value 
)

sets the label of a game

Parameters
gamethe game to modify
sidethe side of the game where the label should be modified
posthe position that the label should be modified (from S to N or from W to E)
valuethe new value to give to the label
game setup_new_game ( int *  labels[NB_DIR],
content board,
int  required_nb_ghosts,
int  required_nb_vampires,
int  required_nb_zombies 
)

creates a game from a board description. It uses a given board possibly with its mirrors, and a list of labels.

Parameters
labelsan array of four pointers towards array of labels (namely, labels[N], labels[S], labels[E], labels[W]). The labels are given according to increasing coordinate value (from S to N or from W to E)
boardan array of all the board squares, stored sequentially line by line starting from coordinate (0,0)
required_nb_ghoststhe number of ghosts required in the game.
required_nb_vampiresthe number of vampires required in the game.
required_nb_zombiesthe number of zombies required in the game.
Returns
the created game