コード例 #1
0
ファイル: http_game.py プロジェクト: brumleygap/bwx-adventure
def make_game(name):
    game = Game(name)
    sidewalk = game.new_location("Sidewalk", "There is a large glass door to the east. The sign says 'Come In!'")
    vestibule = game.new_location(
        "Vestibule",
        "A small area at the bottom of a flight of stairs.\nThere is a glass door to the west and a door to the south.",
    )
    game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])
    office = game.new_location("Office", "A nicely organized office.\nThere is a door to the north.")
    game.new_connection("Office Door", vestibule, office, [IN, SOUTH], [OUT, NORTH])
    key = sidewalk.new_object("key", "a small tarnished key")
    office.make_requirement(key)
    coin = sidewalk.new_object("coin", "a small coin")
    player = game.new_player(sidewalk)
    key.add_phrase("rub key", Say("You rub the key, but fail to shine it."))

    def flip_coin(game):
        if not "coin" in game.player.inventory:
            game.output("The coin is on the ground!")
            return
        if random.random() > 0.5:
            game.output("The coin shows heads.")
        else:
            game.output("The coin shows tails.")

    player.add_phrase("flip coin", flip_coin, [coin])
    return game
コード例 #2
0
room_marco = game.new_location(
    "Marco's Room", """You find yourself inside an curiosity shop.
There is an closet eastbound""")

room_closet = game.new_location("Closet", """:-o""")

room_andz = game.new_location(
    "Andz's Room", """Chaos, Chaos everywhere.
There is a closed door in the north""")

room_attic = game.new_location("Attic", """An Attic!""")

# connect the rooms

game.new_connection("hallway", room_hallway_north, room_hallway_middle, SOUTH,
                    NORTH)
game.new_connection("hallway", room_hallway_middle, room_hallway_south, SOUTH,
                    NORTH)
game.new_connection("hallway", room_hallway_south, room_hallway_east, EAST,
                    WEST)

game.new_connection("door", room_hallway_north, room_living_room, WEST, EAST)
game.new_connection("door", room_hallway_middle, room_laura, WEST, EAST)
game.new_connection("door", room_hallway_south, room_maga, WEST, EAST)
game.new_connection("door", room_hallway_south, room_kitchen, SOUTH, NORTH)
game.new_connection("door", room_hallway_east, room_bath, EAST, WEST)
game.new_connection("door", room_hallway_east, room_klo, NORTH, SOUTH)

game.new_connection("circular stairs", room_hallway_east, room_oben, UP, DOWN)

game.new_connection("door", room_oben, room_marco, SOUTH, NORTH)
コード例 #3
0
ファイル: tutorial1.py プロジェクト: brumleygap/bwx-adventure
# Let's create another location, this time the long description will be surrounded by
# triple quotes """.  This enables us to write the description over multiple lines:

vestibule = game.new_location(
  "Vestibule",
"""A small area at the bottom of a flight of stairs.
There is a glass door to the west.""")

# Again, make sure to end with """ and to close the parenthesis) and use a comma between
# the short and long description.

# Now we need to connect the two locations together.  Again, we are going to create
# a connection using a function.  This time we are not going to to assign it to a variable,
# but don't worry that it will simply vanish, instead it will be stored in the game.

game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])

# The 'new_connection' function takes a name for the connection, two locations and
# two directions or lists of directions.  Again, the arguments are separated by commas
# and the lists of directions are separated by commas.  We could also have said:
# game.new_connection("Glass Door", sidewalk, vestibule, EAST, WEST)
# if we didn't want the player to be able to say "in" to enter the door.

# Now we are going to add our player at the starting location:

player = game.new_player(sidewalk)

# We assign our player to the variable 'player' even though we are not going to do anything
# with the player in this tutorial.

# Finally, we run the game.   You can run the game by typing 'python tutorial1.py' or by
コード例 #4
0
ファイル: tutorial2.py プロジェクト: jplevyak/bwx-adventure
# import random module for random numbers
import random

# Let's start with the code from the first tutorial:

game = Game("Brightworks Adventure")

sidewalk = game.new_location(
    "Sidewalk",
    "There is a large glass door to the east. The sign says 'Come In!'")

vestibule = game.new_location(
    "Vestibule", """A small area at the bottom of a flight of stairs.
There is a glass door to the west.""")

game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])

player = game.new_player(sidewalk)

# Now let's add an inanimate object, a key by providing a single word name and a longer
# description.  We will create the key at the sidewalk

key = sidewalk.new_object("key", "a small tarnished key")

# The builtin commands "take", "drop" and "i" or "inventory" will allow the player to
# take the key, drop the key or check if what is in their inventory.

# Let's add a special phrase.  We can attach this phrase to any object, location or actor,
# and the phrase will trigger only if that object or actor is present or at the given location.

key.add_phrase("rub key", game.say("You rub the key, but fail to shine it."))
コード例 #5
0
sidewalk = game.new_location(
  "Sidewalk",
  "There is a large glass door to the east. The sign says 'Come In!'")

vestibule = game.new_location(
  "Vestibule",
"""A small area at the bottom of a flight of stairs.
There is a glass door to the west and door to the south.""")

office = game.new_location(
  "Office",
"""A nicely organized office.
There is a door to the north.""")

game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])

office_door = game.new_connection("Office Door", vestibule, office,
                                  [IN, SOUTH], [OUT, NORTH])

player = game.new_player(sidewalk)

# Now let's add an inanimate object, a key by providing a single word name and a longer
# description.  We will create the key at the sidewalk

key = sidewalk.new_object("key", "a small tarnished key")

# we can make the key something you have to have to go in the front door to the vestibule
# a simple one line way to do this is to simply require an object for a location:
vestibule.make_requirement(key)
コード例 #6
0
game = Game("Brightworks Adventure")

sidewalk = game.new_location(
    "Sidewalk",
    "There is a large glass door to the east. The sign says 'Come In!'")

vestibule = game.new_location(
    "Vestibule", """A small area at the bottom of a flight of stairs.
There is a glass door to the west and door to the south.""")

office = game.new_location(
    "Office", """A nicely organized office.
There is a door to the north.""")

game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])

office_door = game.new_connection("Office Door", vestibule, office,
                                  [IN, SOUTH], [OUT, NORTH])

player = game.new_player(sidewalk)

# Now let's add an inanimate object, a key by providing a single word name and a longer
# description.  We will create the key at the sidewalk

key = sidewalk.new_object("key", "a small tarnished key")

# we can make the key something you have to have to go in the front door to the vestibule
# a simple one line way to do this is to simply require an object for a location:
vestibule.make_requirement(key)
コード例 #7
0
ファイル: bwx-game.py プロジェクト: jplevyak/bwx-adventure
# example: variable = Connection("The Connection Name", location_a, location_b, direction_a, direction_b)
#
# You can have more than one way of using a connection by combining them in a list.
# In Python, [] brackets make a list.
# example: new_connection = Connection("The Connection Name", location_a, location_b, [direction_a, other_direction_a], [direction_b, other_direction_b])
big_door = Connection("Big Door", sidewalk, vestibule, [IN, EAST], [WEST, OUT])
stairs = Connection("Stairs", vestibule, reception, UP, DOWN)
steps_to_reception = Connection("A Few Steps", reception, intersection, NORTH, SOUTH)

# Now add the connections to the game too.
game.add_connection(big_door)
game.add_connection(stairs)
game.add_connection(steps_to_reception)

# You can also add a connection with a single convenience function:
game.new_connection("A Few Steps", intersection, elevator, EAST, WEST)

# Create some objects to put in your game. You need a name and
# a description for the object you are making.
# example: something = Object("Object Name", "A description for the object")
# If you add True as the last argument, then it's an item that can't be taken.
elev_key = Object("key", "small tarnished brass key")

sidewalk.add_object(elev_key)

pebble = sidewalk.add_object(Object( "pebble", "round pebble"))
sidewalk.add_object(Object("Gary the garden gnome",
  "a small figure liberated from a nearby garden."))


# You can make rooms require things, like keys, before a player can enter them.
コード例 #8
0
ファイル: tutorial1.py プロジェクト: arcarrow70/bwx-adventure
  "Vestibule",
"""A small area at the bottom of a flight of stairs.
There is a glass door to the west.""")

stairs = game.new_location(
  "Stairs",
"""You are now on the stairs, there is a door at the top of the stairs""")

# Again, make sure to end with """ and to close the parenthesis) and use a comma between
# the short and long description.

# Now we need to connect the two locations together.  Again, we are going to create
# a connection using a function.  This time we are not going to to assign it to a variable,
# but don't worry that it will simply vanish, instead it will be stored in the game.

game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])

game.new_connection("Stairs", vestibule, stairs, [UP], [DOWN])


# The 'new_connection' function takes a name for the connection, two locations and
# two directions or lists of directions.  Again, the arguments are separated by commas
# and the lists of directions are separated by commas.  We could also have said:
# game.new_connection("Glass Door", sidewalk, vestibule, EAST, WEST)
# if we didn't want the player to be able to say "in" to enter the door.

# Now we are going to add our player at the starting location:

player = game.new_player(sidewalk)

# We assign our player to the variable 'player' even though we are not going to do anything
コード例 #9
0
#
# You can have more than one way of using a connection by combining them in a list.
# In Python, [] brackets make a list.
# example: new_connection = Connection("The Connection Name", location_a, location_b, [direction_a, other_direction_a], [direction_b, other_direction_b])
big_door = Connection("Big Door", sidewalk, vestibule, [IN, EAST], [WEST, OUT])
stairs = Connection("Stairs", vestibule, reception, UP, DOWN)
steps_to_reception = Connection("A Few Steps", reception, intersection, NORTH,
                                SOUTH)

# Now add the connections to the game too.
game.add_connection(big_door)
game.add_connection(stairs)
game.add_connection(steps_to_reception)

# You can also add a connection with a single convenience function:
game.new_connection("A Few Steps", intersection, elevator, EAST, WEST)

# Create some objects to put in your game. You need a name and
# a description for the object you are making.
# example: something = Object("Object Name", "A description for the object")
# If you add True as the last argument, then it's an item that can't be taken.
elev_key = Object("key", "small tarnished brass key")

sidewalk.add_object(elev_key)

pebble = sidewalk.add_object(Object("pebble", "round pebble"))
sidewalk.add_object(
    Object("Gary the garden gnome",
           "a small figure liberated from a nearby garden."))

# You can make rooms require things, like keys, before a player can enter them.