Battles ~ CLI Integration Design Document - uchicago-cs/chiventure GitHub Wiki
This design document will detail how we will like to integrate the CLI with NPC battles. We have already created a design document with how we would like to run the battles themselves, but now we will need the CLI team to help us integrate features that will allow players to choose their own moves or items while battling an NPC. There already exists code that will take in an action from the command line and finds the operation and action associated with it in the CLI cmd.h file, though the majority of the CLI code at the moment seems to focus on parts of the game not associated with NPC battles. To avoid an overwhelmingly long list of battle actions being mixed in with the non-battle actions, it may be helpful to create a battle-specific CLI module or function that will only be used during battles.
Structs and Functions we will like to add:
/* Battle specific command list (see cli/cmdlist.h for further documentation) */
command_list_t *new_battle_command_list(char* command)
{
command_list_t *new = malloc(sizeof(command_list_t));
if (command == NULL)
{
new->command = NULL;
} else {
new->command = strdup(command);
}
new->next = NULL;
return new;
}
/* Askes a player to input a move (for more general information, see cli/operations.h
*
* Parameters:
* - combatant: the player
* - tokens: parsed input string (validified)
* - ctx: pointer to a battle context struct
*
* Returns:
* - informs the player of the move chosen, or if it is not valid.
char *choose_move(battle_player_t *combatant, char *tokens[TOKEN_LIST_SIZE], battle_ctx_t * ctx);
/* Askes a player to chose an item(for more general information, see cli/operations.h
*
* Parameters:
* - combatant: the player
* - tokens: parsed input string (validified)
* - ctx: pointer to a battle context struct
*
* Returns:
* - informs the player of the item chosen, or if it is not valid.
char *choose_weapon(battle_player_t *combatant, char *tokens[TOKEN_LIST_SIZE], battle_ctx_t * ctx);
/* Informs the player that the battle has ended
*
* Parameters:
* - ctx: pointer to a battle context struct (has battle state in it)
*
* Returns:
* - informs the player whether they lost or won, and what they gain/lose from the battle
char *battle_end_line(battle_ctx_t * ctx);
Example: Say the player would like to use the move “kick” and the item “super strong boots”. Then, the CLI Integration will be as followed:
>> Please select your item:
>> super strong boots_
>> Super strong boots have been chosen! Your attack goes up by 5!
>> Please select your move:
>> kick_
>> Kick has been chosen! You dealt 3 damage!
>> You have defeated the enemy! You have gained 30 EXP!