<jupyter_start><jupyter_text>game> API details for the game module<jupyter_code>from tcai_mages.core import Mage, Ability, Demon
#hide
from nbdev.showdoc import *
#export
def init_player():
    "Initializes a player, `Mage`, with the user's speciality and name"
    print(f"Hi there, what is your speciality? {Ability.ability_types}")
    while True:
        ability_types = input()
        if ability_types in Ability.ability_types:
            break
        else:
            print(f"Invalid ability choice, What is your Speciality? {Ability.ability_types}")
    name = input("What is your name, mage?")
    return Mage(name, 100, Ability(10, ability_types))
#export
COMBAT_OPTIONS = ["attack"]

def combat(player, boss):
    "Performs a combat with a player, `Mage`, which as generated with the `init_player` function, and a `Demon`"
    print("Combat has begun!")
    while True:
        print(player)
        print(boss)
        print(f"What do you want to do? {COMBAT_OPTIONS}")
        player_move = input()
        if player_move not in COMBAT_OPTIONS:
            print("Not an option, you lose a move!")
        else:
            if player_move == "attack":
                player.attack(boss)
                if boss.current_health <= 0:
                    return player
        boss.attack(player)
        if player.current_health <= 0:
            return boss
#export
def game_loop(player, n = 5):
    for i in range(1, n + 1):
        boss = Demon("Gary", 50 * i)
        print(f"A demon name {boss.name}) appeared! They seem to have a chip on their shoulder and want to fight you.")
        winner = combat(player, boss)
        if winner == player:
            print(f"Well done, you beat {boss.name} and leveled up to {i + 1}! ")
            player.level_up()
        else:
            print(f"You have fallen to {boss.name}. Game Over!")
            break
    if i == n:
        print(f"Congratulations, you've defeated all the bosses and won the game. {player.name}'s name shall go down in history!")
player = init_player()
game_loop(player, 1)
from nbdev.export import notebook2script; notebook2script()<jupyter_output>Converted 00_core.ipynb.
Converted 01_game.ipynb.
Converted 02_tutorial.ipynb.
Converted index.ipynb.
{'fraction_non_alphanumeric': 0.10084783578759482, 'fraction_numerical': 0.009817045961624275, 'mean_word_length': 2.675409836065574, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '551187', 'license': 'Apache-2.0', 'n_tokens_mistral': 720, 'n_tokens_neox': 692, 'n_words': 229, 'path': '01_game.ipynb', 'repo_name': 'CailleauThierry/tcai_mages', 'size': '2241'}