Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- next_state = "intro"
- flags_set = {}
- state_counter = 2
- player_health = 30
- bare_hand = random.randrange(8, 15)
- flee_chances = random.randrange(1, 6)
- defend_damange = random.randrange(3, 5)
- enemy1 = 25
- 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():
- print("A monster approaches")
- print("What will you do?\n"
- "1)Attack\n"
- "2)Defend\n"
- "3)Flee")
- while True:
- action = input()
- if action == "1":
- print("You attacked.\n"
- "You dealt a total of " + str(bare_hand))
- enemy1 -= bare_hand
- print(enemy1)
- break
- elif action == "2":
- print("You pulled out your shield and took less damage.")
- player_health -= defend_damange
- print(player_health)
- continue
- elif action == "3":
- if flee_chances <= 3:
- print("You escaped.")
- else:
- print("You couldn't escape")
- 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:
- if state_counter <= 0:
- rpg_game()
- state_counter = 2
- else:
- state_counter -= 1
- 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"]
- 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 = choice["action"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement