Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement flee #116

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void battle(Character *player);
* @param A pointer to the player
*/
void random_battle_trigger(Character *player);

Monsters *flee(Monsters *monsters, Character *player);
/**
* @brief Prompts user to choose an attack type, then executes the attack &
* prints the turn summary.
Expand Down
29 changes: 27 additions & 2 deletions src/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void battle(Character *player)
break;

case 5:
// TODO: Implement flee
printf("Flee to implement\n");
monsters = flee(monsters, player);
break;
}

Expand Down Expand Up @@ -161,3 +160,29 @@ Monsters *perform_attack

return update_monsters_list(monsters);
}

Monsters *flee(Monsters *monsters, Character *player)
{
int rdm = rand()%100 +1;
if(rdm<=30){
free(monsters);
clear_screen();
printf("You fled !!\n\n");
press_enter_to_continue();
return NULL;
}else{
printf("You didn't fled !!\n\n");
unsigned short damage_taken = attack(monsters->monster, player, NULL);
printf
(
"%s dealt %d damage to you.\n\n",
monsters->monster->name,
damage_taken
);
restore_mana(player, 10);
press_any_key_to_continue();

return monsters;
}

}