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.
|
EXPORT struct Game * | game_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 Team * | game_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 Team * | game_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...
|
|
Game structures, as well as helper functions.
EXPORT int game_addPlayer |
( |
struct Player * |
player, |
|
|
struct Game * |
game |
|
) |
| |
Adds a player to a game.
- Parameters
-
player | The player to be added. |
game | The 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
-
team | The team to be added. |
game | The 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
-
game | The game to process. |
i | The 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
-
player | The player who wants to put the card down. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
idCard | The 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
-
numberPoints | The 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
-
game | Pointer 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
-
player | The player who has the cards. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
currentCard | Function 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
-
player | The player who has the cards. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
currentCard | Function 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
-
game | The game where to search. |
player | The 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
-
player | The player to be removed. |
game | The 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
-
team | The team to be removed. |
game | The 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
-
game | Game where to update the scores. |
bidWinner | Pointer 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
-
game | The game in which the winning team is to be search. |
- Returns
- Pointer to the winner team on success or NULL on failure.