Python Forum
collosal cave python adventure
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
collosal cave python adventure
#1
in this task that i have been set i have to recrate the 80s game colosal cave adventure but with learning python.
my code is this:
# collosal cave python adventure!
def op01():
input("what is your name brave adventurer?")

def op02():
if op01()== ("Parzival" and "parzival" and "Art3mis" and "artemis" and "Aech" and "aech"):
print ("welcome I am honoured to meet you. Even not in person it is still an honour.")
else:
print("welcome",op01(),"welcome to collosal cave python adventure")

def op03():
ready1 = input("are you ready to learn python? Yes/No")

def op04():
input("you are sat infront of a red brick house deep in the heart of a pine wood. what should you do? \n be simple\n try enter")

def op05():
if ready1() == ("Yes" and "yes" and "Y"):
op04()

def op06():
input("well were starting anyway \n you are sat infront of a red brick house deep in the heart of a pine wood. what should you do? \n be simple \n try 'enter' ")

def op07():
input("on a desk in the middle of the dark dingy room is an ancient apple II. waht do you do?")

def op08():
if op04()and op06() == ("go in" and "enter" and "open door"):
op07 = input("on a desk in the middle of the dark dingy room is an ancient PC. waht do you do?")


op01()
op02()
op03()
op04()
op05()
op06()
op07()
op08()




when this runs it asks for the name 3 times and the ignors the hello bla bla bla (op02)
(the aech parzival art3mis are from my favourite book ready player one)
Reply
#2
In your first function, input("what is your name brave adventurer?") will prompt the user for their name, but then does nothing with the input. It needs to be returned to the caller. This is your first instance of being asked the question.

Your second function calls the first function (your second instance of the question), which does not return a values, and then tests it. The test is not going to be true as you are comparing '' with the last string in the list of ANDed strings (because: 'a' and 'b' and 'c' is the same as 'c'). Python treats null strings as false, and non null strings as true. When and is used, if the left string is true and the second string is true then the second string is returned. In your comparison this works through each and and ends up with your last string.

The else print line in the second function calls the first function again, which is the third time the question is asked.

Your third function at least stores the input, but only within the function. It needs to returned to the caller.

Another function attempts to get to the value saved in the third function by referencing the variable the input was saved in BUT it tries to call it as a function - name(). That will not work. The variable is not available outside of the function that defined it anyway.
I am trying to help you, really, even if it doesn't always seem that way
Reply
#3
That was a great game. I wasted many hours playing.
Reply
#4
Usually when new programmers try to write a text adventure like the original Colossal Cave Adventure, they use a huge nest if if/elif/else statements. You're using functions, which is a step up, but your functions are just a wrapper for all of the if/elif/else statements, and the don't even have descriptive names. If you want to do this, you should check out the text adventures tutorial link in my signature. It shows a much better way to do this sort of thing.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020