Discuss Scratch

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Delta135 wrote:

Want me to host it on Replit?

Thanks for offering that! Are you sure though?

also, you might wanna remove/modify the saving and loading, if you do












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

Yeah I tested saving/loading and it doesn't work well…

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

Fixed. Can you add a command to end the game, and instructions?

It works well, but on Repl you probably need instructions and a command to end the game. Great job on this though!

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Delta135 wrote:

Yeah I tested saving/loading and it doesn't work well…

probably because it requires a savedat2.txt to work (and the save wouldn't persist after the user left, making the save useless anyway).












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

I'm getting a tab-error… ?

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

It highlights the colon in except:

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

Futurebot5
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Delta135 wrote:

Never mind. fixed. ScratchCatHELLO's Text Adventure
Tis a 404.

So…hello, ou bonjour, o hola, o ciao, oder hallo.

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Futurebot5 wrote:

Delta135 wrote:

Never mind. fixed. ScratchCatHELLO's Text Adventure
Tis a 404.

scratch converts @s to %40's in links, which breaks every replit link. just replace the %40 with an @ or select the link below and open it in a new tab.

https://replit.com/@Kizuo/ScratchCatHELLOs-Text-Adventure?v=1












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

gosoccerboy5
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

ScratchCatHELLO wrote:

question: is it okay to put Object 1 inside of Object 2 when Object 2 is also in Object 1? It doesn't seem to be breaking anything, but objects that contain each other infinitely is a kinda sketchy thing to do.
I don't see anything wrong with that..
is there a way to minify the file? oh wait, it's python

You should use/sign up for replit or github, its worth it

Kerbal Space Program!!!
ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

so I made the original map in the new engine
#uses new engine
import pickle
from difflib import SequenceMatcher
import re
#find the item of a list that is closest to a string
def findsimilar(thing, inlist):
    similar = {}
    for item in inlist:
        similar[item] = SequenceMatcher(None, item, thing).ratio()
    return list(reversed(sorted(similar.items(),key=lambda x:x[1])))[0][0]
class Creature:
    def __init__(self, name, dialog, stats, attackable):
        self.name = name
        self.dialog = dialog
        self.stats = stats
        self.attackable = attackable
class Player:
    def __init__(self, name, flags, inventory, stats):
        self.name = name
        self.flags = flags
        self.inventory = inventory
        self.stats = stats
#item class
class Item:
    def __init__(self, name, description, detail):
        self.name = name
        self.description = description
        self.detail = detail
#weapon subclass of item
class Weapon(Item):
    def __init__(self, name, description, detail, atkstr):
        super().__init__(name, description, detail)
        self.atkstr = atkstr
#room class definition
class Room:
    def __init__(self, name, directions, descriptions, items, creatures):
        self.name = name
        self.directions = directions
        self.descriptions = descriptions
        self.items = items
        self.creatures = creatures
Start = Room (
    "Start Crossroads",
    {
    "south": "Forest Exit"
    },
    {
    "normal": "The entrance to the town of Qwertyuiopasdfghjkl.",
    "detail": "The sign reads \"Qwertyuiopasdfghjkl; Gur gbja bs xrlobneq fznfu.\" \nThe town is to the north.\nTo the south lies a dense forest. \nTo the west is a trail that leads to a distant mountain.\nTo the east is a bridge over a rushing river."
    },
    {},
    {}
)
F_Ex = Room(
    "Forest Exit",
    {
    "south": "Forest Clearing",
    "north": "Start Crossroads"
    },
    {
    "normal": "The trail on which you came.",
    "detail": "A dark forest trail. This place makes you jumpy. \nThe trail continues south."
    },
    {},
    {}
)
F_C = Room(
    "Forest Clearing",
    {
    "north": "Forest Exit",
    "west": "Forest Trapdoor"
    },
    {
    "normal": "A rocky clearing in the forest.",
    "detail": "The trail widens out into a clearing.\nThere is a trapdoor in the ground to the west that you hadn't noticed before.\nThe trail continues north and south."
    },
    {},
    {}
)
F_T = Room(
    "Forest Trapdoor",
    {
    "east": "Forest Clearing"
    },
    {
    "normal": "A forest clearing. Below you is a trapdoor.",
    "detail": "The trapdoor is locked. \nYou may go back east into the main clearing."
    },
    {},
    {}
)
F_En = Room(
    "Forest Entrance",
    {
    "north": "Forest Clearing"
    },
    {
    "normal": "The entrance to the forest.",
    "detail": "A dark, thin forest trail. The forest gradually thins into a plains.\nYou may go north back into the clearing."
    },
    {},
    {}
)
F_SR = Room(
    "Sword Room",
    {
    "up": "Forest Trapdoor"
    },
    {
    "normal": "A dim, small, stone room.",
    "detail": "A sword sits on the pedestal in the center. The only way to go in the cramped room is up."
    },
    {},
    {}
)
allrooms = {
    "Start Crossroads": Start,
    "Forest Exit": F_Ex,
    "Forest Clearing": F_C,
    "Forest Entrance": F_En,
    "Forest Trapdoor": F_T,
    "Sword Room": F_SR
}
allcommands = ["load", "save", "inspect", "inventory", "help", "instructions", "drop", "grab", "look at", "look", "up", "down", "north", "south", "east", "west"]
hintrock = Item("rock", "A rock with writing on it. You can't make out the words.", "The rock reads \"[Oo]pen ([Ss]esame[.!]|[Uu]p[!.])\"...\nIt's in the ancient language of R'jex!")
F_T.items["hintrock"] = hintrock
sword = Weapon("sword", "A faintly glowing blue sword...\nHow cliche.", "There are various symbols etched into the blade that glow brighter.", 10)
F_SR.items["sword"] = sword
name = input("What is your name?\n")
if name:
    player = Player(name, {}, {}, {})
else:
    player = Player("Johnus Doeus", {}, {}, {})
#starting room
place = Start
#allow user to quit
command = ""
while not command == "quit":
    #show the normal description of the room
    print(place.descriptions["normal"])
    #list items in the room
    for item in place.items:
        print("There is a " + place.items[item].name + " here.")
    #list creatures in the room
    for creature in place.creatures:
        print("There is a " + place.creatures[creature].name + " in the room.")
    #get input
    command = input(player.name + ">")
    #allow player to move
    if command in place.directions:
        place = allrooms[place.directions[command]]
    elif place.name == "Forest Trapdoor" and command == "down":
        if re.search("[Oo]pen ([Ss]esame[.!]|[Uu]p[!.])", input("What is the password?\n")):
            print("The trapdoor glows faintly and creaks open.")
            place.directions["down"] = "Sword Room"
            place.descriptions["detail"] = "The trapdoor is locked. \nYou may go back east into the main clearing.\nYou can also climb down through the trapdoor."
        else:
            print("Nothing happens.")
    elif command in ["up", "down", "north", "south", "east", "west"]:
        print("You cannot go " + command)
    #print all command names (add descriptions?)
    elif command == "help":
        for command in allcommands:
            print(command)
    #print instuctions
    elif command == "instructions":
        print("This is just a test level, and there isn't much to just yet.\nYou can type 'help' for a list of commands.\nYou can type 'quit' to quit.\nYou can look around with 'look'\nYou can pick up and drop items with 'grab ___' and 'drop ___'\nYou can open your inventory with 'inventory'\nYou can inspect items you are holding with 'inspect ___'\nYou can look at items you aren't holding with 'look at ___'\nYou can talk to creatures by typing 'talk to ___'\nYou can load and save (EXPIREMENTAL) with 'load' and 'save'")
    #allow player to look at items they aren't holding
    elif command[0:7] == "look at":
        if command.replace("look at", ""):
            for item in place.items:
                if place.items[item].name == command.replace("look at ", ""):
                    print(place.items[item].description)
        else:
            print("look at what?")
    #deeper descriptions
    elif command == "look":
        print(place.descriptions["detail"])
    #allow player to grab items
    elif command[0:4] == "grab":
        if command.replace("grab", ""):
            #figure out what they're grabbing
            tmpitem = ""
            for item in place.items:
                if place.items[item].name == command.replace("grab ", ""):
                    #python gets upset when I put the code in this loop
                    tmpitem = item
                    break
            if tmpitem:
                print(place.items[tmpitem].name + " grabbed!")
                #copy item into inventory and remove item from room
                player.inventory[tmpitem] = place.items[tmpitem]
                place.items.pop(tmpitem)
                if place.name == "Sword Room":
                    place.descriptions["detail"] = "There is an empty pedestal in the center of the room. The only way to go in the cramped room is up."
            else:
                print("There is no " + command.replace("grab ", "") + " here.")
        else:
            print("Grab what?")
    #allow player to drop items (does the inverse of "grab")
    elif command[0:4] == "drop":
        if command.replace("drop", ""):
            tmpitem = ""
            for item in player.inventory:
                if player.inventory[item].name == command.replace("drop ", ""):
                    tmpitem = item
                    break
            if tmpitem:
                print(player.inventory[tmpitem].name + " dropped!")
                #copy item into inventory and remove item from room
                place.items[tmpitem] = player.inventory[tmpitem]
                player.inventory.pop(tmpitem)
                if place.name == "Sword Room":
                    place.descriptions["detail"] = "A sword sits on the pedestal in the center. The only way to go in the cramped room is up."
            else:
                print("You don't have a " + command.replace("drop ", "") + ".")
        else:
            print("Drop what?")
    #show the player's inventory (make this better later)
    elif command == "inventory":
        for item in player.inventory:
            print(player.inventory[item].name)
            print(player.inventory[item].description)
    #show detailed description for items in inventory
    elif command[0:7] == "inspect":
        if command.replace("inspect ", ""):
            for item in player.inventory:
                if player.inventory[item].name == command.replace("inspect ", ""):
                    print(player.inventory[item].detail)
        else:
            print("Inspect what?")
    #allow player to talk to creatures
    elif command[0:7] == "talk to":
        activecreature = ""
        #figure out what creature the player is talking to
        for creature in place.creatures:
            if place.creatures[creature].name == command.replace("talk to ", ""):
                activecreature = place.creatures[creature]
                break
        if activecreature:
            userresp = ""
            #get the initial dialog snippet
            currentdialog = activecreature.dialog[activecreature.dialog["INITIAL"]]
            while not userresp == "goodbye":
                print("The " + activecreature.name + " says '" + currentdialog["text"] + "'")
                #print possible responses
                for response in currentdialog["responses"]:
                    print(response + ": " + currentdialog["responses"][response]["text"])
                userresp = input(">").upper()
                if userresp in currentdialog["responses"]:
                    try:
                        print("You say '" + currentdialog["responses"][userresp]["text"] + "' to the " + activecreature.name)
                        #set the current dialog snippet to the new dialog snippet
                        currentdialog = activecreature.dialog[currentdialog["responses"][userresp]["newdialog"]]
                    except:
                        break
                elif not userresp == "goodbye":
                    #tell user if they didn't type a valid response
                    print("'" + userresp + "' is not a valid response.")
    #save (not updated)
    elif command == "save":
        save = {}
        save["player"] = player
        save["place"] = place.name
        save["rooms"] = {}
        for room in allrooms:
            save["rooms"][room] = allrooms[room]
        with open('savedat2.txt', 'wb') as fh:
            pickle.dump(save, fh)
        print("Saved.")
    #load (not updated)
    elif command == "load":
        savefile = open("savedat2.txt", "rb")
        loadedsave = pickle.load(savefile)
        player = loadedsave["player"]
        for room in loadedsave["rooms"]:
            allrooms[room] = loadedsave["rooms"][room]
        place = allrooms[loadedsave["place"]]
        print(F_C)
        print("Loaded.")
        savefile.close()
    #if the command is valid, but cannot be done in the current room
    elif command in allcommands:
        print("You cannot do that here.")
    #if the command is not valid (and is not "quit"), print a similar command
    elif not command == "quit":
        print("command '" + command + "' not found.")
        print("did you mean: " + findsimilar(command, allcommands))












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

gosoccerboy5 wrote:

You should use/sign up for replit or github, its worth it

ScratchCatHELLO wrote:

Delta135 wrote:

Make one, it's free!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
…real estate

I can't
believe me, I want to












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

i am finally finishing up your text adventure, ScratchCatHELLO.

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

It is done and published as an app. Here:


ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Delta135 wrote:

It is done and published as an app. Here:


wow, thanks!

I'm working on making a path to the mountain, and I've also added a number of things to the dialogue system (mostly under the hood), such as the ability to execute functions in dialogue.












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

funny glitch devlog[0]:

I accidentally placed a creature in the item slot of a room instead of the creatures slot and was surprised that I couldn't talk to it until I realized I could pick it up.

Last edited by ScratchCatHELLO (May 9, 2021 21:39:34)













enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

Can I have the new code after you update it? Oh, and you have to make the ending lines of code like this or else the quit function says "You cannot do that here and crashes:

    elif not command in allcommands:
        print("You cannot do that here.")
    #if the command is not valid (and is not "quit"), print a similar command
    elif not command == "quit":
        print("command '" + command + "' not found.")
        print("did you mean: " + findsimilar(command, allcommands))
    elif command == "quit":
        print("Goodbye, " + player.name)

Delta135
Scratcher
100+ posts

PyRPG (Python Text Adventure)

Although I do have the save/load functions removed… your code may look different

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

Delta135 wrote:

Can I have the new code after you update it? Oh, and you have to make the ending lines of code like this or else the quit function says "You cannot do that here and crashes:

    elif not command in allcommands:
        print("You cannot do that here.")
    #if the command is not valid (and is not "quit"), print a similar command
    elif not command == "quit":
        print("command '" + command + "' not found.")
        print("did you mean: " + findsimilar(command, allcommands))
    elif command == "quit":
        print("Goodbye, " + player.name)

yeah, I noticed that when I saw your screenshot. I'll fix it (I forgot to because I got into the habit of ending the script by using ctrl-c before there was a quit command)












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

ScratchCatHELLO
Scratcher
1000+ posts

PyRPG (Python Text Adventure)

so here's the new path so far (I haven't added everything yet, because I don't have a combat system yet):

#uses new engine
import pickle
from difflib import SequenceMatcher
import re
#find the item of a list that is closest to a string
def findsimilar(thing, inlist):
    similar = {}
    for item in inlist:
        similar[item] = SequenceMatcher(None, item, thing).ratio()
    return list(reversed(sorted(similar.items(),key=lambda x:x[1])))[0][0]
class Creature:
    def __init__(self, name, dialog, inventory, stats, attackable):
        self.name = name
        self.dialog = dialog
        self.inventory = inventory
        self.stats = stats
        self.attackable = attackable
class Player:
    def __init__(self, name, flags, inventory, stats):
        self.name = name
        self.flags = flags
        self.inventory = inventory
        self.stats = stats
#item class
class Item:
    def __init__(self, name, description, detail):
        self.name = name
        self.description = description
        self.detail = detail
#weapon subclass of item
class Weapon(Item):
    def __init__(self, name, description, detail, atkstr):
        super().__init__(name, description, detail)
        self.atkstr = atkstr
#room class definition
class Room:
    def __init__(self, name, directions, descriptions, items, creatures):
        self.name = name
        self.directions = directions
        self.descriptions = descriptions
        self.items = items
        self.creatures = creatures
Start = Room (
    "Start Crossroads",
    {
    "south": "Forest Exit",
    "west": "Mountain Trail"
    },
    {
    "normal": "The entrance to the town of Qwertyuiopasdfghjkl.",
    "detail": "The sign reads \"Qwertyuiopasdfghjkl; Gur gbja bs xrlobneq fznfu.\" \nThe town is to the north.\nTo the south lies a dense forest. \nTo the west is a trail that leads to a distant mountain.\nTo the east is a bridge over a rushing river."
    },
    {},
    {}
)
#forest region
F_Ex = Room(
    "Forest Exit",
    {
    "south": "Forest Clearing",
    "north": "Start Crossroads"
    },
    {
    "normal": "The trail on which you came.",
    "detail": "A dark forest trail. This place makes you jumpy. \nThe trail continues south."
    },
    {},
    {}
)
F_C = Room(
    "Forest Clearing",
    {
    "north": "Forest Exit",
    "west": "Forest Trapdoor"
    },
    {
    "normal": "A rocky clearing in the forest.",
    "detail": "The trail widens out into a clearing.\nThere is a trapdoor in the ground to the west that you hadn't noticed before.\nThe trail continues north and south."
    },
    {},
    {}
)
hintrock = Item("rock", "A rock with writing on it. You can't make out the words.", "The rock reads \"[Oo]pen ([Ss]esame[.!]|[Uu]p[!.])\"...\nIt's in the ancient language of R'jex!")
F_T = Room(
    "Forest Trapdoor",
    {
    "east": "Forest Clearing"
    },
    {
    "normal": "A forest clearing. Below you is a trapdoor.",
    "detail": "The trapdoor is locked. \nYou may go back east into the main clearing."
    },
    {
    "hintrock": hintrock
    },
    {}
)
F_En = Room(
    "Forest Entrance",
    {
    "north": "Forest Clearing"
    },
    {
    "normal": "The entrance to the forest.",
    "detail": "A dark, thin forest trail. The forest gradually thins into a plains.\nYou may go north back into the clearing."
    },
    {},
    {}
)
sword = Weapon("sword", "A faintly glowing blue sword...\nHow cliche.", "There are various symbols etched into the blade that glow brighter.", 10)
F_SR = Room(
    "Sword Room",
    {
    "up": "Forest Trapdoor"
    },
    {
    "normal": "A dim, small, stone room.",
    "detail": "A sword sits on the pedestal in the center. \nThe only way to go in the cramped room is up."
    },
    {"sword": sword},
    {}
)
#end forest region
#mountain region
M_T = Room(
    "Mountain Trail",
    {
    "east": "Start Crossroads",
    "west": "Mountain Trail Bench"
    },
    {
    "normal": "A dirt trail through the grassy plains.",
    "detail": "The mountain looms tall in the distance, surrounded by a vast, grassy plain.\nThe trail extends far to the west and east."
    },
    {},
    {}
)
def givemountgear():
    if "mountgear" in garret.inventory:
        player.inventory["mountgear"] = garret.inventory["mountgear"]
        garret.inventory.pop("mountgear")
        M_M.directions["up"] = "Mountain Peak"
        print("He says 'Here, have this mountaineering gear.' and gives you an assortment of mountain-climbing gear.")
#I'm bad at naming things, okay?
garretdialog = {
    "INITIAL": "intro",
    "intro": {
        "text": "The man introduces himself as Garret Eastmund.\nHe asks what you're doing so far out of town.",
        "responses": {
            "A": {
                "text": "I'm not from here, actually.",
                "newdialog": "traveller"
            },
            "B": {
                "text": "I'm on an adventure!",
                "newdialog": "adventurer"
            },
            "C": {
                "text": "I want to see the mountain.",
                "newdialog": "mountaineer"
            },
            "D": {
                "text": "I don't know, why are you?",
                "newdialog": "backstory"
            }
        }
    },
    "traveller": {
        "text": "He looks suprised.\n'We don't get many travellers here. Why have you come all the way here?' he asks.",
        "responses": {
            "A": {
                "text": "I'm on an adventure!",
                "newdialog": "adventurer"
            },
            "B": {
                "text": "I want to climb the mountain.",
                "newdialog": "mountaineer"
            },
            "C": {
                "text": "I want to see the world!",
                "newdialog": "adventurer"
            },
            "D": {
                "text": "It's a secret.",
                "newdialog": "unknown"
            }
        }
    },
    "adventurer": {
        "text": "'Exciting! However, I'm afraid there isn't much to explore around here.'\nHe gestures around at the empty plains.",
        "responses": {
            "A": {
                "text": "I want to scale that mountain.",
                "newdialog": "mountaineer"
            },
            "B": {
                "text": "I want to explore the village.",
                "newdialog": "tourist"
            }
        }
    },
    "mountaineer": {
        "text": "'You want to climb the mountain, eh? That's quite the journey. Good luck on your quest!'",
        "execute": givemountgear
    },
    "backstory": {
        "text": "'I like this spot. It gives me a nice view. The land here is so flat you can see for miles. I enjoy reading here, too'. He holds up a book.",
        "newdialog": "unknown"
    },
    "unknown": {
        "text": "'Well, I wish you luck with... whatever you're doing!' he says. Then he starts reading a book."
    },
    "tourist": {
        "text": "'I think you've gone the wrong way, then.' he smiles and says 'We don't really have the most exciting sights, but I hope you enjoy your tour!'"
    }
}
mountgear = Item("mountain gear", "Mountaineering tools", "This will come in handy for the climb.")
garret = Creature("man", garretdialog, {"mountgear": mountgear}, {}, False)
M_Be = Room(
    "Mountain Trail Bench",
    {
    "east": "Mountain Trail",
    "west": "Mountain Base"
    },
    {
    "normal": "A trail through the plains, with a bench at its side.",
    "detail": "To the side of the trail is a bench, on which sits a man.\nThe trail extends west and east."
    },
    {},
    {"garret": garret}
)
M_Ba = Room(
    "Mountain Base",
    {
    "east": "Mountain Trail Bench",
    "west": "Lower Mountain"
    },
    {
    "normal": "The base of the mountain.",
    "detail": "The mountain looked giant from a distance, but it looks titanic from here. It's a long way up, and you shouldn't go without the proper gear. The trail stretches almost to the horizon to the east and the mountain looms tall to the west."
    },
    {},
    {}
)
M_L = Room(
    "Lower Mountain",
    {
    "east": "Mountain Base",
    "west": "Central Mountain"
    },
    {
    "normal": "The lower third of the mountain.",
    "detail": "The lowest section of the mountain is heavily forested and full of life. You can hear animals all around you. To the east is the foot of the mountain, and the mountain's peak is far above to the west."
    },
    {},
    {}
)
M_M = Room(
    "Central Mountain",
    {
    "east": "Lower Mountain",
    "west": "Mountain Cave"
    },
    {
    "normal": "The middle of the mountain.",
    "detail": "The forest thinned out and now there are only a few trees here. Vegetation and life are sparse up here. It's starting to get cold.\nThe summit above has a steep slope and you will need to go directly up. You cannot climb to the peak without proper gear. To your east is the forested bottom of the mountain. To the west is a cave out of which smoke is flowing."
    },
    {},
    {}
)
gem = Item("gem", "A glowing ruby", "I wonder what this'll be useful for...")
M_P = Room(
    "Mountain Peak",
    {
    "down": "Central Mountain"
    },
    {
    "normal": "The peak of the mountain.",
    "detail": "You've finally done it. It was a long climb, but you've reached the summit. There is a small, glowing gem on the top of the peak.\nThe only way to go is down."
    },
    {"gem": gem},
    {}
)
sign = Item("sign", "It reads 'sorry, but I'm not ambitious enough to put a dragon here just yet. After all, I don't have a combat system.'", "This sign is very strange. Who knows who wrote it?")
M_C = Room(
    "Mountain Cave",
    {
    "east": "Central Mountain"
    },
    {
    "normal": "A large cave inside of the mountain.",
    "detail": "The cave's roof withholds a large quantity of smoke. On the ground there is a vast treasure hoard. This looks like the sort of cave a dragon might inhabit.\nThe cave's exit is to your east."
    },
    {"sign": sign},
    {}
)
#end mountain region
allrooms = {
    "Start Crossroads": Start,
    "Forest Exit": F_Ex,
    "Forest Clearing": F_C,
    "Forest Entrance": F_En,
    "Forest Trapdoor": F_T,
    "Sword Room": F_SR,
    "Mountain Trail": M_T,
    "Mountain Trail Bench": M_Be,
    "Mountain Base": M_Ba,
    "Lower Mountain": M_L,
    "Central Mountain": M_M,
    "Mountain Peak": M_P,
    "Mountain Cave": M_C
}
allcommands = ["load", "save", "inspect", "inventory", "help", "instructions", "drop", "grab", "look at", "look", "up", "down", "north", "south", "east", "west"]
name = input("What is your name?\n")
if name:
    player = Player(name, {}, {}, {})
else:
    player = Player("Johnus Doeus", {}, {}, {})
#starting room
place = Start
#allow user to quit
command = ""
while not command == "quit":
    #show the normal description of the room
    print(place.descriptions["normal"])
    #list items in the room
    for item in place.items:
        print("There is a " + place.items[item].name + " here.")
    #list creatures in the room
    for creature in place.creatures:
        print("There is a " + place.creatures[creature].name + " in the room.")
    #get input
    command = input(player.name + ">")
    #allow player to move
    if command in place.directions:
        place = allrooms[place.directions[command]]
    elif place.name == "Forest Trapdoor" and command == "down":
        if re.search("[Oo]pen ([Ss]esame[.!]|[Uu]p[!.])", input("What is the password?\n")):
            print("The trapdoor glows faintly and creaks open.")
            place.directions["down"] = "Sword Room"
            place.descriptions["detail"] = "The trapdoor is locked. \nYou may go back east into the main clearing.\nYou can also climb down through the trapdoor."
        else:
            print("Nothing happens.")
    elif command in ["up", "down", "north", "south", "east", "west"]:
        print("You cannot go " + command)
    #print all command names (add descriptions?)
    elif command == "help":
        for command in allcommands:
            print(command)
    #print instuctions
    elif command == "instructions":
        print("There isn't much to just yet.\nYou can type 'help' for a list of commands.\nYou can type 'quit' to quit.\nYou can look around with 'look'\nYou can pick up and drop items with 'grab ___' and 'drop ___'\nYou can open your inventory with 'inventory'\nYou can inspect items you are holding with 'inspect ___'\nYou can look at items you aren't holding with 'look at ___'\nYou can talk to creatures by typing 'talk to ___'\nYou can load and save (EXPIREMENTAL) with 'load' and 'save'")
    #allow player to look at items they aren't holding
    elif command[0:7] == "look at":
        if command.replace("look at", ""):
            for item in place.items:
                if place.items[item].name == command.replace("look at ", ""):
                    print(place.items[item].description)
        else:
            print("look at what?")
    #deeper descriptions
    elif command == "look":
        print(place.descriptions["detail"])
    #allow player to grab items
    elif command[0:4] == "grab":
        if command.replace("grab", ""):
            #figure out what they're grabbing
            tmpitem = ""
            for item in place.items:
                if place.items[item].name == command.replace("grab ", ""):
                    #python gets upset when I put the code in this loop
                    tmpitem = item
                    break
            if tmpitem:
                print(place.items[tmpitem].name + " grabbed!")
                if place.items[tmpitem].name == "mountain gear":
                    M_M.directions["up"] = "Mountain Peak"
                if place.name == "Mountain Peak" and place.items[tmpitem].name == "gem":
                    M_P.descriptions["detail"] = "You've finally done it. It was a long climb, but you've reached the summit.\nThe only way to go is down."
                if place.name == "Sword Room" and place.items[tmpitem].name == "sword":
                    place.descriptions["detail"] = "There is an empty pedestal in the center of the room. The only way to go in the cramped room is up."
                #copy item into inventory and remove item from room
                player.inventory[tmpitem] = place.items[tmpitem]
                place.items.pop(tmpitem)
            else:
                print("There is no " + command.replace("grab ", "") + " here.")
        else:
            print("Grab what?")
    #allow player to drop items (does the inverse of "grab")
    elif command[0:4] == "drop":
        if command.replace("drop", ""):
            tmpitem = ""
            for item in player.inventory:
                if player.inventory[item].name == command.replace("drop ", ""):
                    tmpitem = item
                    break
            if tmpitem:
                print(player.inventory[tmpitem].name + " dropped!")
                if player.inventory[tmpitem].name == "mountain gear":
                    M_M.directions.pop("up")
                if place.name == "Mountain Peak" and player.inventory[tmpitem].name == "gem":
                    M_P.descriptions["detail"] = "You've finally done it. It was a long climb, but you've reached the summit. There is a small, glowing gem on the top of the peak.\nThe only way to go is down."
                if place.name == "Sword Room" and player.inventory[tmpitem].name == "sword":
                    place.descriptions["detail"] = "A sword sits on the pedestal in the center. The only way to go in the cramped room is up."
                #copy item into inventory and remove item from room
                place.items[tmpitem] = player.inventory[tmpitem]
                player.inventory.pop(tmpitem)
            else:
                print("You don't have a " + command.replace("drop ", "") + ".")
        else:
            print("Drop what?")
    #show the player's inventory (make this better later)
    elif command == "inventory":
        for item in player.inventory:
            print(player.inventory[item].name)
            print(player.inventory[item].description)
    #show detailed description for items in inventory
    elif command[0:7] == "inspect":
        if command.replace("inspect ", ""):
            for item in player.inventory:
                if player.inventory[item].name == command.replace("inspect ", ""):
                    print(player.inventory[item].detail)
        else:
            print("Inspect what?")
    #allow player to talk to creatures
    elif command[0:7] == "talk to":
        activecreature = ""
        #figure out what creature the player is talking to
        for creature in place.creatures:
            if place.creatures[creature].name == command.replace("talk to ", ""):
                activecreature = place.creatures[creature]
                break
        if activecreature:
            userresp = ""
            #get the initial dialog snippet
            currentdialog = activecreature.dialog[activecreature.dialog["INITIAL"]]
            while not userresp == "goodbye":
                print(currentdialog["text"])
                #run events
                if "execute" in currentdialog:
                    currentdialog["execute"]()
                #instant dialog transitions
                if "newdialog" in currentdialog:
                    currentdialog = activecreature.dialog[currentdialog["newdialog"]]
                    continue
                #print possible responses
                if "responses" in currentdialog:
                    for response in currentdialog["responses"]:
                        print(response + ": " + currentdialog["responses"][response]["text"])
                else:
                    break
                userresp = input(">").upper()
                if userresp in currentdialog["responses"]:
                    try:
                        print("You say '" + currentdialog["responses"][userresp]["text"] + "' to the " + activecreature.name)
                        #set the current dialog snippet to the new dialog snippet
                        currentdialog = activecreature.dialog[currentdialog["responses"][userresp]["newdialog"]]
                    except:
                        break
                elif not userresp == "goodbye":
                    #tell user if they didn't type a valid response
                    print("'" + userresp + "' is not a valid response.")
    #save (not updated)
    elif command == "save":
        save = {}
        save["player"] = player
        save["place"] = place.name
        save["rooms"] = {}
        for room in allrooms:
            save["rooms"][room] = allrooms[room]
        with open('savedat2.txt', 'wb') as fh:
            pickle.dump(save, fh)
        print("Saved.")
    #load (not updated)
    elif command == "load":
        savefile = open("savedat2.txt", "rb")
        loadedsave = pickle.load(savefile)
        player = loadedsave["player"]
        for room in loadedsave["rooms"]:
            allrooms[room] = loadedsave["rooms"][room]
        place = allrooms[loadedsave["place"]]
        print(F_C)
        print("Loaded.")
        savefile.close()
    #if the command is valid, but cannot be done in the current room
    elif command in allcommands:
        print("You cannot do that here.")
    #if the command is not valid (and is not "quit"), print a similar command
    elif not command == "quit":
        print("command '" + command + "' not found.")
        print("did you mean: " + findsimilar(command, allcommands))












enter command
West of House
This is an open field west of a white house, with a boarded front door.
There is a small mailbox here.
A rubber mat saying 'Welcome to Zork!' lies by the door.

>examine mailbox
I see nothing special about the mailbox.

>
















Python 3 Text Adventure
cool new browser game - cursed laughing-crying emoji - Illuminati - you know waterbenders, but do you know stock-imagebenders? - snek - vibin' - Bump song (vevo) - Speed bump - yee - fred - m i c k e y



ScratchCatHELLO
I have 4300+ posts, I've been on scratch for 3 years, I'm a Forum Helper™ and I have a Scratch Wiki account!
I like: Python, CSS, Javascript, Rust

Powered by DjangoBB

Standard | Mobile