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
def __init__(self, port): def handler(*args): RequestHandler(*args) global games games = Game.get_registered_games() HTTPServer.protocol_version = "HTTP/1.0" server = HTTPServer(('0.0.0.0', port), handler) server.serve_forever()
# Create the game print(" ~~~ Welcome to ~~~ ") print(" ___ __ __ ___ ___") print(" / | ____/ / _____ ____ / /___ __________ |__ \< /") 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(
# First we need to import everything we need from the Game engine (a module called 'advent'): 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 # These are the things that you can use to build your game. # For example, a Location is a place the player can be, like a room, corridor, meddow, etc. # The ones in all CAPS are directions that the player can use to move from one Location to another. # Now we are ready to make our game. # First, you need to create your game and give it a name: game = Game("Brightworks Adventure") # 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(
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 Game.register("ExampleHTTPGame", make_game)
#!/user/bin/python # vim: et sw=2 ts=2 sts=2 # # 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
#!/usr/bin/python # vim: et sw=2 ts=2 sts=2 from advent import * # for cloud9 from advent import Game, Location, Connection, Object, Animal, Robot, Pet, Player, Verb, Say, SayOnNoun, SayOnSelf 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 # comment this line out to skip the devtools for environments like trinket import advent_devtools # Set up the game you are going to build on. # my_game is a top-level container for everything in the game. game = Game("Brightworks Adventure") # Create some interesting locations. Locations need a name # and a description of any doorways or connections to the room, like this: # variable_name = Location('The Name", "The description") # The triple quotes (""") below are a way to make multi-line strings in Python. # The final argument is which word to use in the location title in place of "in" # in the phrase "You are in the..." sidewalk = Location( "Sidewalk", """There is a large glass door to the east. The sign says 'Come In!' """, "on") # Custom messages can contain lists of strings and functions which return strings. vestibule = Location("Vestibule", [ "A small area at the bottom of a flight of stairs.\n", game.if_flag('switch_on', "There is a switch next to a lit bulb.\n", "There is a switch next to an unlit bulb.\n"),
# 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, 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.""")
#!/user/bin/python # vim: et sw=2 ts=2 sts=2 # # 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
#!/usr/bin/python # vim: et sw=2 ts=2 sts=2 from advent import * # for cloud9 from advent import Game, Location, Connection, Object, Animal, Robot, Pet, Player, Verb, Say, SayOnNoun, SayOnSelf 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 # comment this line out to skip the devtools for environments like trinket import advent_devtools # Set up the game you are going to build on. # my_game is a top-level container for everything in the game. game = Game("Brightworks Adventure") # Create some interesting locations. Locations need a name # and a description of any doorways or connections to the room, like this: # variable_name = Location('The Name", "The description") # The triple quotes (""") below are a way to make multi-line strings in Python. # The final argument is which word to use in the location title in place of "in" # in the phrase "You are in the..." sidewalk = Location( "Sidewalk", """There is a large glass door to the east. The sign says 'Come In!' """, "on") # Custom messages can contain lists of strings and functions which return strings. vestibule = Location( "Vestibule", ["A small area at the bottom of a flight of stairs.\n",
"Death from boredom after twelve continous hours of blood transfusion" ) self.player.terminate() else: self.output( "12 hours pass - you gain 10 Acceptatrons, but you now fill depressed. " "You need to find more of these happy pills!") game.player.unset_flag(happypills.name) self.player.add_to_inventory( Object("Acceptatrons", "10 pure, undiluted acceptatrons")) self.verb.act(actor, noun, words) return True game = Game("Non-Compulsory Slaving-Volunteering") lobby = Location( "Lobby", "The heavy smog of the slave-volunteering ship Vromarion is hurting your lungs. " "Captain must be cheap, air filters are expensive. 'Welcome to cruise-ship Vromarion', a pleasant voice explains. " "'You are a first generation volunteer. " "Given a choice of death by thirst and hunger or volunteering for just 56 years, you chose (out of your own free volition) the later. " "We start volunteering on the decks at exactly 7am, one hour before robot operations commence. " "You arrived late, thus there will be no formal induction." "the transporter to the right will move you to blood operations. You can choose to go right. Please hurry!'", "on") blood_room = Location( "Blood donations", "You are teleported in the middle of what is probably a mile-wide and two-miles long room full of little 'igloos'. Your iCommunicator beams:"
else: self.output("12 hours pass - you gain 10 Acceptatrons, but you now fill depressed. " "You need to find more of these happy pills!") game.player.unset_flag(happypills.name) self.player.add_to_inventory(Object("Acceptatrons", "10 pure, undiluted acceptatrons")) self.verb.act(actor, noun, words) return True game = Game("Non-Compulsory Slaving-Volunteering") lobby = Location( "Lobby", "The heavy smog of the slave-volunteering ship Vromarion is hurting your lungs. " "Captain must be cheap, air filters are expensive. 'Welcome to cruise-ship Vromarion', a pleasant voice explains. " "'You are a first generation volunteer. " "Given a choice of death by thirst and hunger or volunteering for just 56 years, you chose (out of your own free volition) the later. " "We start volunteering on the decks at exactly 7am, one hour before robot operations commence. " "You arrived late, thus there will be no formal induction." "the transporter to the right will move you to blood operations. You can choose to go right. Please hurry!'", "on") blood_room = Location(
# 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, 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])
world.add_connection(stairs) world.add_connection(steps_to_reception) world.add_connection(steps_to_elevator) # create some things to put in your world elev_key = Thing("key", "small tarnished brass key") elev_lock = Thing("lock", "ordinary lock") sidewalk.put(elev_key) sidewalk.put(elev_lock) sidewalk.put(Thing("pebble", "round pebble")) sidewalk.put( Thing("Gary the garden gnome", "a small figure liberated from a nearby garden.")) # simple verb applicable at this location sidewalk.add_verb('knock', Game.say('The door makes a hollow sound.')) # custom single location verb def scream(world, words): print "You scream your head off!" for w in words[1:]: print "You scream '%s'." % w return True sidewalk.add_verb('scream', scream) # Add an animal to roam around. Animals act autonomously cat = Animal(world, "cat") cat.set_location(sidewalk)