CruceGame  v0.4.0
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Classes | Functions
game.h File Reference

Game structures, as well as helper functions. More...

#include "platform.h"
#include "constants.h"
#include "team.h"
#include "deck.h"
#include "round.h"

Go to the source code of this file.

Classes

struct  Game
 Game structure. More...
 

Functions

EXPORT struct Gamegame_createGame (const int numberPoints)
 Allocates memory for and initializes a game. More...
 
EXPORT int game_deleteGame (struct Game **game)
 Frees the memory of a game and makes the pointer NULL. More...
 
EXPORT int game_addPlayer (struct Player *player, struct Game *game)
 Adds a player to a game. More...
 
EXPORT int game_removePlayer (const struct Player *player, struct Game *game)
 Removes a player from a game. More...
 
EXPORT int game_addTeam (struct Team *team, struct Game *game)
 Adds a team to a game. More...
 
EXPORT int game_removeTeam (const struct Team *team, struct Game *game)
 Removes a team from a game. More...
 
EXPORT struct Teamgame_winningTeam (struct Game *game)
 Searches the winning team of a game. More...
 
EXPORT int game_checkCard (struct Player *player, const struct Game *game, struct Hand *hand, const int idCard)
 Function checks if the player can put a card down. More...
 
EXPORT int game_findNextAllowedCard (struct Player *player, struct Game *game, struct Hand *hand, int currentCard)
 Function to find the next allowed card after currentCard. Uses game_checkCard to check if a card is allowed. More...
 
EXPORT int game_findPreviousAllowedCard (struct Player *player, struct Game *game, struct Hand *hand, int currentCard)
 Function to find the previous allowed card before currentCard. Uses game_checkCard to check if a card is allowed. More...
 
EXPORT struct Teamgame_findTeam (const struct Game *game, struct Player *player)
 Function to find the team in which a player belongs. More...
 
EXPORT int game_updateScore (const struct Game *game, struct Player *bidWinner)
 Function to update the score of teams and players after a round. More...
 
EXPORT int game_arrangePlayersRound (struct Game *game, const int i)
 Function to add a round to a game and to arrange players into it, according to game rules. More...
 

Detailed Description

Game structures, as well as helper functions.

Function Documentation

EXPORT int game_addPlayer ( struct Player player,
struct Game game 
)

Adds a player to a game.

Parameters
playerThe player to be added.
gameThe game where the player is to be added.
Returns
NO_ERROR on success, other value on failure.
EXPORT int game_addTeam ( struct Team team,
struct Game game 
)

Adds a team to a game.

Parameters
teamThe team to be added.
gameThe game where the team is to be added to.
Returns
NO_ERROR on success, other value on failure.
EXPORT int game_arrangePlayersRound ( struct Game game,
const int  i 
)

Function to add a round to a game and to arrange players into it, according to game rules.

Parameters
gameThe game to process.
iThe index of the first player in that round.
Returns
NO_ERROR or 0 on success, other value on failure.
EXPORT int game_checkCard ( struct Player player,
const struct Game game,
struct Hand hand,
const int  idCard 
)

Function checks if the player can put a card down.

Parameters
playerThe player who wants to put the card down.
gameThe game where the player is located.
handThe hand in which should put the card.
idCardThe id of the card.
Returns
1 if the player may to put the card down 0 if the player can't to put the card down other value on failure.
EXPORT struct Game* game_createGame ( const int  numberPoints)

Allocates memory for and initializes a game.

Parameters
numberPointsThe number of points required for winning the game.
Returns
Pointer to the new game on success or NULL on failure.
EXPORT int game_deleteGame ( struct Game **  game)

Frees the memory of a game and makes the pointer NULL.

Parameters
gamePointer to the game to be deleted.
Returns
NO_ERROR on success, other value on failure.
EXPORT int game_findNextAllowedCard ( struct Player player,
struct Game game,
struct Hand hand,
int  currentCard 
)

Function to find the next allowed card after currentCard. Uses game_checkCard to check if a card is allowed.

Parameters
playerThe player who has the cards.
gameThe game where the player is located.
handThe hand in which should put the card.
currentCardFunction finds the first allowed card after currentCard.
Returns
The next allowed card's id on success (value between 0 and MAX_CARDS -1). Negative value on failure.
EXPORT int game_findPreviousAllowedCard ( struct Player player,
struct Game game,
struct Hand hand,
int  currentCard 
)

Function to find the previous allowed card before currentCard. Uses game_checkCard to check if a card is allowed.

Parameters
playerThe player who has the cards.
gameThe game where the player is located.
handThe hand in which should put the card.
currentCardFunction finds the last allowed card before currentCard.
Returns
The next allowed card's id on success (value between 0 and MAX_CARDS -1). Negative value on failure.
EXPORT struct Team* game_findTeam ( const struct Game game,
struct Player player 
)

Function to find the team in which a player belongs.

Parameters
gameThe game where to search.
playerThe player to find.
Returns
Pointer to the required team on success, NULL on failure.
EXPORT int game_removePlayer ( const struct Player player,
struct Game game 
)

Removes a player from a game.

Parameters
playerThe player to be removed.
gameThe game from where the player is to be removed.
Returns
NO_ERROR on success, other value on failure.
EXPORT int game_removeTeam ( const struct Team team,
struct Game game 
)

Removes a team from a game.

Parameters
teamThe team to be removed.
gameThe game from where the team is to be removed.
Returns
NO_ERROR on success, error code otherwise.
EXPORT int game_updateScore ( const struct Game game,
struct Player bidWinner 
)

Function to update the score of teams and players after a round.

Parameters
gameGame where to update the scores.
bidWinnerPointer to the player that won the bid in the last round.
Returns
NO_ERROR or 0 on success, other value on failure.
EXPORT struct Team* game_winningTeam ( struct Game game)

Searches the winning team of a game.

Parameters
gameThe game in which the winning team is to be search.
Returns
Pointer to the winner team on success or NULL on failure.