5
\$\begingroup\$

I made an adventure game, it is unfinished at the moment but not far off.

Here is what I have so far:

def Invalid():
    print("Sorry I didnt understand what you just wrote")

def Help():
    print("The commands that I understand are:")
    print("Open, Take, Talk, Use")

def Intro():
  print("Welcome to my adventure game")
  print("Type 'Help' for a list of options")
  print("You will move using 'N'(North), 'S'(South), 'E'(East) and 'W'(West)")
  print("Some extra options will be available shown as 'text' ")
  print("Type 'S' to get started")




game = input("")

  if game.upper() == "S":
    ShipWreck()
  else:
    Invalid()
    ShipWreck()

def ShipWreck():
    print("You are at a shipwreck.")
    print("You can see a forest in the north")
    print("There is a locked chest in front of you")
    print("Where do you wish to go")
    print("N")

    direction = input("")

    if direction.upper() == "N":
        Town()
    elif direction.upper() == "OPEN CHEST":
        print("The chest cant be open without the key")
        ShipWreck()
    elif direction.upper() == "HELP":
        Help()
        ShipWreck()
    else:
        Invalid()
        ShipWreck()

def Town():
    print("You are in a town")
    print("It is very busy")
    print("There is a preacher near by (E)")
    print("There is also a blacksmith (W)")
    print("Where do you want to go next?  Cave(N) or Forest(S)")

    direction = input("")

    if direction.upper() == "W":
        Blacksmith()
    elif direction.upper() == "E":
        Preacher()
    elif direction.upper() == "N":
        eCave()
    elif direction.upper() == "S":
        Forest()
    else:
        Invalid()

def Preacher():
    print ("    __    ")
    print ("   /..\   ")
    print ("   \__/   ")
    print ("  /|  |\  ")
    print (" /_|__|_\ ")
    print("There is a dragon somewhere in the cave, be careful.")
    print("I recommend you buy a sword if you are brave enough to fight it")
    print("You can buy a sword from the Blacksmith over there")
    print("")
    print("(E, to leave preacher)")
    print("")

    direction = input("")

    if direction.upper() == "E":
        Town()
    else:
        Invalid()
        Preacher()


def Blacksmith():
    print ("  _____  ")
    print (" / ~~~ \ ")
    print (" \ `¿´ / ")
    print ("  \ - /  ")
    print("You are in the blacksmith")
    print("There is a man selling weapons")
    print("")
    print("")
    print("")

    direction = input("")

    if direction.upper() == "S":
        Town()
    elif direction.upper() == "U":
        ()
    if direction.upper() == "U":
        ()
    else:
        Invalid()



def eCave():
    print("You are at the entrance to a cave, it is very dark inside the cave")
    print("There is a man in a black robe standing outside the cave")
    print("Where do you wish to go")
    print("N")
    print("E")
    print("S")

    direction = input("")


    if direction.upper() == "N":
        spCave()
    elif direction.upper() == "E":
        Woods()
    elif direction.upper() == "S":
        Town()
    else:
        Invalid()

def spCave():
    print("The cave has split into two tunnels.")
    print("You can go left or right")
    print("")
    print("(L, For left tunnel)")
    print("(R, For right tunnel)")
    print("(S, To leave the cave)")

    direction = input("")

    if direction.upper() == "L":
        print("You are at a dead end, you must go back")
        spCave()
    elif direction.upper() == "R":
        Dragon()
    elif direction.upper() == "S":
        eCave()
    else:
        Invalid()
        spCave()

def Woods():
    print("You are in a lightly spaced woods.")
    print("There seems")
    print("Where do you wish to go")
    print("N")
    print("E")
    print("S")

    direction = input("")

    if direction.upper() == "W":
        eCave()
    elif direction.upper() == "N":
        House()
    else:
        Invalid()
        Woods()

'''def House():

    Answer = False
    print ("In front of you is a gaint house")
    while Answer == False:
        print ("There is a gaint open eye on the door, the eye stare directly at you")
        print ("A voice booms out from the door")
        print ("(Answer my)"'''

Intro()
\$\endgroup\$

closed as off-topic by holroy, Ethan Bierlein, Mast, SuperBiasedMan, 200_success Feb 29 '16 at 19:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – holroy, Ethan Bierlein, Mast, SuperBiasedMan, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Your code is broken as it stands as House() is undefined but referenced, and the indentation on game = input("") is wrong which would lead to runtime errors. Code Review is for reviewing working code. Note that if it is closed, you can still edit it and get it reopened afterwards... \$\endgroup\$ – holroy Feb 29 '16 at 16:36
  • \$\begingroup\$ @holroy No, this question already has an answer. Answered questions risk answer invalidation when their code is edited, which should be prevented. A follow-up question would be more appropriate. The site policy is explained in What to do when someone answers. \$\endgroup\$ – Mast Feb 29 '16 at 16:42
  • \$\begingroup\$ Disregard the edit part as Mast suggest from my comment! Sorry for confusing you! \$\endgroup\$ – holroy Feb 29 '16 at 16:45
  • 3
    \$\begingroup\$ @Mast If the code is broken due to a simple error in posting rather than a logic bug, I don't see the harm in fixing the indentation and reopening the question. Let's use some common sense. \$\endgroup\$ – 200_success Feb 29 '16 at 19:04
2
\$\begingroup\$

A few things I noticed right off the bat:

  • Spelling mistakes. They take away from the user's experience.
  • Too many print statements. You can call print() then use newline characters (\n) to put the rest of the text on the next line.
  • Repeated checking of "W" "E" "S" "N". Write a function that you can call like user_input(direction) instead.
  • Define your ASCII art in functions, like print_preacher() and print_blacksmith().
  • You need not put an empty string in input().
  • You have an unneeded if() in Blacksmith().

Otherwise, you've got a pretty good start here.

\$\endgroup\$
  • 1
    \$\begingroup\$ Technically functions in Python should be named in snake_case, as per PEP8, the official Python style guide. \$\endgroup\$ – Ethan Bierlein Feb 29 '16 at 16:35
  • \$\begingroup\$ Welcome to Code Review! Please be aware that we in general restrain from answering questions where the original code is broken as is the case here. Broken code is off-topic. Other than that, you are making some good points. \$\endgroup\$ – holroy Feb 29 '16 at 16:39
  • 1
    \$\begingroup\$ @EthanBierlein Updated to snake_case. \$\endgroup\$ – Ellis Feb 29 '16 at 18:33
1
\$\begingroup\$

Controls

From a player's standpoint, even though N, S, E, W may seem like good choices, this would make it totally awkward to play (try it yourself). A more typical layout of keys for directions in computer games is "You will move using 'W'(North), 'S'(South), 'D'(East) and 'A'(West)". This is know as WASD controls:

WASD

A caveat of this is that it is intended for ANSI American / "QWERTY" keyboards.

Another, perhaps better alternative would be to use the standard arrow keys which are found on practically all keyboards. See Finding the Values of the Arrow Keys in Python on Stack Overflow.

arrow keys

Then for example you could do something like this:

if direction.upper() == 'W' or direction == '\x1b[D':   #left arrow
    Blacksmith()
elif direction.upper() == "E" or direction == '\x1b[C': #right arrow
    Preacher()
elif direction.upper() == "N" or direction == '\x1b[A': #up arrow
    eCave()
elif direction.upper() == "S" or direction == '\x1b[B': #down arrow
    Forest()
else:
    Invalid()

Of course this is clunky to have to type every time, so you could declare some constants:

UP_ARROW = '\x1b[A'
DOWN_ARROW = '\x1b[B'
RIGHT_ARROW = '\x1b[C'
LEFT_ARROW = '\x1b[D'

if direction.upper() == 'W' or direction == LEFT_ARROW:
    Blacksmith()
# etc.

That way you leave both options open to the player, and apply the changes through your code...

print("You will move using 'N' or [↑] (North), 'S' or [↓] (South), 'E' or [→] (East) and 'W' or [←] (West)")
\$\endgroup\$
  • 3
    \$\begingroup\$ N,S,E,W (along with optionally U, D, NW, NE, SW, and SE) is as canonical in adventure games as WASD is in FPS's, and to comply with user expectations, should probably not be omitted. Permitting the arrows as an alternative is a good option, though - some systems allow the numeric keypad, which allows for the NW/NE/SW/SE directions, too. \$\endgroup\$ – Dewi Morgan Feb 29 '16 at 19:00
  • 2
    \$\begingroup\$ In addition, if there are to be more options for input rather than a direction character like E or an arrow key, the input checking if statements should probably be changed to something like if direction.upper() in ["W", LEFT_ARROW, ...]. \$\endgroup\$ – Ethan Bierlein Feb 29 '16 at 19:07

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