4
\$\begingroup\$

I have another little text based game, this time, you're exploring a little castle. I have wanted to do this type of game for a while, and I finally got to do it!

You are exploring a little castle, choosing which halls and rooms to go into, you find keys as well, which unlock doors, which lead to more halls and rooms!

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()
\$\endgroup\$
  • 1
    \$\begingroup\$ Again, as with your previous question, I suggest you to add some more information about the game into your post. That way reviewers know what to expect from their initial game session and whether you've met that expectations. \$\endgroup\$ – Zeta Mar 30 '18 at 20:45
  • \$\begingroup\$ Alright, done. @Zeta \$\endgroup\$ – Colea Mar 30 '18 at 20:47
  • \$\begingroup\$ You're using Python 3.x right? \$\endgroup\$ – Phrancis Mar 30 '18 at 21:05
  • 1
    \$\begingroup\$ Given Jerry Cui answer's revealed a basic failure in functioning correctly, I think this question should be closed as Code not implemented or not working as intended. \$\endgroup\$ – Graham Jan 6 at 23:07
3
\$\begingroup\$

I think you should change the way a user inputs their decision. For example, look at these lines:

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()

The first time I ran the program, I did this:

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
>>> 

I also tried entering the number one too, but it didn't work. You need to add quotes around the code like this:

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

or:

mid = int(input(""))
\$\endgroup\$
  • 3
    \$\begingroup\$ The second method is probably better, but the OP will probably want to go more generic; for CLI programs, it's important to have input validation so the program doesn't crash when an non-number input or a number out of range is input. However, given that you have uncovered such a major bug in the program from a basic test, I think the question needs to be closed as Code not implemented or not working as intended. \$\endgroup\$ – Graham Jan 6 at 23:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.