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
print(" / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ __/ // / ") print(" / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ / __// / ") print("/_/ |_\__,_/ |___/\___/_/ /_/\__/\__,_/_/ \___/ /____/_/ ") print(" ") print(" ~~~~~~~~~~~~~~~~~~ ") print(" ") print("For a list of commands, just enter 'commands' or 'verbs'... ") print(" ") game = Game("Adventure 21") # Create all Rooms room_hallway_north = game.new_location( "Hallway North", """You find yourself in a hallway. In the west, you see the open door to the living room. In the east, you look at a door with a combination lock. The hallway extends towards south.""") room_hallway_middle = game.new_location( "Center Hallway", """ You still walk through the hallway. There is a closed door in the west. The hallway is open to south and north.""") room_hallway_south = game.new_location( "Hallway South", """You find yourself at the south end of the hallway. There is an open door towards west. The kitchen is placed in the south. The hallway still extends towards east.""") room_hallway_east = game.new_location(
# In Python, you create or change a 'variable' by simply assigning to it with '='. # Here we are creating the variable 'game'. We are assigning it the result of # the function call Game("..."). A function is a bit of code defined elsewhere which # is run when it's name is used with some arguments in paramenthesis '()' # (in this case the string "Brightworks Adventure"). # This 'statement' creates your game and stores it in the 'variable' named 'game'. # Now we want to create some locations. We are going to recreate Brightworks! # Let's start out on the sidewalk. # Again we are going to create a 'variable', this time named 'sidewalk' and assign it # the result of calling a function: sidewalk = game.new_location( "Sidewalk", "There is a large glass door to the east. The sign says 'Come In!'") # In this case we are calling a function which is part of our game. # This is indicated by using a '.' after 'game' to get the function from 'game'. # That function 'new_location' takes two arguments: # a short description (in this case 'Sidewalk') # a long description (in this case 'There ....') # Again, the arguments are in parentheses '()' and are separated by a comma. # Leaving out the comma is a common mistake and python will report a error like: # # File "tutorial1.py", line 38, in <module> # "Sidewalk" # File "advent.py", line 214, in new_location # return self.add_location(Location(*args)) # TypeError: __init__() takes exactly 3 arguments (2 given)
# This is the second tutorial for writing Interactive Fiction with the BWX Adventure Game Engine. # from advent import * # for cloud9 from advent import Game, Location, Connection, Object, Animal, Robot, Pet, Player from advent import NORTH, SOUTH, EAST, WEST, UP, DOWN, RIGHT, LEFT, IN, OUT, FORWARD, BACK, NORTH_WEST, NORTH_EAST, SOUTH_WEST, SOUTH_EAST, NOT_DIRECTION # 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")
secret_lab = Location( "Secret Laboratory", "This place is spooky. It's dark and \nthere are cobwebs everywhere. There must \nbe a light switch somewhere." ) # Let's add the locations to your game. game.add_location(sidewalk) game.add_location(vestibule) game.add_location(reception) game.add_location(intersection) game.add_location(elevator) # You can also add a simple location with the convience function 'new_location'. # "\n" makes a new line in a Python string. game.new_location( "Secret Laboratory", "This place is spooky. It's dark and \nthere are cobwebs everywhere. There must \nbe a light switch somewhere." ) # Create connections between the different places. Each connection # needs a name, the two locations to connect, and the two directions # you can go to get in and out of the space. # 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, WEST], [OUT, EAST]) # You can omit the 2nd direction and it will just be the opposite of the 1st stairs = Connection("Stairs", vestibule, reception, UP) steps_to_reception = Connection("A Few Steps", reception, intersection, NORTH)
# for cloud9 from advent import Game, Location, Connection, Object, Animal, Robot, Pet, Player, Say from advent import NORTH, SOUTH, EAST, WEST, UP, DOWN, RIGHT, LEFT, IN, OUT, FORWARD, BACK, NORTH_WEST, NORTH_EAST, SOUTH_WEST, SOUTH_EAST, NOT_DIRECTION # import devtools for helpers you can use when running locally (not in trinket.io) import advent_devtools # 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 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,
To the west is an intersection. """) # "\n" makes a new line in a Python string. secret_lab = Location("Secret Laboratory", "This place is spooky. It's dark and \nthere are cobwebs everywhere. There must \nbe a light switch somewhere.") # Let's add the locations to your game. game.add_location(sidewalk) game.add_location(vestibule) game.add_location(reception) game.add_location(intersection) game.add_location(elevator) # You can also add a simple location with the convience function 'new_location'. # "\n" makes a new line in a Python string. game.new_location( "Secret Laboratory", "This place is spooky. It's dark and \nthere are cobwebs everywhere. There must \nbe a light switch somewhere.") # Create connections between the different places. Each connection # needs a name, the two locations to connect, and the two directions # you can go to get in and out of the space. # 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, WEST], [OUT, EAST]) # You can omit the 2nd direction and it will just be the opposite of the 1st stairs = Connection("Stairs", vestibule, reception, UP) steps_to_reception = Connection("A Few Steps", reception, intersection, NORTH) # Now add the connections to the game too.
# for cloud9 from advent import Game, Location, Connection, Object, Animal, Robot, Pet, Player, Say from advent import NORTH, SOUTH, EAST, WEST, UP, DOWN, RIGHT, LEFT, IN, OUT, FORWARD, BACK, NORTH_WEST, NORTH_EAST, SOUTH_WEST, SOUTH_EAST, NOT_DIRECTION # import devtools for helpers you can use when running locally (not in trinket.io) import advent_devtools # 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 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])