コード例 #1
0
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']

# make some rooms lit
room['outside'].is_lit = True
room['foyer'].is_lit = True

# items

item = {
    'sword': Weapon("stick", "Sticky Stick", 10),
    'coins': Treasure("sack", "a small sack (wonder whats in it?)", 5),
    'lamp': LightSource("lamp", "Oil Lamp")
}

# add some items to the rooms

room['overlook'].contents.append(item['sword'])
room['overlook'].contents.append(item['coins'])
room['foyer'].contents.append(item['lamp'])

# # helper functions
# def try_a_direction(player, dir):
#     attribute = dir + '_to'

#     if hasattr(player.current_room, attribute):
#         return getattr(player.current_room, attribute)
コード例 #2
0
        """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."""
    ),
}

# Add items to two rooms

room['outside'].items.append(
    Items(
        "shovel",
        "Enter \'take shovel\' to dig holes and defend yourself from zombies"))
room['foyer'].items.append(
    Lightsource("lamp",
                "Enter \'take lamp\' and use it to illuminate the passages"))
room['treasure'].items.append(
    Treasure(
        "gold",
        "Enter \'take gold\' thought it's not a chest full, you\'ve found something",
        "25"))
room['narrow'].items.append(
    Treasure(
        "silver",
        "Enter \'take silver\' when there's silver, sometimes gold is near",
        "10"))
room['overlook'].items.append(
    Treasure(
        "bronze",
        "Enter \'take bronze\' when there's bronze, sometimes silver is near",
        "5"))

# Link rooms together

room['outside'].n_to = room['foyer']
コード例 #3
0
ファイル: adv.py プロジェクト: jocafrin/Intro-Python
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.""", False),
}

items = {
    'dagger': Item("dagger", "a small dull blade. It's practically useless"),
}

treasure = {
    'potion': Treasure("healing potion", "Can restore HP and MP", 1000),
    'book': Treasure("book", "The Necronomicon", 50),
    'ribbon': Treasure("ribbon", "give immunity to all status effects", 200)
}

torch = LightSource('torch', "a mgagically lit torch. Watch your hair.")


room['outside'].addItem(items['dagger'])
room['treasure'].addItem(treasure['potion'])
room['overlook'].addItem(treasure['book'])
room['overlook'].addItem(torch)
room['foyer'].addItem(treasure['ribbon'])

suppressRoomPrint = False
validDirections = ["n", "s", "e", "w"]
コード例 #4
0
from items import Treasure

world = World(15, 15)

player_i, player_j = world.random_location()
player = Player(player_i, player_j)
world.entities.append(player)

for i in range(10):
    knight_i, knight_j = world.random_location()
    knight = Knight(knight_i, knight_j)
    world.entities.append(knight)

for j in range(10):
    treasure_i, treasure_j = world.random_location()
    treasure = Treasure(treasure_i, treasure_j)
    world.entities.append(treasure)

while True:
    world.draw()
    command = input('what is your command? ').lower()
    if command in ['done', 'quit', 'exit']:
        break
    if command in ['left', 'a']:
        if player.loc_i > 0:  # this keeps player from going off the edge of the board
            player.loc_i -= 1
    elif command in ['right', 'd']:
        player.loc_i += 1
    elif command in ['up', 'w']:
        player.loc_j -= 1
    elif command in ['down', 's']:
コード例 #5
0
 def get_all_treasures(self):
     f = open("roguey/resources/items.xml")
     root = etree.fromstring(f.read())
     treasures = [Treasure.from_xml(t) for t in root]
     f.close()
     return treasures
コード例 #6
0
ファイル: generator.py プロジェクト: nyalldawson/dwarf_mine
    def build_mine(self, screen, pad):

        m = Mine(screen, pad, self.width, self.height)

        tribe_population = self.args.miners or random.randint(1, 30)

        tribe_width = int(m.width / (self.args.tribes * 2 - 1))
        for t in range(self.args.tribes):
            new_tribe = random.choice(TRIBE_CLASSES)(t)

            new_tribe.min_x = tribe_width * new_tribe.id * 2
            new_tribe.max_x = tribe_width * (new_tribe.id * 2 + 1) - 1
            new_tribe.color = COLORS[t]
            new_tribe.leader_color = KING_COLORS[t]
            new_tribe.name = (NAMES[t] + ' ' + new_tribe.name).strip()
            m.tribes.append(new_tribe)

            creatures = new_tribe.populate(tribe_population)
            for c in creatures:
                m.add_creature(c)

        #for i in range(miner_count):
        #    tribe = random.choice(m.tribes)
        #    x = random.randint(tribe.min_x, tribe.max_x)

        #    creature = tribe.create_creature(x=x, y=0, tribe=tribe)
        #    m.add_creature(creature)

        for i in range(random.randint(4, 10)):
            hole_size = random.randint(4, 8)
            m.create_cave(random.randint(0, m.width - 1),
                          random.randint(0, m.height - 1), hole_size)

        outcast_tribe = Tribe(-1)
        outcast_tribe.name = 'Outcast'
        saboteur_count = self.args.saboteurs or random.randint(1, 3)
        for i in range(saboteur_count):
            saboteur = Saboteur(random.randint(0, m.width - 1),
                                int(m.height / 2),
                                tribe=outcast_tribe)
            m.add_creature(saboteur)

        wizard_count = self.args.wizards or random.randint(1, 5)
        for i in range(wizard_count):
            wizard = Wizard(
                random.randint(0, m.width - 1),
                random.randint(math.ceil(m.height / 3), m.height - 1))
            m.add_creature(wizard)

    #   def make_explore_action():
    #       return ExploreAction()

    #snake_count = self.args.snakes or random.randint(1, 5)
    #for i in range(snake_count):
    #    tribe = random.choice([t for t in m.tribes if Snake in t.creatures])
    #    x = random.randint(tribe.min_x, tribe.max_x)
    #    snake = Snake(x, 0, tribe=tribe)

    #    snake.default_action = make_explore_action
    #    snake.push_action(ExploreAction())
    #    if snake.has_trait(Contagious):
    #        snake.color = KING_COLORS[tribe.id]
    #    else:
    #        snake.color = tribe.color

#     #     snake = Snake(random.randint(0, m.width - 1), random.randint(math.ceil(m.height / 5), m.height - 1))
#    m.add_creature(snake)

        treasure_count = self.args.treasures or random.randint(1, 10)
        for i in range(treasure_count):
            treasure = Treasure(random.randint(0, m.width - 1),
                                random.randint(10, m.height - 1))
            m.add_item(treasure)
            map_item = Map(random.randint(0, m.width - 1),
                           random.randint(5, m.height - 1), treasure)
            m.add_item(map_item)

    #  for t in m.tribes:
    #      king_count = int(self.args.kings) if self.args.kings is not None else 1
    #      for i in range(king_count):
    #          x = random.randint(t.min_x, t.max_x)
#
#          king = DwarfKing(x, 0, t)
#          king.color = KING_COLORS[t.id]
#          m.add_creature(king)
#
        return m
コード例 #7
0
ファイル: adv.py プロジェクト: RockmanExe/Intro-Python
to north. The smell of gold permeates the air.""", False, True),
    '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),
}

# Declare all the items
item_dict = {
    'apple':
    Food('apple', 'a small to medium-sized conic apple', 'food', 1, 10),
    'bread':
    Food('bread', 'a slice of bread', 'food', 1, 10),
    'ring':
    Treasure('ring', 'a silver ring', 'treasure', 1, 50),
    'lamp':
    LightSource('lamp', 'a lamp', 'light source', 1, 50),
    'necklace':
    Treasure('necklace', 'a silver necklace', 'treasure', 1, 50),
    'bracelet':
    Treasure('bracelet', 'a silver bracelet', 'treasure', 1, 50),
    'largeTreasureChest':
    Treasure('bracelet', 'a large treasure chest', 'treasure', 1, 500),
    'sword':
    Weapon('sword', 'a large ninja katana', 'weapon', 10, 10),
    'knife':
    Weapon('knife', 'a rusty knife', 'weapon', 10, 7),
    'fist':
    Weapon('fist', 'your knuckles hardened by life', 'weapon', 1, 1),
コード例 #8
0
ファイル: adv.py プロジェクト: hillal20/Intro-Python
                     "North of you, the cave mount beckons",
                     items=Item('knifes', ['Irish knifes',
                                           'turkish knife', 'viking knife']), treasure=None, light=LightSource('lamp', 'moderate light ', False)
                     ),

    'foyer':    Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east. """,
                     items=Item('books', ['magic books',
                                          'bible', 'food', 'albums']), treasure=None, light=None
                     ),

    '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. #### THERE IS A TREASURE HERE#### """,
                     items=Item(
                         'boxes ', ['pirates of the carribian', 'old stuff', 'bombs']), treasure=Treasure('gold', 'british gold bullion', 90), light=None
                     ),

    'narrow':   Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air. #### THERE IS A TREASURE HERE #######""",
                     items=Item(
                         'cloths ', ['army uniform', 'clone', 'pilot uniform', 'nurse uniform']), treasure=Treasure("bronze", "argentina bronze bullion", 35), light=None
                     ),

    '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.""",
                     items=Item('shields', ['hand shield', 'mask', ' motorcycle halmet']), treasure=None, light=LightSource('lamp', 'very strong light', True)),
}

コード例 #9
0
ファイル: adv.py プロジェクト: wvandolah/Intro-Python
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 = {
    'sword':
    Weapon("sword", "An old sword, very rusty, will not last thru the winter"),
    'bow':
    Weapon("bow", "A worthless bow, looks like something out of a zelda game"),
    'book':
    Treasure("bible", "The most worthless of items a person could find"),
    'hair':
    Treasure("hair", "This item is still more useful than the bible"),
    'lamp':
    LightSource("lamp",
                "a cheap lamp from the dollar store, this wont last long")
}

# Link item to room
room['foyer'].addItem(items['sword'])
room['foyer'].addItem(items['bow'])
room['treasure'].addItem(items['book'])
room['foyer'].addItem(items['hair'])
room['overlook'].addItem(items['lamp'])

#
コード例 #10
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def get_all_treasures(self):
     f = open("roguey/resources/items.xml")
     root = etree.fromstring(f.read())
     treasures = [Treasure.from_xml(t) for t in root]
     f.close()
     return treasures
コード例 #11
0
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),
}

items = {
    'sword':
    Item("sword", "A wooden sword. It's dangerous to go alone! Take this."),
}

treasure = {
    'necklace':
    Treasure("necklace", "A necklace made out of pure gold", 1000),
    'book':
    Treasure("book",
             "A dusty book with the title 'Incantions of the Nether Realm'",
             50),
    'ring':
    Treasure("ring", "A basic iron ring", 200)
}

lamp = LightSource('lamp', "A lamp filled with oil")

room['outside'].addItem(items['sword'])
room['treasure'].addItem(treasure['necklace'])
room['overlook'].addItem(treasure['book'])
room['foyer'].addItem(treasure['ring'])
room['overlook'].addItem(lamp)
コード例 #12
0
ファイル: adv.py プロジェクト: sean-git-hub/python
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']

#
# Main
#

# declare items

room['outside'].addItem(Item('sword', 'a sword for slashing'))
room['foyer'].addItem(Item('shield', 'a sheild for protection'))
room['overlook'].addItem(Item('compass', 'a compass to show the direction'))
room['foyer'].addItem(Treasure('key', 'a key', 300))
room['outside'].addItem(Treasure('picture', 'a picture', 100))
room['treasure'].addItem(Treasure('Gold', 'a piece of gold', 500))

# Make a new player object that is currently in the 'outside' room.
name = input('Who are you? \n')
me = Player(name ,room['outside'])

# Write a loop that:
#
# * Prints the current room name
# * Prints the current description (the textwrap module might be useful here).
# * Waits for user input and decides what to do.
#
# If the user enters a cardinal direction, attempt to move to the room there.
# Print an error message if the movement isn't allowed.