I need help with Python 3.5.2 Code


#1

Hi so I just started to learn python 3.5.2 about 4 hours ago and I’m trying to make a game similar to Zork (the text based game) but I’m having some trouble with a part of my code.

I’m not sure what to do so please help me out :P

##Actual Code
import random import time

def displayIntro():
print('You\'re in a land full of magic and mystery, ') print('Some say dragons live here and reside in caves.') print('In front of you, you see two caves. ') print('In one cave, there is a friendly dragon who ') print('has been alone for a thousand years and really just wants') print('to talk with someone. Maybe there\'s some treasure to be had!') print() print('In the other cave, the dragon is mean, nasty and terrible. ') print('He\'s not misunderstood, he\'s just a mean guy and will eat you.') print() print('There seems to be another cave, but only one you\'ve heard in legends')

def chooseCave():
cave = '' while cave != '1' and cave != '2' and cave !='3': print('Which cave will you go into? (1, 2 or 3)') cave = input()

return cave

def checkCave(chosenCave):
print('You approach the cave...')
time.sleep(2)
print('It\'s pitch black.. you can barely see a thing')
time.sleep(3)
print('A massive dragon surges from the shadows and confronts you, nose to nose.')
print()
time.sleep(2)

friendlyCave = random.randint(1,2)
emptyCave = 3


if int(chosenCave) == friendlyCave:
    print('He then asks for your name and where you come from')
    name = input()
    time.sleep(1)
    print('\"I haven\'t seen a living, breathing human for many years...\"')
    print()
    time.sleep(3)
    print('\"Come inside and tell me about your adventures, ' + name + '.\"')
if int(chosenCave) == emptyCave:
    print('\"BLURURURG\"')
    print('The Dragon explodes in front of you! Turns out it was just a balloon')
    print('You aqquire the long forgotten jewels and riches so you head out of the cave')
    time.sleep(4)
    print('there are 2 paths once you emerge from the cave...')
    print('One leads east, the other, west. Which one will you choose?')
    def choosePath():
        path = ''
        while path != 'West' or 'west' and path != 'East' or 'east':
            print('Pick a path (east or west)')
            path = input()

        return path
    def checkPath (chosenPath):
        print('You head down the ' + path + 'trail.')
        time.sleep(4)
        print('It\'s very steep and should you falter or sway, leads to an unforgiving fall.')
        time.sleep(2)
        print('The trail levels out into a clearing.')

        rightPath = str('East' or 'east')

        if path == rightPath:
            print('GOOD JOB')
        else:
            print('UR DEAD m8')

else:
    print('You see steam rise from the corners of it\'s mouth... ')
    time.sleep(1)
    print('The dragon opens it\'s mouth to reveal a glowing orb in the ')
    print('back of it\'s mouth. A warm gust of air hits your face.')
    time.sleep(4)
    print('The dragon incinerates the entire room, leaving no evidence ')
    print('that you ever existed.')

playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y' or playAgain == 'Yes':

displayIntro()

caveNumber = chooseCave()

checkCave(caveNumber)

print('Do you want to play again? (yes or no)')

playAgain = input()

It appears that some of my code had been split^ this is not the case in python

Should display as below (minus periods preceding ‘print’):

def displayIntro():
. . . print('You\'re in a land full of magic and mystery, ')

So, right now if I choose “3” it takes me to the “path” option AND the “play again” option at the same time, thus ending the game if I enter east or west.

I don’t know if it will even work because I haven’t been able to enter a response!

Actual game output if choose “3”:

You're in a land full of magic and mystery,
Some say dragons live here and reside in caves.
In front of you, you see two caves.
In one cave, there is a friendly dragon who
has been alone for a thousand years and really just wants
to talk with someone. Maybe there's some treasure to be had!

In the other cave, the dragon is mean, nasty and terrible.
He's not misunderstood, he's just a mean guy and will eat you.

There seems to be another cave, but only one you've heard in legends
Which cave will you go into? (1, 2 or 3)
3
You approach the cave...
It's pitch black.. you can barely see a thing
A massive dragon surges from the shadows and confronts you, nose to nose.

"BLURURURG"
The Dragon explodes in front of you! Turns out it was just a balloon
You aqquire the long forgotten jewels and riches so you head out of the cave
there are 2 paths once you emerge from the cave...
One leads east, the other, west. Which one will you choose?
Do you want to play again? (yes or no)

NOTE: There are also a couple other bugs with when playing again and choosing 1 or 2, it plays both scenarios…but I think I can fix that one myself.

Anyone with knowledge of Python 3.5.2 please help thanks.

P.S. the “UR DEAD M8” and “GOOD JOB” are just placeholders for now :slight_smile:

#EDIT:
The guys on stackoverflow really helped me out, thanks @Life! I’ve managed to fix my current problem and will be able to avoid future problems too.


Mod note: Moved to Off-topic ~ BMJ


#2

Stack Overflow is a great website to ask and answer programming related questions.


#3

I’ve moved this to Off-topic. Whilst technically it’s Tech Support, the Game Discussion > Tech Support sub-category is for technical help with Realm.


#4

Gotcha


#5

aka Yeah use stack over flow it’s great


#6

Fixed:

<img src="DIRECT IMAGE URL HERE" />


#7

IK but then people can’t see how shitty imgur is!

I miss my puush :frowning:, can’t DL it on this computer.

Edit NVM just realized what you did haha thank you! I know HTML but didin’t think of doing that cause I suck


#8

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.