def create():
    """
    Sets game objects at initial state and returns them.
    """
    # Declare the player
    state["player"] = Player()

    # Declare the actions
    state["action"] = {
        "attack":
        Action(name="attack",
               grammar={
                   "d_obj_required": True,
                   "preps_accepted": ("with", "using"),
               },
               run=run["attack"]),
        "die":
        Action(name="die",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["die"]),
        "drop":
        Action(name="drop",
               grammar={
                   "d_obj_required": True,
                   "i_obj_prohibited": True,
               },
               run=run["drop"]),
        "eat":
        Action(name="eat",
               grammar={
                   "d_obj_required": True,
                   "i_obj_prohibited": True,
               },
               run=run["eat"]),
        "get":
        Action(name="get",
               grammar={
                   "d_obj_required": True,
                   "i_obj_prohibited": True,
               },
               run=run["get"]),
        "go":
        Action(name="go", grammar={
            "adv_required": True,
        }, run=run["go"]),
        "help":
        Action(name="help",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["help"]),
        "inventory":
        Action(name="inventory",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["inventory"]),
        "load":
        Action(name="load",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["load"]),
        "look":
        Action(name="look",
               grammar={
                   "d_obj_prohibited":
                   True,
                   "preps_accepted": (
                       "at",
                       "in",
                       "into",
                       "inside",
                       "beneath",
                       "underneath",
                       "under",
                       "below",
                   )
               },
               run=run["look"]),
        "quit":
        Action(name="quit",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["quit"]),
        "save":
        Action(name="save",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_prohibited": True,
               },
               run=run["save"]),
        "talk":
        Action(name="talk",
               grammar={
                   "d_obj_prohibited": True,
                   "i_obj_required": True,
                   "preps_accepted": (
                       "to",
                       "with",
                       "at",
                   )
               },
               run=run["talk"]),
        "use":
        Action(name="use",
               grammar={
                   "d_obj_required": True,
                   "preps_accepted": (
                       "with",
                       "on",
                   )
               },
               run=run["use"]),
        "wait":
        Action(name="wait", grammar={}, run=run["wait"]),
    }

    # Declare the items
    state["item"] = {
        "fists":
        Weapon(
            slug="fists",
            name=text_style['item']("fists"),
            long_name=f"your {text_style['item']('fists')}",
            desc=None,
            stats={
                "damage": 1,
                "accuracy": 0.9
            },
            attack_text=
            (f"You pretend you're a boxer and attempt a left hook with your {text_style['item']('fists')}.",
             f"You leap forward, putting your {text_style['item']('fists')} in front of you in the hope that they "
             f"do some damage.",
             f"You swing your {text_style['item']('fists')} around in your best imitation of a helicopter."
             ),
            tags=["obtainable"]),
        "knife":
        Weapon(
            slug="knife",
            name=text_style['item']("knife"),
            long_name=f"a {text_style['item']('knife')}",
            desc=text_style['desc']
            ("It's a knife. Like for cutting your steak with, except designed for steak that is actively trying to "
             "kill you. "),
            weight=2,
            stats={
                "damage": 2,
                "accuracy": 0.95
            },
            attack_text=(
                f"Gripping your {text_style['item']('knife')} in a {text_style['item']('knife')}-like manner, you "
                f"stab with the stabby part.",
                f"You slash forward with your {text_style['item']('knife')}, praying for a hit.",
            ),
            tags=["obtainable"]),
        "sword":
        Weapon(
            slug="sword",
            name=text_style['item']("sword"),
            long_name=f"a {text_style['item']('sword')}",
            desc=text_style['desc']
            ("This sword has seen better days, but it's probably got one or two good swings left in it."
             ),
            weight=3,
            stats={
                "damage": 3,
                "accuracy": 0.8
            },
            attack_text=(
                f"You swing wildly with your {text_style['item']('sword')}.",
            ),
            tags=["obtainable"]),
        "lantern":
        LightSource(
            slug="lantern",
            name=text_style['item']("lantern"),
            long_name=f"an extinguished {text_style['item']('lantern')}",
            desc=text_style['desc']
            ("The lantern is unlit. It has fuel though; you imagine you could get it lit if you had some matches."
             ),
            weight=1,
            tags=["obtainable"]),
        "amulet_of_yendor":
        Item(slug="amulet_of_yendor",
             name=text_style['item']("Amulet of Yendor"),
             long_name=f"the {text_style['item']('Amulet of Yendor')}",
             desc=text_style['desc'](
                 "This amulet is said to contain unimaginable power."),
             weight=0.5,
             tags=["obtainable"]),
        "cheese":
        Item(slug="cheese",
             name=text_style['item']("cheese"),
             long_name=f"a hunk of {text_style['item']('cheese')}",
             desc=text_style['desc'](
                 "It is a hunk of cheese. Looks all right."),
             weight=0.25,
             tags=["obtainable", "food"]),
        "goblin_corpse":
        Item(
            slug="goblin_corpse",
            name=text_style['item']("goblin corpse"),
            long_name=f"a {text_style['item']('goblin corpse')}",
            desc=text_style['desc']
            (f"It's a dead goblin. You turn it over, looking for valuables, but all you can find is "
             f"a\\crumpled {text_style['item_in_desc']('matchbook')}, which falls to the floor next to the corpse. "
             ),
            tags=["corpse"]),
        "lever":
        Item(
            slug="lever",
            name=text_style['item']("lever"),
            long_name=
            f"a {text_style['item']('lever')} jutting from the cliff side",
            desc=text_style['desc']
            ("It looks close enough to reach. Your fingers twitch. You never could resist a good lever."
             )),
        "matchbook":
        Item(
            slug="matchbook",
            name=text_style['item']("matchbook"),
            long_name=f"a {text_style['item']('matchbook')}",
            desc=text_style['desc']
            ("At first glance, the crumpled matchbook appears to be empty, but looking closer,\\you see it still "
             "has a few matches inside. "),
            weight=0.1,
            tags=["obtainable"]),
        "rope":
        Item(slug="rope",
             name=text_style['item']("rope"),
             long_name=f"some {text_style['item']('rope')}",
             desc=text_style['desc']("Good, sturdy rope, about 50 feet long."),
             weight=2,
             tags=["obtainable"]),
    }

    # Declare the rooms
    state["room"] = {
        "outside":
        Room(
            slug="outside",
            name="Outside Cave Entrance",
            desc=text_style['desc']
            (f"{text_style['dir_in_desc']('North')} of you, the cave mouth beckons."
             ),
            no_mobs=True,
        ),
        "foyer":
        Room(
            slug="foyer",
            name="Foyer",
            desc=text_style['desc']
            (f"Dim light filters in from the {text_style['dir_in_desc']('south')}. Dusty passages "
             f"run {text_style['dir_in_desc']('north')} and {text_style['dir_in_desc']('east')}."
             ),
            init_items=[state["item"]["sword"]],
        ),
        "overlook":
        Room(
            slug="overlook",
            name="Grand Overlook",
            desc=text_style['desc']
            (f"A steep cliff appears before you, falling into the darkness. Ahead to the "
             f"{text_style['dir_in_desc']('north')}, a lightflickers in the distance, but there is no way across "
             f"the chasm. A passage leads {text_style['dir_in_desc']('south')},away from the cliff."
             ),
            init_items=[state["item"]["rope"]],
        ),
        "narrow":
        Room(
            slug="narrow",
            name="Narrow Passage",
            desc=text_style['desc']
            (f"The narrow passage bends here from {text_style['dir_in_desc']('west')} to "
             f"{text_style['dir_in_desc']('north')}. The smell of gold permeates the air."
             ),
        ),
        "treasure":
        Room(
            slug="treasure",
            name="Treasure Chamber",
            desc=text_style['desc']
            (f"You've found the long-lost treasure chamber! Sadly, it has already been completely emptied "
             f"byearlier adventurers. The only exit is to the {text_style['dir_in_desc']('south')}."
             ),
            init_items=[state["item"]["lantern"]],
        ),
        "chasm":
        Room(
            slug="chasm",
            name="Over The Edge",
            desc=text_style['desc']
            (f"You find yourself suspended over a dark chasm, at the end of a rope that was clearly notlong "
             f"enough for this job. Glancing about, you see a {text_style['item_in_desc']('lever')} jutting out "
             f"from the wall, half hidden.The rope leads back {text_style['dir_in_desc']('up')}."
             ),
            dark=True,
            dark_desc=text_style['desc']
            (f"You find yourself suspended over a dark chasm, at the end of a rope that was clearly notlong "
             f"enough for this job. It is dark. You can't see a thing. You are likely to be eaten by a grue.The "
             f"rope leads back {text_style['dir_in_desc']('up')}."),
            no_mobs=True,
            no_drop=True,
            init_items=[state["item"]["lever"]]),
        "final":
        Room(
            slug="final",
            name="Across the Chasm",
            desc=text_style['desc']
            (f"You find a small, elaborately decorated room. Sunlight streams down a hole in the ceiling "
             f"highabove you, illuminating an altar upon which sits the fabled "
             f"{text_style['item_in_desc']('Amulet of Yendor')}.To the {text_style['dir_in_desc']('south')}, a "
             f"bridge leads back the way you came."),
            init_items=[state["item"]["amulet_of_yendor"]]),
    }

    # Declare the mobs
    mob_types = {
        "goblin":
        lambda mob_id:
        Mob(mob_id=mob_id,
            name=text_style['mob']("goblin"),
            long_name=f"a {text_style['mob']('goblin')}",
            desc=text_style['desc']
            (f"The {text_style['mob_in_desc']('goblin')} is eyeing you warily and shuffling his weight from one "
             f"foot to the other.A crude knife dangles from his belt."),
            text={
                "enter":
                (f"A {text_style['mob']('goblin')} shuffles into the room. At the sight of you, he gives a squeal "
                 f"of surprise and bares his teeth.", ),
                "exit":
                (f"The {text_style['mob']('goblin')} skitters out of the room, heading ",
                 ),
                "idle": (
                    f"The {text_style['mob']('goblin')} grumbles nervously about how crowded the cave has "
                    f"gotten lately.",
                    f"The {text_style['mob']('goblin')} pulls out a knife, then thinks better of it and puts "
                    f"the knife back.",
                    f"The {text_style['mob']('goblin')} is momentarily transfixed by a rash on his elbow.",
                ),
                "dodge_success":
                (f"The {text_style['mob']('goblin')} leaps back, emotionally scarred by your violent outburst "
                 f"but physically unharmed.", ),
                "dodge_fail":
                (f"The {text_style['mob']('goblin')} staggers back, wounded physically (and emotionally).",
                 ),
                "dead":
                (f"The {text_style['mob']('goblin')} cries out in shock as your attack connects. He gives you a "
                 f"baleful glare that fades intoa look of weary resignation as he slumps to the ground, dead.",
                 ),
                "attack_success":
                (f"The {text_style['mob']('goblin')} whips its knife out towards you in a desperate arc. It carves "
                 f"into you.", ),
                "attack_fail":
                (f"The {text_style['mob']('goblin')} whips its knife out towards you in a desperate arc. You dodge "
                 f"nimbly out of the way.", ),
                "kill_player":
                (f"The {text_style['mob']('goblin')} screams at you and flies forward, plunging its knife into "
                 f"your chest. You final thought,improbably, is a silent prayer that the "
                 f"{text_style['mob']('goblin')}'s filthy knife doesn't give you an infection.",
                 )
            },
            stats={
                "health": 10,
                "damage": 2,
                "accuracy": .75,
                "evasion": .15
            },
            init_loc=state["room"]["foyer"],
            init_att="neutral",
            items=([state["item"]["goblin_corpse"]]))
    }
    state["mobs"] = [mob_types["goblin"](1)]

    # Link rooms together
    state["room"]["outside"].n_to = (state["room"]["foyer"],
                                     "You step into the mouth of the cave.")
    state["room"]["foyer"].s_to = (
        state["room"]["outside"],
        "You head south, and find yourself outside the cave.")
    state["room"]["foyer"].n_to = (
        state["room"]["overlook"],
        "You make your way north, and the cave opens up suddenly, revealing a vast chasm before you."
    )
    state["room"]["foyer"].e_to = (
        state["room"]["narrow"],
        "You take the eastern passage. It grows narrower until you have a hard time standing straight."
    )
    state["room"]["overlook"].s_to = (
        state["room"]["foyer"],
        "You step back from the cliff's edge and head south.")
    state["room"]["overlook"].n_to = (
        state["room"]["overlook"],
        "You take a step back, and get ready to jump over the gap. Then you realize that is "
        f"an incredibly stupid idea, and decide you would rather live.")
    state["room"]["narrow"].w_to = (
        state["room"]["foyer"],
        "You move west through the cramped passage until it opens up a bit.")
    state["room"]["narrow"].n_to = (state["room"]["treasure"],
                                    "You follow your nose and head north.")
    state["room"]["treasure"].s_to = (
        state["room"]["narrow"], "You head south into the narrow passage.")
    state["room"]["chasm"].u_to = (
        state["room"]["overlook"],
        "You climb slowly back up the rope, and pull yourself back onto the overlook, panting."
    )
    state["room"]["final"].s_to = (
        state["room"]["overlook"],
        "You go back across the bridge, resisting the pull of the amulet.")

    # Set initial room
    state["player"].loc = state["room"]["outside"]

    # Add functionality to items
    state["item"]["sword"].use = use_sword
    state["item"]["rope"].use = use_rope
    state["item"]["lantern"].use = use_lantern
    state["item"]["matchbook"].use = use_matchbook
    state["item"]["goblin_corpse"].on_look = on_look_goblin_corpse
    state["item"]["lever"].use_from_env = use_from_env_lever

    return state
Beispiel #2
0
from room import Room
from player import Player
from item import Item, Treasure, LightSource
import textwrap
import sys
# Declare all the rooms

room = {
    'outside':
    Room("Outside Cave Entrance", "North of you, the cave mount beckons",
         [LightSource("lamp", "a battered old lamp with some oil in it")],
         True),
    'bridge':
    Room(
        "Bridge",
        """Rough winds blow acoss a lonely bridge. The smell of dragon fire and brimstone is heavy here.
On the other side you see a red dragon sleeping in the sunlight. It guards the entrance to an ancient cathedral""",
        [], True),
    'cathedral':
    Room(
        "Cathedral",
        """Broken pews, torn tapestries, and skeletons of past adventurers are all that remain inside.
At the end, sunlight illuminates the lady's chapel. You see a crack in the wall.""",
        [Treasure("ruby", "crimson red jewel worn by ancient priests", 10000)],
        False),
    'foyer':
    Room(
        "Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [
            LightSource("torch",
                        "an everlasting torch that gives off a yellow light"),
Beispiel #3
0
from item import Item

from item import LightSource

import os

# Declare all the rooms

room = {
    'outside':
    Room("Outside Cave Entrance", "North of you, the cave mount beckons", [],
         True),
    'foyer':
    Room(
        "Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [LightSource("lamp", "An old lamp")]),
    'overlook':
    Room(
        "Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""",
        [Item("fork", "Used for stabbing ... or eating")]),
    'narrow':
    Room(
        "Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", []),
    'treasure':
    Room(
        "Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south.""", []),
Beispiel #4
0
chest = Treasure(
    'Treasure Chest - [chest]', """An old pirate relic, overflowing with 
    bullions and gems""", 'chest', 100)
ring = Treasure(
    "Princess Fiora's Ring - [ring]",
    """A ring granting the wearer god-like beauty and charm,
    but removing the ability to love""", 'ring', 125)
crown = Treasure(
    "King Arthur's Crown - [crown]",
    """Rumored among mystics and trobadours to grant
the wearer the ability to read the minds of others""", 'crown', 250)
grail = Treasure(
    'Holy Grail - [grail]', """The enchanted chalice of life. It looks benign 
    now, but perhaps in the proper hands...""", 'grail', 375)
candle = LightSource('Magic Candle', """Your true source of light""", 'candle',
                     10)

#// ******************
# Assign Items to Rooms

room['treasure'].add_items(chest, grail)
room['narrow'].add_items(ring)
room['overlook'].add_items(crown)
room['foyer'].add_items(candle)

allowed_moves = [
    'n', 'e', 's', 'w', 'q', 'i', 'items', 'inventory', 'quit', 'score'
]


def action(phrase, lit):
Beispiel #5
0
from room import Room
from player import Player
from weapon import Weapon
from item import Item
from item import Treasure
from item import LightSource
from time import sleep
import random
import os 
# Declare all the rooms
lights = {
    "flashlight": LightSource("flashlight", "The flashlight helps you see better but can also be used as a weapon careful if you use it as a weapon it may not work anymore as a visual aid."),
    "latern" : LightSource("latern", "use this to see in dark rooms, able to use underwater, may break if dropped"),
    "torch" : LightSource("torch", "use as a light source torch stakes do not stay lit when wet"),
}

items = {
    "shovel": Item("shovel", "Use this to dig or hit with manually droppable item"),
    "sword": Item("sword", "Use this to chop or slice manually droppable item"),
    "spells": Item("spells", "Book of spells manually droppable item"),
    "bat": Item("bat", "Use this to knock down or hit with manually droppable item"),
    "gun": Item("gun", "Shoot with this manually droppable item"),
    "extinguisher": Item("extinguisher", "Put out fires or use as a decoy, manually droppable item"),
    "coins": Item("coins", "coins count as points, every room has coins This item cannot be mannually dropped"),
    "key": Item("key", "Master key that can unlock anything might be worth holding on to."),
    "scuba": Item("scuba", "Scuba Mask allows you to breathe under water for extended periods of time.")
}

treasures = {
    "gold": Treasure(1000, "gold", "Chest full of Gold. The chest features 1000 points worth of gold. You will need a master key to unlock it!"),
    "silver": Treasure(500, "silver", "500 points worth of valuable silver at the bottom of the pool. YOu will need a scuba mask due the pool being 50 feet deep. Silvers at the bottom."),
Beispiel #6
0
from item import Item, Treasure, LightSource

starter_lantern = LightSource('Lantern', 'Adding while testing')

items = [
    Treasure('Helmet', "A bronze helmet. Slightly dented, but still intact", 250),
    Treasure('Bracers', 'Leather bracers. May cause chafing', 100),
    Treasure('Pants', 'Will DEFINITELY cause chafing', 300),
    Treasure('Chestpiece', 'Strong iron chestpiece', 750),
    Treasure('Sword', 'Slightly dull, but will lay some hurt', 500),
    Item('Tome', 'Maybe someone will pay for this'),
    Item('Fork', 'Looks to be silver plated and thus worthless, why take it?'),
    LightSource('Torch', 'Good for light AND setting things on fire!')
]
Beispiel #7
0
from room import Room
from player import Player
from item import Item
from item import LightSource
from item import Treasure


item = {
    "key": Item("key", "a small golden key"),
    "rock": Item("rock", "just a small rock"),
    "torch": LightSource("torch", "a torch with a flame"),
    "coins": Treasure("coins", "a pouch filled with golden coins", 5),

}

# Declare all the rooms

room = {
    'outside':  Room("Outside Cave Entrance",
                     "North of you, the cave mount beckons", [item["rock"]], True),

    'foyer':    Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [item["key"]], True),

    'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", [item["torch"]], True),

    'narrow':   Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", [], False),
Beispiel #8
0
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
room['fountain'].s_to = None
room['fountain'].w_to = room['armory']
room['armory'].e_to = room['fountain']
room['fountain'].n_to = room['hall']
room['hall'].e_to = room['larder']
room['hall'].s_to = room['fountain']
room['hall'].w_to = room['indev']
room['hall'].n_to = room['indev']
room['larder'].w_to = room['hall']

# Populate rooms

room['outside'].items.append(
    LightSource('Lamp', 'A small metal lamp with glass windows'))
room['outside'].items.append(
    Item('Rope', 'Twisted hemp forms a long, flexible rope'))
room['treasure'].items.append(
    Item('Grappling Hook', 'A metal hook, with three prongs'))
room['armory'].items.append(
    Weapon('Rusty Sword', 'A metal sword, rusty from long neglect', 6,
           "Slashing"))
room['larder'].items.append(
    Item('Tasty Cake', 'A tasty old cake. Fills you up!'))

#
# Main
#

# Make a new player object that is currently in the 'outside' room.
Beispiel #9
0
# Declare all the rooms
room = {
    'outside':
    Room(
        "outside the Cave Entrance",
        "North of you, the cave mount beckons",
        [Item('matches', 'some matches')],
    ),
    'foyer':
    Room(
        "in the Foyer",
        """Dim light filters in from the south. Dusty passages run north and east.""",
        [
            Item('flask', 'a flask'),
            LightSource('lamp', 'a lamp'),
            Item('bones', 'some old bones'),
        ],
    ),
    'overlook':
    Room(
        "at the Grand Overlook",
        """A steep cliff appears before you, falling into the darkness.
Ahead to the north, a light flickers in the distance,
but there is no way across the chasm.""",
        [
            Item('flask', 'a flask of water'),
            Item('coins', 'some old coins'),
        ],
    ),
    'narrow':
Beispiel #10
0
    'foyer':    Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),

    'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm."""),

    'narrow':   Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),

    'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south. """),
}

t = LightSource("Torch", "And Let There Be Light")
h = Treasure("Human Poo", "I don't know why you would pick this up", 100)
f = Treasure("Tiger Poo", "I don't know why you would pick this up", 100)
j = Treasure("Bat Poo", "I don't know why you would pick this up", 100)
room['outside'].item.append(t)
room['foyer'].item.append(h)
room['narrow'].item.append(f)
room['overlook'].item.append(j)



# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
Beispiel #11
0
        "Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", False),
    'treasure':
    Room(
        "Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south.""", False),
    'dungeon':
    Room(
        "Filthy Dungeon",
        """The stench of death overwhelms you as you enter the room.  Ancient bones and more freshly rotten corpses litter the floor, walls, and cells of this dungeon.  It looks like no one fed the prisoners and they died agonizing deaths. A grimy passage leads to the west.""",
        False)
}

item = {
    'flashlight': LightSource("flashlight",
                              "a flashlight. That could be handy!"),
    'sword': Item("sword", "a large broadsword"),
    'shield': Item("shield", "a protective shield"),
    'nothing': Item("nothing", "nothing. Keep looking"),
    'pokeball': Item("pokeball",
                     "a pokeball. Huh? Are there pokemon around here?"),
    'tunic': Item("tunic", "a warm tunic"),
    'hookshot': Item("hookshot", "a hookshot. You can escape by pressing q!")
}

# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
Beispiel #12
0
room['outside'].items.append(
    Item(
        name='sword',
        description=
        'This can kill another player if there are multiple players and you encounter one in a room'
    ))
room['foyer'].items.append(
    Item(name='scroll', description='This will give you a clue'))
room['foyer'].items.append(
    Item(
        name='sword',
        description=
        'This can kill another player if there are multiple players and you encounter one in a room'
    ))
room['foyer'].items.append(
    LightSource(name='torch',
                description='This will help you see more items in the room'))
room['treasure'].items.append(
    Item(name='gem', description='You can trade this for something else'))
room['treasure'].items.append(
    LightSource(name='match', description='You can only use this once'))
room['narrow'].items.append(Item(name='coin', description='5 points'))

# Classify rooms that have lighting
room['outside'].is_light = True
room['foyer'].is_light = True
room['overlook'].is_light = True

# Main
# Make a new player object that is currently in the 'outside' room.
player = Player(name='Jasim', current_room=room['outside'])
Beispiel #13
0
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']
room['narrow'].e_to = room['cavern']
room['cavern'].w_to = room['narrow']

# items in rooms
room['foyer'].add_item(Item('chest', 'Wonder what is in here?'))
room['outside'].add_item(Item('dagger', 'small dagger... it is kinda dull'))
room['outside'].add_item(
    Item('necklace', 'A dirty necklace... try wiping it off'))
room['overlook'].add_item(Item('key', 'tiny bronze key'))
room['treasure'].add_item(Item('bottle', 'Seems to contain a message'))
room['cavern'].add_item(
    LightSource('torch', 'Bet this will help in dark areas...'))

#
# Main
#

# Make a new player object that is currently in the 'outside' room.

ruby = Player('Ruby', room['outside'])
boss = Dragon()
warlock = Warlock()

# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
Beispiel #14
0
from room import Room
from player import Player
from item import Item
from item import LightSource
# Declare all the rooms

items = {
    'Knife':
    Item('Knife', 'A small cooking knife.', True),
    'Torch':
    LightSource('Torch', 'An unlit torch', True),
    'Matches':
    Item('Matches', 'Used for starting fires or lighting torches.'),
    'Rations':
    Item('Rations', 'Well-preserved food'),
    'Cigarettes':
    Item('Cigarettes', 'Adventuring can be stressful.'),
    'Pistol':
    Item('Pistol', 'A standard issue 9mm Pistol', True),
    'Ammunition':
    Item('Ammunition', 'Ammunition for 9mm weapons.', True),
    'Rusty Key':
    Item('Rusty Key',
         "A key that looks like it's spent a lot of time outdoors."
         ),  # key to the shed
    'Shiny Key':
    Item('Shiny Key', "A key that looks like it opens an important room."
         ),  # key to the master bedroom
    'Globe':
    Item('Globe',
         "A large globe with hardware meant to mount it on something..."
Beispiel #15
0
}

# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

items = {
    'flashlight':
    LightSource("flashlight", "A device that provides a light source."),
    'mysterious_box':
    Item("mysterious_box", "A locked box of unknown origin.")
}

room['outside'].add_item(items['flashlight'])
room['outside'].add_item(items['mysterious_box'])

monsters = {
    'dragon': Monster('Dragon', 20, 10),
    'troll': Monster('Troll', 10, 5)
}

room['foyer'].monster = monsters['dragon']
room['narrow'].monster = monsters['troll']
Beispiel #16
0
# Link rooms together

room['outside'].n_to = room['foyer']
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

room['outside'].contents = [
    Item("the hot dog", "hot diggity dog"),
    Item("orb", "sick orb brah"),
    LightSource("lamp", "a friendly oil lamp"),
    Item("the rusty sword", "a super gnarly sword"),
    Item("the silver sword", "shiny rad sword")
]

#
# Main
#

# Make a new player object that is currently in the 'outside' room.

player = Player('Hero', room['outside'])

# Write a loop that:
#
# * Prints the current room name
Beispiel #17
0
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

room['outside'].is_light = True
room['foyer'].is_light = True

# Add some items

t = Treasure("coins", "Shiny coins", 100)
room['overlook'].contents.append(t)

t = Treasure("silver", "Tarnished silver", 200)
room['treasure'].contents.append(t)

l = LightSource("lamp", "Brass lamp")
room['foyer'].contents.append(l)


def tryDirection(d, curRoom):
    """
    Try to move a direction, or print an error if the player can't go that way.
    Returns the room the player has moved to (or the same room if the player
    didn't move).
    """
    attrib = d + '_to'

    # See if the room has the destination attribute
    if hasattr(curRoom, attrib):
        # If so, return its value (the next room)
        return getattr(curRoom, attrib)
Beispiel #18
0
# Declare all the items
item = {}
item['sword'] = Item('sword', 'It is magical sword with interesting powers')
item['knife'] = Item('knife', 'It is an ancient knife with speed and power')
item['arrow'] = Item('arrow', 'Bow and arrow are a deadly combination')
item['coins'] = Item('coins', 'Coins can buy you other items')

#Treasure creation, it is a sub-class of item

item['gold'] = Treasure('gold', 'gold gives you the power to buy more items',
                        500)
item['silver'] = Treasure('silver', 'silver is the choice of a warrior', 300)
item['ruby'] = Treasure('ruby', 'ruby potion can put Hagrid to sleep', 150)

#LightSource creation
item['lamp'] = LightSource(
    'lamp', 'lamp is a source of light that leads to knowledge')

# Declare all the rooms
room = {
    'outside':
    Room("Outside Cave Entrance", "North of you, the cave mount beckons",
         [item['sword'], item['coins']], False),
    'foyer':
    Room(
        "Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", [item['knife'], item['coins'], item['lamp']],
        False),
    'overlook':
    Room(
        "Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
Beispiel #19
0
# Link rooms together

rooms['outside'].n_to = rooms['foyer']
rooms['foyer'].s_to = rooms['outside']
rooms['foyer'].n_to = rooms['overlook']
rooms['foyer'].e_to = rooms['narrow']
rooms['overlook'].s_to = rooms['foyer']
rooms['narrow'].w_to = rooms['foyer']
rooms['narrow'].n_to = rooms['treasure']
rooms['treasure'].s_to = rooms['narrow']

# Populate rooms with items
rooms['foyer'].add_item(
    Item("Potion", "You can drink this to boost your health."))
rooms['foyer'].add_item(Item("Coins", "These can be used to buy stuff."))
rooms['foyer'].add_item(LightSource("Lamp", "This burns oil for light."))
rooms['outside'].add_item(Item("Stick", "A very crude weapon."))
rooms['narrow'].add_item(Item("Coin", "This can be used to buy stuff."))
rooms['narrow'].add_item(Item("Coin", "This can be used to buy stuff."))
rooms['narrow'].add_item(Item("Stick", "A very crude weapon."))
rooms['narrow'].add_item(Item("Coin", "This can be used to buy stuff."))
rooms['treasure'].add_item(Item("Rope", "Good for lots of things."))

#
# Main
#

# Make a new player object that is currently in the 'outside' room.
pc = Player(rooms['outside'])

# Write a loop that:
Beispiel #20
0
from player import Player, Monster, Merchant
from os import system, name

#Item list
ten_gold = Gold(
    -1,
    "a smattering of 10 gold pieces lies on the cobblestone tile next to the rusty sword.",
    10)

thousand_gold = Gold(
    -1,
    "a pile of 1000 gold pieces is piled high in a treasure chest near something.",
    10)

torch = LightSource(
    0, "torch", "a crude stick with an oil soaked rag at its tip",
    "a torch lies on the floor next to the chest, hastily discarded.", 0, 0, 4)

chest = Container(
    1, "chest",
    "its lock was clearly broken, but there appears to be something inside.",
    "a battered wooden chest sits in the corner", [ten_gold])

rusty_sword = Weapon(
    2, "rusty_sword",
    "rusting, it could probably do better if it were sharpened",
    "a rusty sword lies nearby under a drip somewhere on the cavern's ceiling",
    2, 4)

golden_sword = Weapon(
    3, "golden_sword",
Beispiel #21
0
    'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", True),

    'narrow':   Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air.""", False),

    'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south.""", True),

    'dungeon': Room("Filthy Dungeon", """The stench of death overwhelms you as you enter the room.  Ancient bones and more freshly rotten corpses litter the floor, walls, and cells of this dungeon.  It looks like no one fed the prisoners and they died agonizing deaths. A grimy passage leads to the west.""", False)
}

item = {
	'lamp': LightSource("A lamp", "a lamp that glows brightly"),

	'goblet': Item("A goblet", "an empty silver goblet"),

	'hat': Item("A hat", "a brightly plumed hat"),

	'nothing': Item("nothing", "a frightening, overwhelming lack of anything"),

	'dagger': Item("dagger", "an old, rusty dagger"),

	'feces': Item("feces", "rat droppings, they look fresh"),

	'rags': Item("rags", "some rags cover old, unfound treasure. these are just rags"),

	'femur': Item("femur", "an ancient human femur, still mostly whole, though sharpened on one end."),
Beispiel #22
0
import os
from time import sleep
from textwrap import wrap

from room import Room
from player import Player
# from minimap.minimap import MiniMap # Importing from subdirectories
from item import Item
from item import Treasure
from item import LightSource

# Declare Global Items
items = {
    'dandelions':   Item('dandelions', 'A handful of dandelions. Can be found at the entrance of the cave.'),
    'sword':        Item('sword', 'A masterfully crafted sword, suited for a champion!'),
    'lamp':         LightSource('lamp', 'An old and rusty lamp, looks like it still has oil in it'),
    'amulet':       Item('amulet', 'A glowing amulet, it vibrates as you get closer to treasures'),
    'backpack':     Item('backpack', 'A very large backpack. This can come in handy!'),
    'laptop':       Item('laptop', 'A personal laptop, too bad the batteries have run out'),
    'treasure':     Treasure('treasure', 'A cache of gems and artifacts, neatly packed in a old leather bag', 100),
}

# Declare all the rooms

room = {
    #outside:   { name: "Outside Cave Entrance", description: "North of you, the cave mount beckons", n_to: {POINTS TO FOYER}}
    'outside':  Room("Outside Cave Entrance", "Dandelions grow on the outside of the cave entrance. North of you, the cave mount beckons", is_lit=True),
    'foyer':    Room("Foyer","Dim light filters in from the south. Dusty passages run north and east.", is_lit=True),
    'overlook': Room("Grand Overlook","A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in the distance, but there is no way across the chasm."),
    'narrow':   Room("Narrow Passage","The narrow passage bends here from west to north. The smell of gold permeates the air."),
    'treasure': Room("Treasure Chamber","You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by earlier adventurers. The only exit is to the south."),
Beispiel #23
0
from room import Room
from player import Player
from item import Item, Treasure, LightSource

items = {
    'club':
    Item('Club', 'An old worn stick. Good for bashing things'),
    'ring':
    Treasure(100, 'Ring',
             'A plain looking ring that gives off a mystical glow'),
    'key':
    Treasure(100, 'Key', 'A golden Key'),
    'ruby':
    Treasure(500, 'Ruby', 'A large ruby'),
    'lamp':
    LightSource('Lamp', 'A common lamp. No genies here!')
}

room = {
    'outside':
    Room("Outside Cave Entrance", "North of you, the cave mount beckons", True,
         [items['club'], items['key'], items['lamp']]),
    'foyer':
    Room(
        "Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
    'overlook':
    Room(
        "Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", False,
Beispiel #24
0
    'narrow':   Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),

    'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
}


# Link rooms together

room['outside'].n_to = room['foyer']
room['outside'].s_to = None
room['outside'].e_to = None
room['outside'].w_to = None
torch_foyer = LightSource('burning touch', 'A wooden touch, which should burn for some time.')
room['outside'].items.append(torch_foyer)
room['outside'].isLit = True

room['foyer'].n_to = room['overlook']
room['foyer'].s_to = room['outside']
room['foyer'].e_to = room['narrow']
room['foyer'].w_to = None

room['overlook'].n_to = None
room['overlook'].s_to = room['foyer']
room['overlook'].e_to = None
room['overlook'].w_to = None

room['narrow'].n_to = room['treasure']
room['narrow'].s_to = None
Beispiel #25
0
room['foyer'].s_to = room['outside']
room['foyer'].n_to = room['overlook']
room['foyer'].e_to = room['narrow']
room['overlook'].s_to = room['foyer']
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['narrow']

# Create items for game (item, treasure, lightsource and packs)
dagger = Item('dagger',
              'A small but very sharp dagger. Good for cutting things.')
rope = Item('rope', 'A very sturdy long piece of rope. Could be useful...')
coins = Treasure('coins',
                 "A small pile of gold coins. Shine brightly in the light")
treasure = Treasure('treasure', 'A large pile of treasure')
flashlight = LightSource('flashlight', 'A tool used to see in the dark')
backpack = Pack('backpack', 'A good way to carry more items', 3)

# Add items to the respective rooms
room['foyer'].items = [dagger, backpack]
room['overlook'].items = [rope]
room['narrow'].items = [treasure]
room['treasure'].items = [coins]
room['outside'].items = [flashlight]

# Main
#

# Make a new player object that is currently in the 'outside' room.
playerName = input("Please enter your name: \n")
player1 = Player(playerName, room['outside'])
Beispiel #26
0
duck = Treasure(
    'Duck', "If something weighs as much as a duck, it must be made of wood.",
    10)
ninePence = Treasure("Pence", "Nine pence.  Enough to pay a mortician.", 9)
shrubbery = Treasure("Shrubbery", "It's...  a shrubbery!", 10)
elderberries = Treasure(
    "Elderberries",
    "A very... *cough* manly... *cough* perfume...  *snicker snicker*", 10)
deed = Treasure("Deed", "A deed for HUGE...  tracts of land!", 10)
hamster = Item("Hamster", "This is your Mother.  Do not lose her.")
coconuts = Item("Coconuts", "A mighty steed!")
shield = Armor("Shield", "A worn, wooden shield.", 10)
spam1 = Food("Spam", "I would like some Spam.", 1)
spam2 = Food("SpamSpam", "I would like some Spam and Spam.", 2)
spam3 = Food("SpamSpamSpam", "I would like some Spam, Spam, and Spam", 3)
spam4 = Food("SpamSpamSpamSpam",
             "I would like some Spam, Spam, Spam, and Spam", 4)
spam5 = Food("SpamSpamSpamSpamSpam",
             "I would like some Spam, Spam, Spam, Spam, and Spam", 5)
eggs = Food("Eggs", "It's a tasty egg.", 1)
bacon = Food("Bacon", "What dreams are made of.", 10)
lantern = LightSource("Lantern",
                      "A lantern that you can light with a fire source.",
                      False)
torch = LightSource("Torch",
                    "A branch with an oil soaked rag wrapped on one end.",
                    False)
flint = Item("Flint",
             "You can use flint against a piece of metal to create fire.")
wagon = Item("Wagon", "Bring out'cher dead!")
deadPerson = Item("Body", "They're not so happy... =(")
Beispiel #27
0
room['narrow'].w_to = room['foyer']
room['narrow'].n_to = room['treasure']
room['treasure'].s_to = room['partyroom']

room['outside'].is_light = True
room['foyer'].is_light = True

# Add some items

t = Treasure("stars", "Shiny stars", 100)
room['overlook'].contents.append(t)

t = Treasure("jewels", "Jewels! Beautiful Jewels ", 200)
room['treasure'].contents.append(t)

l = LightSource("jar", "Jar of Fairies")
room['foyer'].contents.append(l)

f = Food("turkeyleg", "Turkey Leg")
room['partyroom'].contents.append(f)

def tryDirection(d, currentRoom):
    """
    Try to move a direction, or print an error if the player can't go that way.

    Returns the room the player has moved to (or the same room if the player
    didn't move).
    """
    attrib = d + '_to'

    # See if the room has the destination attribute
Beispiel #28
0
        handle_input()
    elif lc_command == 'q':
        print(colored('\n     **You have ended the game.**\n',
                      'red', attrs=['bold']))
        input("\n     press 'Enter' to continue")
    else:
        print(colored('\n     what command is this!?', 'red', attrs=['bold']))
        input("\n     press 'Enter' to continue")


# instantiate/initialize player, room items, and command
player = Player(room['outside'])
room['outside'].list.append(
    Item('HealthGlobe', 'Glowey Globe of Shiny Red Stuffs'))
room['outside'].list.append(Item('Sign', 'Danger, Keep out!'))
room['outside'].list.append(LightSource(
    'WillowWisp', 'A globe of shiny lights'))
room['traproom'].list.append(LightSource(
    'Torch', 'Fire strikes fear in the hearts of shadows'))
room['traproom'].list.append(Treasure('FineGemstone', 500))
room['traproom'].list.append(
    Weapon('Sword', 'A basic but effective looking blade.', 5))

command = ''  # anything other than 'q' to start main loop

# Main
while command.lower() != 'q':
    start_turn(player)
    get_input()
    handle_input()
Beispiel #29
0
import random
from room import Room
from player import Player
from item import Item
from item import Treasure
from item import LightSource
from monster import Monster

room = {
    'outside':
    Room("Outside Cave Entrance", "North of you, the cave mounth beckons.", [
        Item('sword', 'looks sharp'),
        LightSource("lamp", 'good source of light'),
        Treasure('goldbag', 'looks like a small bag of gold', 50)
    ]),
    'foyer':
    Room(
        "Foyer", """Dim light filters in from the south. Dusty
passages run north and east.""", []),
    'overlook':
    Room(
        "Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm.""", [
            Item('key', 'looks important'),
            Item('rope', 'looks sturdy'),
            Treasure('beans', 'they appear to be magical beans', 20)
        ]),
    'narrow':
    Room(
        "Narrow Passage", """The narrow passage bends here from west
Beispiel #30
0
earlier adventurers. But after some searching you find a key... """, False),
    'secret':
    Room(
        "Secret Room", """With all of your knowledge and sheer fortitude
you have found a way into this room and found the treasure. And go east to exit this ride\n\nDon't forget to claim your prize!""",
        False)
}

# Create Items Dictionary

Items = {
    "Sword": Item('Sword', 'Shiny'),
    "BronzeCoin": Treasure('BronzeCoin', 'Bronze', '5'),
    "SilverCoin": Treasure('SilverCoin', 'Silver', '10'),
    "GoldCoin": Treasure('GoldCoin', 'Gold', '20'),
    "Lamp": LightSource('Lamp', 'Illuminator'),
    "Key": Item('Key', 'Secret Hidden Key'),
    "Pebble": Item('Pebble', 'Yep, Just A Pebble')
}

# Adding Items to a Room

room['outside'].addItem(Items['Sword'])
room['foyer'].addItem(Items['BronzeCoin'])
room['narrow'].addItem(Items['SilverCoin'])
room['overlook'].addItem(Items['GoldCoin'])
room['outside'].addItem(Items['Lamp'])
room['treasure'].addItem(Items['Key'])
room['secret'].addItem(Items['Pebble'])

# Link rooms together