def fight_round(): """ Compute fight round action between hero player and monster put it into globals fight_state """ state = globals.fight_state state["player_1"]["instance"].mode = state["player_1"]["next_mode"] if state["player_1"]["next_mode"] == "attack": round_step("player_1", "player_2") if state["player_2"]["current_life"] <= 0: globals.fight_state["round"] = -1 globals.add_log( f"{state['player_1']['instance'].name} kill {state['player_2']['instance'].name} !" ) return -1 if isinstance(state['player_2']['instance'], Hero) else 1 state["player_2"]["instance"].mode = state["player_2"]["next_mode"] if state["player_2"]["next_mode"] == "attack": round_step("player_2", "player_1") if state["player_1"]["current_life"] <= 0: globals.fight_state["round"] = -1 globals.add_log( f"{state['player_2']['instance'].name} kill {state['player_1']['instance'].name} !" ) return -1 if isinstance(state['player_1']['instance'], Hero) else 1 return 0
def round_step(_attacker, _target): """ Compute _attacker action against _target and put it into globals fight_state """ state = globals.fight_state state[_attacker]["damage"] = state[_attacker]["instance"].give_damage() state[_target]["taken"] = state[_target]["instance"].take_damage( state[_attacker]["damage"]) state[_target]["current_life"] -= state[_target]["taken"] globals.add_log( f"{state[_attacker]['instance'].name} make {state[_target]['taken']} damages to {state[_target]['instance'].name}" )
def quest1(_value): """ Quest 1 steps computing according to user choice """ globals.user current_step = globals.user.selected_hero.current_step if current_step == 1: # Change sex step globals.user.selected_hero.sex = (_value == "female") next_step(2) globals.add_log(f"Quest 1 (step 1) : user sex is now {_value}") return "next_step" elif current_step == 2: # Filler step if _value == "stay": next_step(1, 2) globals.add_log(f"Quest 1 (step 2) : hero chooses to {_value}") return "next_quest" return "game_over"
def quest3(_value): """ Quest 3 steps computing according to user choice """ globals.user current_step = globals.user.selected_hero.current_step if current_step == 1: if _value == "start": next_step(2) fight_init() globals.add_log(f"Quest 3 (step 1) : hero start fighting") return "start_fight" elif current_step == 2: status = fight_loop(_value) if status == -1: globals.add_log(f"Quest 3 (step 2) : hero is dead") elif status == 1: next_step(3) globals.add_log(f"Quest 3 (step 2) : hero won fight") return "next_step" else: globals.add_log(f"Quest 3 (step 2) : fight is not over") return "fight" elif current_step == 3: # if _value == "garden": # next_step(1, 4) # return f"Action (1, {current_step}) : hero now {_value}" return "end_game" return "game_over"
def quest2(_value): """ Quest 2 steps computing according to user choice """ globals.user current_step = globals.user.selected_hero.current_step if current_step == 1: # Filler step if _value == "stay": next_step(2) globals.add_log(f"Quest 2 (step 1) : hero chooses to {_value}") return "next_step" elif current_step == 2: # Is a PNJ if _value == "no": next_step(3) globals.add_log(f"Quest 2 (step 2) : hero says {_value}") return "next_step" elif current_step == 3: # Is a rich one if _value == "no": next_step(4) globals.add_log(f"Quest 2 (step 3) : hero says {_value}") return "next_step" elif current_step == 4: # Offer stick if _value == "yes": next_step(1, 3) globals.user.selected_hero.weapon = "Stick" globals.add_log( f"Quest 2 (step 4) : hero says {_value} to the 'Stick'") return "next_quest" return "game_over"