Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- next_state = "intro"
- name = input("What is your name?")
- flags_set = {}
- state_counter = 2
- player_health = 30
- current_weapons = []
- inventory = ["Gummies", "Gummies", "Gummies"]
- def next_state_counter(active):
- global next_state
- global state_counter
- if active == "yes":
- state_counter -= 1
- next_state = choice["action"]
- def determine_flag_state(required_flags, current_flags):
- for key in required_flags:
- if current_flags.get(key, False) != required_flags[key]:
- return False
- return True
- def rpg_game():
- global player_health
- print("A monster approaches")
- while True:
- enemy1 = 25
- bare_hand = random.randrange(8, 15)
- flee_chances = random.randrange(1, 10)
- defend_damange = random.randrange(3, 5)
- enemy_attack = random.randrange(7, 10)
- gummie = 5
- print(name + ': ' + str(player_health) + " hp.\nEnemy: " + str(enemy1) + " hp.")
- print("What will you do?\n"
- "1)Attack\n"
- "2)Defend\n"
- "3)Use Item\n"
- "4)Flee")
- action = input()
- if action == "1":
- print("You attacked.\n"
- "You dealt a total of " + str(bare_hand) + " damage.")
- enemy1 -= bare_hand
- if enemy1 >= 0:
- player_health -= enemy_attack
- print("Enemy dealt " + str(enemy_attack) + " damage.")
- elif enemy1 <= 0:
- print("Enemy was defeated.")
- break
- continue
- elif action == "2":
- print("You pulled out your shield.")
- player_health -= defend_damange
- print("You only took " + str(defend_damange) + " damage.")
- continue
- elif action == "3":
- print("Inventory:\n"
- "What will you use?")
- if player_health >= 30:
- print("It had no effect.")
- elif player_health == min(player_health += gummie, 30):
- player_health += gummie
- if player_health >= 30:
- player_health = 30
- print("You healed!")
- continue
- elif action == "4":
- print(flee_chances)
- if flee_chances <= 5:
- print("You escaped.")
- break
- else:
- print("You couldn't escape")
- print("Enemy dealt " + str(enemy_attack) + " damage.")
- continue
- print("That is not a valid answer.")
- states = {
- "intro": {
- "text": [
- "This is the intro.",
- "I hope I am able to become a programmer one day!"
- ],
- "choices": [
- {"text": "Go to the middle", "action": "middle"},
- {"text": "Go to the end", "action": "end"}
- ],
- },
- "middle": {
- "text": [
- "You have reached the middle.",
- "This is not the end"
- ],
- "jump": "extra"
- },
- "extra": {
- "text": [
- "This is a section you arrived to automatically.",
- "You see a door with the word 'Exit' on top written in big red letters."
- ],
- "choices": [
- {"text": "Open door", "action": "not end", "flag_check": {"light is on": False}},
- {"text": "Open door the door", "action": "end", "flag_check": {"light is on": True}}
- ]
- },
- "not end": {
- "text": [
- "You are close to the end, but it is to dark.",
- "While trying to feel your way out, you find a light switch."
- ],
- "choices": [
- {"text": "Turn on the light", "action": "light is turned on"},
- {"text": "Keep walking", "action": "light was ignored"}
- ]
- },
- "light is turned on": {
- "text": [
- "You turned on the light.",
- "You can see the way out"
- ],
- "jump": "end",
- "flags": {
- "light is on": True
- }
- },
- "light was ignored": {
- "text": [
- "You ignored the light switch.",
- "You're not sure that you will ever reach the end.",
- "After being lost in the darkness for to long you search the walls",
- "hoping to find another light switch.",
- "As you search the wall your hand gets covered in cobwebs,",
- "before the spiders have a chance to come out,",
- "you find another light switch!"
- ],
- "jump": "light is turned on"
- },
- "end": {
- "text": [
- "You have arrived at the end, but is it really over?",
- "That will be for you to decide"
- ],
- "choices": [
- {"text": "Not ready to go.", "action": "middle"},
- {"text": "Pull the plug", "action": None}
- ]
- }
- }
- while next_state != None:
- counter_active = "yes"
- if state_counter <= 0:
- rpg_game()
- state_counter = 2
- current_state = states[next_state]
- print(*current_state["text"], sep="\n")
- if "flags" in current_state:
- flags_set.update(current_state["flags"])
- if "jump" in current_state:
- next_state = current_state["jump"]
- counter_active = "no"
- continue
- enabled_choices = []
- counter = 1
- for choice in current_state["choices"]:
- if "flag_check" not in choice or determine_flag_state(choice["flag_check"], flags_set, ):
- print(str(counter) + ") " + choice["text"])
- counter = counter + 1
- enabled_choices.append(choice)
- while True:
- answer = input()
- length = len(enabled_choices)
- if answer.isdigit():
- position = int(answer)
- if 0 < position <= length:
- break
- print("That is not a valid answer.")
- answer = int(answer) - 1
- choice = enabled_choices[answer]
- next_state_counter(counter_active)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement