3
\$\begingroup\$

This is a project I've been working on and it's my first, so please feel free to just copy this into python and give this a try.

Below you'll find the main code and a small bit on rules and how to play, Enjoy!

import random

print("▄▄▄█████▓ ██░ ██ ▓█████    ▓█████▄  ▄▄▄       ██▀███   ██ ▄█▀   ▓█████▄  █    ██  ███▄    █   ▄████ ▓█████  ▒█████   ███▄    █ ")
print("▓  ██▒ ▓▒▓██░ ██▒▓█   ▀    ▒██▀ ██▌▒████▄    ▓██ ▒ ██▒ ██▄█▒    ▒██▀ ██▌ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒▓█   ▀ ▒██▒  ██▒ ██ ▀█   █ ")
print("▒ ▓██░ ▒░▒██▀▀██░▒███      ░██   █▌▒██  ▀█▄  ▓██ ░▄█ ▒▓███▄░    ░██   █▌▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░▒███   ▒██░  ██▒▓██  ▀█ ██▒")
print("░ ▓██▓ ░ ░▓█ ░██ ▒▓█  ▄    ░▓█▄   ▌░██▄▄▄▄██ ▒██▀▀█▄  ▓██ █▄    ░▓█▄   ▌▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓▒▓█  ▄ ▒██   ██░▓██▒  ▐▌██▒")
print(" ▒██▒ ░ ░▓█▒░██▓░▒████▒   ░▒████▓  ▓█   ▓██▒░██▓ ▒██▒▒██▒ █▄   ░▒████▓ ▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒░▒████▒░ ████▓▒░▒██░   ▓██░")
print(" ▒ ░░    ▒ ░░▒░▒░░ ▒░ ░    ▒▒▓  ▒  ▒▒   ▓▒█░░ ▒▓ ░▒▓░▒ ▒▒ ▓▒    ▒▒▓  ▒ ░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒ ░░ ▒░ ░░ ▒░▒░▒░ ░ ▒░   ▒ ▒ ")
print("    ░     ▒ ░▒░ ░ ░ ░  ░    ░ ▒  ▒   ▒   ▒▒ ░  ░▒ ░ ▒░░ ░▒ ▒░    ░ ▒  ▒ ░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░  ░ ░  ░  ░ ▒ ▒░ ░ ░░   ░ ▒░")
print("  ░       ░  ░░ ░   ░       ░ ░  ░   ░   ▒     ░░   ░ ░ ░░ ░     ░ ░  ░  ░░░ ░ ░    ░   ░ ░ ░ ░   ░    ░   ░ ░ ░ ▒     ░   ░ ░ ")
print("          ░  ░  ░   ░  ░      ░          ░  ░   ░     ░  ░         ░       ░              ░       ░    ░  ░    ░ ░           ░ ")
print(sep='/')

print("You wake up in a rotting cell its walls slowly crumbling.In the distance you hear shouting")
print("You get to your feet and realise the cell door is wide open, you walk through the door")
print("You are in a hallway its cobblestone covered in moss, A guard's body lay upon the ground in front of you.","you dress into this clothes in his pocket you find his scroll of identity it reads:")
firstguardbody="Gerald Whiteway"
print(sep='/')
print(firstguardbody)
print(sep='/')
print("You make your way down the hallway")
print("A growling noise fills the hallway as a dog runs towards you its teeth bearing a evil smile.You dodge its attack")
answer1=input("the dog readies to pounce again do you run or engage it in combat?")
if answer1=="engage"or answer1=="Engage":
    print("you bound towards the dog and strike it down")
else:
    print("you attempt to run but are chased and the dog bites into your leg you loose 2 hp as you shake it off")
print(sep='/')
nameanswer=input("halt!Who goes there?")
if nameanswer =="Gerald Whiteway" or nameanswer== "gerald whiteway":
    print("Gerald! I need your help,the guard stumbles into view with the element of surprise you pierce the man's stomach")
else:
    print("Stand Down! The guard steps into view his sword at the ready You launch forwards with your sword but the guard dodges and opens up a nick upon your arm you loose 1 hp")                 
    print("you swing your sword in a panic and cut open the guards neck")
print("in the man's possession you find a healing elixir")
print(sep='/')
print("In front of you stands a grand wooden door you push it open and enter a room with a resemblance to a kitchen")
print("On the large worktop you see a pot filled with a stew it seems rather fresh")
answer2=input("do you eat it?")
if answer2=="yes"or answer2=="Yes"or answer2==" yes":
    print("The salty taste of the stew makes you splutter but fills your stomach,You gain 3 hp")
else:
    print("Out of caution you leave the stew on the work top")
print(sep='/')
answer3=input("As you leave the kitchen the tunnel splits into two do you go right or left?")
if answer3=="left"or answer3=="Left":
    print("you head down the left route you hear a slow click spikes rise from the ground and impale your foot you loose 3 hp and slowly limp back to the to the start of the passage and make your way down the right side")
else:
    print("you walk down to the end of the passage way")
print("Two mutated creatures stand in your way they seem to be blind")
answer4=input("Do you attempt to sneak past them or do you engage them?")
if answer4=="sneak"or answer4=="go past"or answer4=="sneakpast"or answer4=="sneak past":
    print("You attempt to sneak past.The creatures sniff the air,suddenly both cry out loud and swing their arms wildly in your direction you loose 3 hp")
    print("You regain your footing and swing your sword in two precise swings opening up a gash in the chests of the creatures")
else:
    print("You run up to one of the creatures and quickly decapitate it but the second one digs its claws into your side and you loose 2 hp")
    print(" you penetrate the creature's rib cage and drop it to the floor")
print(sep='/')
print("You hear a loud booming voice getting closer and closer,at once the wall to the passageway crumbles and a large Knight like figure steps in front of you")
heroname=input("WHO IS THIS WHO STAND BEFORE ME THE DARK NIGHT!")
if heroname=="joe":
    joewho=input("Joe who?")
    if joewho=="joemama":
        print("The Knight trembles in fear and collapses before you")
        print(sep='/')
        print("Welldone You have found the joemama easter egg")
else:
    print(heroname,"YOU WILL BE CRUSHED!")
    answer5=input("The dark night swings his sword down do you dodge left or right?")
    if answer5=="left"or answer5=="Left"or answer5==" left"or answer5=="right"or answer5=="Right"or answer5==" right":
        print("You dodge the dark knights swing")
        answer6=input("The dark knight swings his sword once again do you dodge or attack?")
        print("YOU WILL NOT DEFEAT ME! the dark knight booms as he lurches forwards")
        finalkill=random.randint(1,6)
        print(finalkill)
    if finalkill==6:
        print(sep='/')
        print("You dodge the dark knights attack and launch your sword into his unarmoured chest he drops to the floor blood sprawling around him")
        print("Well done. You completed the game. Thank you for playing I greatly appreciate it")
    else:
        print(sep='/')
        print("The dark knight digs his sword through your chest as your soul leaves your body")
        print("                               YOU LOST                                      ")

Rules and how to play

elixir=0
print("This is the stat tracker for The Dark Dungeon Narrative Choice game. Here you will be able to keep track of health how many elixirs you have the final battle and read the rules")
print("RULES:")
print("if you have an elixir you can use it anytime to regain 1 hp")
print("if you are struck with a trap you will take the amount of damage on the screen and loose 1 hp after every battle")
print("the final battle is depended on a dice roll but the computer will roll for you")
\$\endgroup\$
2
  • \$\begingroup\$ Paste into Python is "difficult" due to immediate interpretation. \$\endgroup\$
    – greybeard
    Feb 4 '20 at 12:04
  • 2
    \$\begingroup\$ @greybeard I recommend pasting it in a file first, like you'd with any program. \$\endgroup\$
    – Mast
    Feb 4 '20 at 12:35
3
\$\begingroup\$

It looks like most of the encounters in your game follow this general sequence:

  1. Prompt the user for input.
  2. Print a result and modify the user's HP.

The part where you modify the HP isn't actually implemented, but based on the text it looks like that's something you're planning on doing, anyway. :) You could generalize that sequence as a function that takes the prompt and the set of possible results, prints the outcome, and returns the modified hit point total so you can keep track of it through the different encounters.

That function might look like this:

from typing import Dict, Optional, Tuple

def do_encounter(
    prompt: str, 
    hp: int, 
    outcomes: Dict[Optional[str], Tuple[str, int]
) -> int:
   """Run an encounter in the game, reading input from stdin and writing to stdout.
   If the encounter results in killing the player, exit the program.
   Otherwise, return the player's remaining hit points."""
   answer = input(prompt).lower()
   message, hp_change = outcomes[answer] if answer in outcomes else outcomes[None]
   print(message)
   hp += hp_change
   if hp > 0:
       # Player still alive
       return hp
   # Player is dead!
   print("YOU LOST".center(72))
   exit()

And then you can do:

hp = 10  # starting hp

# The dog encounter: if the player engages, they escape unharmed, otherwise -2 hp.
hp = do_encounter(
    "the dog readies to pounce again do you run or engage it in combat?", hp, {
        "engage": ("you bound towards the dog and strike it down", 0),
        None: ("you attempt to run but are chased and the dog bites" +
               "into your leg; you lose 2 hp as you shake it off", -2)
    }
)
print()

# ... more encounters here, you get the idea

# Initial dark knight attack-- dodge left or right, or suffer massive damage!
print(heroname, "YOU WILL BE CRUSHED!")
hp = do_encounter(
    "The dark knight swings his sword down; do you dodge left or right?", hp, {
        "left": ("You dodge the dark knight's swing", 0),
        "right": ("You dodge the dark knight's swing", 0),
        None: ("The dark knight digs his sword through your chest "+ 
               "as your soul leaves your body", -100)
    }
)
print()

# Second dark knight attack.  It doesn't matter what the player does here!
hp = do_encounter(
    "The dark knight swings his sword once again do you dodge or attack?", hp, {
        None: ("YOU WILL NOT DEFEAT ME! the dark night booms as he lurches forwards", 0)
    }
)

# Now we determine victory by random chance.
finalkill=random.randint(1,6)
# ... etc

Making your encounters follow a similar format makes it easier to tell by looking at your code how the game progresses -- for example, in the final encounter it doesn't matter whether the player dodges left or right initially (but they die if they do neither), and it doesn't matter at all what they do in the final question! That's more of a game design problem than a coding one, but one of the properties of well-written code is that it's easier to perceive the overall design by reading the code.

\$\endgroup\$
1
  • \$\begingroup\$ thank you for your input in the next one Im creating I've taken a more open and different system so its not all just yes or no \$\endgroup\$ Feb 13 '20 at 14:19
3
\$\begingroup\$

Pixel Art

Great pixel art! One thing I want to say about printing pixel art specifically is using block quotes. These are triple quotes """ that allow you to print multi line things in one print statement. This reduces the times print shows up in your program, and even formats it a little nicer.

In some IDE's, after a print statement, there's a small buffer line between the next print statement so they're not immediately stacked on each other. This buffer can mess with how pixel art is supposed to be displayed. With block quotes, there's no buffer between each line in the quote, so the art is displayed as intended.


Functions

Your code can be easily separated into chunks, or functions. Using functions can help you organize your code. Other benefits include code reusability, but that isn't necessary here. You can put each encounter the player deals with into a function, then call the next functions once that encounter has been completed. Please refer to the end of the answer to see what I mean.


Spacing

When spacing operators, there should be a space before and after the operator. Take a look:

name = input("Enter your name: ")

This makes your code a bit nicer, and allows for easier readability of your code.


Input Verification

When accepting user input, it's understandable that it may not be exactly what you want. Checking for "yes" and getting "Yes" or other permutations can be frustrating. Luckily, python is looking out for you.

You can utilize .lower() to reduce the input string to all lowercase characters. Now, if you want a "yes" or "no", simply lower the input string and check that. Take a look:

verify = input("Are you sure? ").lower()
if verify == "yes":
    print("Okay.")

Looking In Lists

This is essentially a subsection of input verification. For answer4, you check multiple inputs from the user. Instead of a == 1 or a == 2 or a == 3 (not what you wrote, but you get the point), you can put these options in a list and check the vacancy of the user input. Take a look:

food = input("What is your favorite fruit? ")
if food in ["apple", "orange", "banana", "grape"]:
    print("Mine too!")

Main Guard

Last thing I'm commenting on.

You should use a main guard when running this program. Why?

Let's say you want to import this module into another program, because you don't want to rewrite all this code in a different file. So you decide to import this program to save some time. When you import the module, any code not within a function is executed. That is not what you want. Containing this extra code in a main guard will prevent this from happening. It's a simple if statement:

if __name__ == "__main__":
    ... do stuff ...

Updated Code

import random

def display_rules():
    print("This is the stat tracker for The Dark Dungeon Narrative Choice game. Here you will be able to keep track of health how many elixirs you have the final battle and read the rules")
    print("RULES:")
    print("if you have an elixir you can use it anytime to regain 1 hp")
    print("if you are struck with a trap you will take the amount of damage on the screen and loose 1 hp after every battle")
    print("the final battle is depended on a dice roll but the computer will roll for you")

    # Allow time for user to read rules #
    _ = input("\nPress enter to continue.")

def start_game():
    print("""
        ▄▄▄█████▓ ██░ ██ ▓█████    ▓█████▄  ▄▄▄       ██▀███   ██ ▄█▀   ▓█████▄  █    ██  ███▄    █   ▄████ ▓█████  ▒█████   ███▄    █ 
        ▓  ██▒ ▓▒▓██░ ██▒▓█   ▀    ▒██▀ ██▌▒████▄    ▓██ ▒ ██▒ ██▄█▒    ▒██▀ ██▌ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒▓█   ▀ ▒██▒  ██▒ ██ ▀█   █ 
        ▒ ▓██░ ▒░▒██▀▀██░▒███      ░██   █▌▒██  ▀█▄  ▓██ ░▄█ ▒▓███▄░    ░██   █▌▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░▒███   ▒██░  ██▒▓██  ▀█ ██▒
        ░ ▓██▓ ░ ░▓█ ░██ ▒▓█  ▄    ░▓█▄   ▌░██▄▄▄▄██ ▒██▀▀█▄  ▓██ █▄    ░▓█▄   ▌▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓▒▓█  ▄ ▒██   ██░▓██▒  ▐▌██▒
         ▒██▒ ░ ░▓█▒░██▓░▒████▒   ░▒████▓  ▓█   ▓██▒░██▓ ▒██▒▒██▒ █▄   ░▒████▓ ▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒░▒████▒░ ████▓▒░▒██░   ▓██░
         ▒ ░░    ▒ ░░▒░▒░░ ▒░ ░    ▒▒▓  ▒  ▒▒   ▓▒█░░ ▒▓ ░▒▓░▒ ▒▒ ▓▒    ▒▒▓  ▒ ░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒ ░░ ▒░ ░░ ▒░▒░▒░ ░ ▒░   ▒ ▒ 
             ░     ▒ ░▒░ ░ ░ ░  ░    ░ ▒  ▒   ▒   ▒▒ ░  ░▒ ░ ▒░░ ░▒ ▒░    ░ ▒  ▒ ░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░  ░ ░  ░  ░ ▒ ▒░ ░ ░░   ░ ▒░
          ░       ░  ░░ ░   ░       ░ ░  ░   ░   ▒     ░░   ░ ░ ░░ ░     ░ ░  ░  ░░░ ░ ░    ░   ░ ░ ░ ░   ░    ░   ░ ░ ░ ▒     ░   ░ ░ 
                  ░  ░  ░   ░  ░      ░          ░  ░   ░     ░  ░         ░       ░              ░       ░    ░  ░    ░ ░           ░ 
    """)
    print(sep='/')
    print("You wake up in a rotting cell its walls slowly crumbling.In the distance you hear shouting")
    print("You get to your feet and realise the cell door is wide open, you walk through the door")
    print("You are in a hallway its cobblestone covered in moss, A guard's body lay upon the ground in front of you.","you dress into this clothes in his pocket you find his scroll of identity it reads:")
    print(sep='/')
    print("Gerald Whiteway")
    print(sep='/')
    print("You make your way down the hallway")
    print("A growling noise fills the hallway as a dog runs towards you its teeth bearing a evil smile.You dodge its attack")

    # Start next encounter #
    dog_encounter()

def dog_encounter():
    answer1 = input("the dog readies to pounce again do you run or engage it in combat?").lower()
    if answer1 == "engage":
        print("you bound towards the dog and strike it down")
    else:
        print("you attempt to run but are chased and the dog bites into your leg you loose 2 hp as you shake it off")
    print(sep='/')

    # Start next encounter #
    name_encounter()

def name_encounter():
    nameanswer = input("halt!Who goes there?").lower()
    if nameanswer == "gerald whiteway":
        print("Gerald! I need your help,the guard stumbles into view with the element of surprise you pierce the man's stomach")
    else:
        print("Stand Down! The guard steps into view his sword at the ready You launch forwards with your sword but the guard dodges and opens up a nick upon your arm you loose 1 hp")                 
        print("you swing your sword in a panic and cut open the guards neck")
    print("in the man's possession you find a healing elixir")
    print(sep='/')

    # Start next encounter #
    stew_encounter()

def stew_encounter():
    print("In front of you stands a grand wooden door you push it open and enter a room with a resemblance to a kitchen")
    print("On the large worktop you see a pot filled with a stew it seems rather fresh")
    answer2 = input("Do you eat it?").lower()
    if answer2 == "yes":
        print("The salty taste of the stew makes you splutter but fills your stomach,You gain 3 hp")
    else:
        print("Out of caution you leave the stew on the work top")
    print(sep='/')

    # Start next encounter #
    tunnel_encounter()

def tunnel_encounter():
    answer3 = input("As you leave the kitchen the tunnel splits into two do you go right or left?").lower()
    if answer3 == "left":
        print("you head down the left route you hear a slow click spikes rise from the ground and impale your foot you loose 3 hp and slowly limp back to the to the start of the passage and make your way down the right side")
    else:
        print("you walk down to the end of the passage way")

    # Start next encounter #
    creature_encounter()

def creature_encounter():
    print("Two mutated creatures stand in your way they seem to be blind")
    answer4 = input("Do you attempt to sneak past them or do you engage them?").lower()
    if answer4 in ["sneak", "go past", "sneakpast", "sneak past"]:
        print("You attempt to sneak past.The creatures sniff the air,suddenly both cry out loud and swing their arms wildly in your direction you loose 3 hp")
        print("You regain your footing and swing your sword in two precise swings opening up a gash in the chests of the creatures")
    else:
        print("You run up to one of the creatures and quickly decapitate it but the second one digs its claws into your side and you loose 2 hp")
        print(" you penetrate the creature's rib cage and drop it to the floor")
    print(sep='/')

    # Start next encounter #
    knight_encounter()

def knight_encounter():
    print("You hear a loud booming voice getting closer and closer,at once the wall to the passageway crumbles and a large Knight like figure steps in front of you")
    heroname = input("WHO IS THIS WHO STAND BEFORE ME THE DARK NIGHT!").lower()
    if heroname == "joe":
        joewho = input("Joe who?").lower()
        if joewho == "joemama":
            print("The Knight trembles in fear and collapses before you")
            print(sep='/')
            print("Welldone You have found the joemama easter egg")
    else:
        print(heroname, "YOU WILL BE CRUSHED!")
        answer5 = input("The dark night swings his sword down do you dodge left or right?").lower()
        if answer5 in ["left", "right"]:
            print("You dodge the dark knights swing")
            answer6 = input("The dark knight swings his sword once again do you dodge or attack?")
            print("YOU WILL NOT DEFEAT ME! the dark knight booms as he lurches forwards")
            finalkill = random.randint(1,6)
            print(finalkill)
        if finalkill == 6:
            print(sep='/')
            print("You dodge the dark knights attack and launch your sword into his unarmoured chest he drops to the floor blood sprawling around him")
            print("Well done. You completed the game. Thank you for playing I greatly appreciate it")
        else:
            print(sep='/')
            print("The dark knight digs his sword through your chest as your soul leaves your body")
            print("                               YOU LOST                                      ")

if __name__ == "__main__":
    display_rules()
    start_game()
\$\endgroup\$
1
  • \$\begingroup\$ I really appreciate your tips and help it means a lot to me as someone who hasn't got a lot of experience I'll implement these new skills in other things I do \$\endgroup\$ Feb 13 '20 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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