Немного "изучить" типа игры в Python


У меня есть еще один маленький текст на основе игры, в этот раз вы исследуете маленький замок. Я хотел сделать этот тип игры на время, и я, наконец, получил, чтобы сделать это!

Вы исследуете маленький замок, выбирая, что залы и комнаты, чтобы пойти в, вы найдете ключи, которые разблокировать двери, которые ведут к более залов и комнат!

import time
import sys
import random

class Player:

    def __init__(self, name):
        self.name = name
        self.key = 0
        self.northemb = 0
        self.rustynail = 0
        pass

p = Player("Player")
#p.key += 1
##############


class Emblem:

    def __init__(self, name):
        self.name = name
        self.Emblem = 0

northemb = Emblem("North Emblem")
southemb = Emblem("South Emblem")







def mid():

    print("You are in the middle of the castle.")
    print("Where do you want to go?")
    time.sleep(3)
    print("1.) North Hall")
    print("2.) East Hall")
    print("3.) South Hall")
    print("4.) West Hall")
    mid = input("")
    if mid == 1:
        north()
    elif mid == 2:
        east()
    elif mid == 3:
        south()
    elif mid == 4:
        west()

def north():
    if northemb.Emblem == 0:
        p.key += 1
        northemb.Emblem += 1
        print("You got a key! I wonder what it unlocks...")
        time.sleep(3)
        print("You are in the north hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) Middle Circle")
        print("2.) East Hall")
        print("3.) South Hall")
        print("4.) West Hall")
        north = input("")
        if north == 1:
            mid()
        elif north == 2:
            east()
        elif north == 3:
            south()
        elif north == 4:
            west()
    else:
        print("You are in the north hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) Middle Circle")
        print("2.) East Hall")
        print("3.) South Hall")
        print("4.) West Hall")
        north = input("")
        if north == 1:
            mid()
        elif north == 2:
            east()
        elif north == 3:
            south()
        elif north == 4:
            west()

def east():
    print("You are in the east hall of the castle.")
    print("Where do you want to go?")
    time.sleep(3)
    print("1.) North Hall")
    print("2.) Middle Hall")
    print("3.) South Hall")
    print("4.) West Hall")
    east = input("")
    if east == 1:
        north()
    elif east == 2:
        mid()
    elif east == 3:
        south()
    elif east == 4:
        west()




def south():
    if southemb.Emblem == 0:
        southemb.Emblem += 1
        p.key += 1
        print("You got a key! I wonder what it unlocks.")
        print("You are in the south hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) North Hall")
        print("2.) Middle Hall")
        print("3.) East hall")
        print("4.) West Hall")
        south = input("")
        if south == 1:
            north()
        elif south == 2:
            mid()
        elif south == 3:
            east()
        elif south == 4:
            west()
    elif southemb.Emblem == 1:
        print("You are in the south hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) North Hall")
        print("2.) Middle Hall")
        print("3.) East hall")
        print("4.) West Hall")
        south = input("")
        if south == 1:
            north()
        elif south == 2:
            mid()
        elif south == 3:
            east()
        elif south == 4:
            west()

def west():
    if p.key == 1:
        print("You see a locked door...")
        print("You have a key!")
        time.sleep(2)
        print("You are in the west hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) North Hall")
        print("2.) Middle Hall")
        print("3.) East Hall")
        print("4.) South Hall")
        print("5.) Unlock Door")
        west = input("")
        if west == 1:
            north()
        elif west == 2:
            mid()
        elif west == 3:
            east()
        elif west == 4:
            south()
        elif west == 5:
            door()

    else:
        print("You see a locked door...")
        time.sleep(2)
        print("You are in the west hall of the castle.")
        print("Where do you want to go?")
        time.sleep(3)
        print("1.) North Hall")
        print("2.) Middle Hall")
        print("3.) East hall")
        print("4.) South hall")
        west = input("")
        if west == 1:
            north()
        elif west == 2:
            mid()
        elif west == 3:
            east()
        elif west == 4:
            south()

def door():
    print("You unlock the door.")
    print("-1 Key")
    p.key -= 1
    time.sleep(3)
    print("You see stairs going down..")
    time.sleep(2)
    print("1.) Go back and keep exploring")
    print("2.) Go down the stairs")
    door = input("")
    if door == 1:
        west()
    elif door == 2:
        floor1()



def floor1():
    if p.key == 0:
        print("You walk down the stairs, and see another locked door.")
        time.sleep(1)
        print("1.) Go back")
        floo1 = input("")
        if floo1 == 1:
            west()
    elif p.key == 1:
        print("You walk down the stairs, and see another locked door.")
        time.sleep(1)
        print("1.) Go back")
        print("2.) Unlock Door")
        floo2 = input("")
        if floo2 == 1:
            west()
        elif floo2 == 2:
            p.key -= 1
            deep()
def deep():
    print("You unlock the door.")
    print("-1 Key")
    time.sleep(2)
    print("You open the door and see more stairs, and walk down them.")
    print("As you walk down the steps, the door swing backs behind you, locking you in. ")
    time.sleep(2)
    print("You see a rusty nail on the stairs, and you think to yourself that it might be of good use at somepoint.")
    p.rustynail += 1
    time.sleep(2)
    print("You see another locked door.")
    time.sleep(2)
    print("You see 3 locked doors, you know you can open one with the rusty nail, but then it would break.")
    time.sleep(3)
    print("1.) Open Red Door")
    print("2.) Open Green Door")
    print("3.) Open Blue Door")
    deep1 = input("")
    if deep1 == 1:
        t1 = random.randint(1,3)
        if t1 == 1:
            door5()
        elif t1 == 2:
            door5()
        elif t1 == 3:
            print("You open the door, and see a goblin armed with a knife, which promptly butchers you.")
            sys.exit()
    elif deep1 == 2:
        t2 = random.randint(1,3)
        if t2 == 1:
            door5()
        if t2 == 2:
            door5()
        elif t2 == 3:
            print("You open the door, and see a goblin armed with a knife, which promptly butchers you.")
            sys.exit()
    elif deep1 == 3:
        t3 = random.randint(1,3)
        if t3 == 1:
            door5()
        elif t3 == 2:
            door5()
        elif t3 == 3:
            print("You open the door, and see a goblin armed with a knife, which promptly butchers you. ")
            sys.exit()

def door5():
    p.rustynail -= 1
    print("-1 Rustynail")
    time.sleep(3)
    print("You see a labryinth in front of you, much like the castle.")
    mid()






mid()


113
4
задан 30 марта 2018 в 08:03 Источник Поделиться
Комментарии
1 ответ

Я думаю, вы должны изменить способ, которым пользователь вводит свое решение. Например, посмотри на эти строки:

print("You are in the middle of the castle.")
print("Where do you want to go?")
time.sleep(3)
print("1.) North Hall")
print("2.) East Hall")
print("3.) South Hall")
print("4.) West Hall")
mid = input("")
if mid == 1:
north()

Первый раз я запустил программу, я сделал это:

You are in the middle of the castle.
Where do you want to go?
1.) North Hall
2.) East Hall
3.) South Hall
4.) West Hall
North Hall
>>>

Я также попытался тоже ввести номер один, но это не сработало. Вам нужно добавить кавычки вокруг такой код:

if mid == '1':
north()
elif mid == '2':
east()
elif mid == '3':
south()
elif mid == '4':
west()

или:

mid = int(input(""))

3
ответ дан 6 января 2019 в 10:01 Источник Поделиться