from visual import * class Console: inputLine = "" def _init_ (self): self.inputLine = "" def getInput (self): print "** " # self.reader = BufferedReader(InputStreamReader()) try: self.inputLine = raw_input("") except IOError: print "There was an error during reading: " + exc.getMessage() return self.inputLine.toLowerCase() def clear (self): print "\f" def showOutput (self, s): print s class Item: key = "" description = "" def _init_ (self, item): self.key = item self.description = "a generic item" def setKey (self, keyName): key = keyName def setDescription (self, keyDescription): description = keyDescription def getKey (self): return key def getDecription (self): return description class Character: key = "" description = "" items = [] stat = 0 def _init_ (self, npc): self.key = npc self.description = "a generic item" self.items = [] self.stat = 0 def setKey (self, keyName): key = keyName def setDescription (self, keyDescription): description = keyDescription def setStat (self, A): stat = A def getKey (self): return key def getDecription (self): return description def getStat (self): return stat def setItem (self, name, myObject): self.items.insert(name, myObject) def getItem (self, name): return Item(items.index(name)) def removeItem (self, name): self.items.remove(name) def getItemString (self): self.returnString = "" for i in range(len(items)): returnString += " " + items[i] return returnString def hasItem (self, key): return self.items.containsKey(key) def getCharacterString (self): self.firstLetter = char[1] self.lastLetters = char[key.length() - 1] key.getChars(0,1,firstLetter,0) key.getChars(1,key.length(),lastLetters,0) self.first = String(firstLetter) self.last = String(lastLetters) return first.toUpperCase() + last def dropAllItems (self, room): self.keyname = "" for i in range(len(items)): self.keyname = String(items[i]) room.setItem(keyname, Item(items.index(keyname))) items.remove(keyname) class Room: key = "" items = [] exits = [] npc = "" description = "" def _init_(self, roomName): self.items = [] self.exits = [] self.npc = null self.key = roomName self.description = "a generic item" def setNPC (self, bob): npc = bob def getNPC (self): return bob def removeNPC (self): npc = null def setKey (self, keyName): key = keyName def setDescription (self, keyDescription): description = keyDescription def getKey (self): return self.key def getDescription (self): return self.description def setItem (self, name, myObject): items.insert(name, myObject) def getItem (self, name): return Item(self.items.index(name)) def removeItem (self, name): items.remove(name) def getItemString (self): self.returnString = "" for i in range(len(self.items)): self.returnString += " " + items[i] return self.returnString def getExitString (self): self.returnString = "" for i in range(len(self.exits)): self.returnString += " " + exits[i] return self.returnString def containsItem (self, key): return items.containsKey(key) def setExit(self, name, myObject): exits.insert(name, myObject) def getExit (self, name): return Room(exits.index(name)) def removeExit (self, name): exits.remove(name) def hasItem (self, key): return items.containsKey(key) def hasNPC (self, npc): return (npc != null) def getNPCName (self): if npc != null: return npc.getCharacterString() else: return "" class Game: currentRoom = Room() io = Console() bedroom = Room() darkCave = Room() katie2MazeEntrance = Room() strawberryRoom = Room() volleyballCourt = Room() tennisCourt = Room() cupcakeRoom = Room() nerdlyRoom = Room() sprinklesRoom = Room() playland = Room() lollipopRoom = Room() hedgehogRoom = Room() room1 = Room() room2 = Room() room3 = Room() room4 = Room() room5 = Room() room6 = Room() room7 = Room() home = Room() def _init_ (self): self.io = Console() currentRoom = self.bedroom self.bedroom = Room("your familiar bedroom") self.darkCave = Room("a small cave") self.katie2MazeEntrance = Room("the Katie Squared Maze") self.strawberryRoom = Room("the Strawberry Room") self.volleyballCourt = Room("the Volleyball Court") self.tennisCourt = Room("the Tennis Court") self.cupcakeRoom = Room("the Cupcake Room") self.nerdlyRoom = Room("the Nerdly Room") self.sprinklesRoom = Room("the Sprinkles Room") self.playland = Room("Playland") self.lollipopRoom = Room("the Lollipop Room") self.hedgehogRoom = Room("the Hedgehog Room") self.room1 = Room("a room") self.room2 = Room("a room") self.room3 = Room("a room") self.room4 = Room("a room") self.room5 = Room("a room") self.room6 = Room("a room") self.room7 = Room("a room") self.home = Room("YOUR HOUSE!!!") self.bedroom.setDescription("But a large dark hole has opened on your wall... dare you enter?!?"); self.darkCave.setDescription("there are 4 exits, a big opening behind you\nand small holes in the wall to the south, southeast, and east"); self.katie2MazeEntrance.setDescription("This is the entrance to a MAZE... good luck!!!"); self.strawberryRoom.setDescription("This strawberry-filled room is filled with strawberry flavored things!!"); self.tennisCourt.setDescription("You can play tennis...if you want to,\nbut entering here without the tennis racket is DEADLY"); self.volleyballCourt.setDescription("You can play volleyball...if you want to,\nbut entering here without the volleyball is DEADLY"); self.cupcakeRoom.setDescription("This is a room full of cupcakes!!!"); self.nerdlyRoom.setDescription("This is a room full of nerdly candy!!!"); self.playland.setDescription("This is a room full of toys!!!"); self.lollipopRoom.setDescription("This is a room full of lollipops!!!"); self.home.setDescription("You have gotten back to you house before your parents got home! Good job :D"); self.hedgehogRoom.setDescription("This is a room full of hedgehogs!!!"); self.sprinklesRoom.setDescription("This is a room full of sprinkles!!!"); self.room1.setDescription("This is a room of the maze..."); self.room2.setDescription("This is a room of the maze..."); self.room3.setDescription("This is a room of the maze..."); self.room4.setDescription("This is a room of the maze..."); self.room5.setDescription("This is a room of the maze..."); self.room6.setDescription("This is a room of the maze..."); self.room7.setDescription("This is a room of the maze..."); self.bedroom.setExit("south", darkCave); self.darkCave.setExit("north", bedroom); self.darkCave.setExit("east", volleyballCourt); self.darkCave.setExit("south", katie2MazeEntrance); self.darkCave.setExit("southeast", cupcakeRoom); self.cupcakeRoom.setExit("northwest", darkCave); self.cupcakeRoom.setExit("east", nerdlyRoom); self.nerdlyRoom.setExit("west", darkCave); self.nerdlyRoom.setExit("south", cupcakeRoom); self.katie2MazeEntrance.setExit("west", darkCave); self.katie2MazeEntrance.setExit("southeast", room1); self.room1.setExit("north", katie2MazeEntrance); self.room1.setExit("west", katie2MazeEntrance); self.room1.setExit("east", room2); self.room2.setExit("south", room1); self.room2.setExit("west", katie2MazeEntrance); self.room2.setExit("northeast", room3); self.room3.setExit("southwest", room2); self.room3.setExit("west", katie2MazeEntrance); self.room3.setExit("southeast", room4); self.room4.setExit("northwest", room3); self.room4.setExit("west", room5); self.room4.setExit("south", katie2MazeEntrance); self.room5.setExit("west", room4); self.room5.setExit("north", katie2MazeEntrance); self.room5.setExit("northeast", room6); self.room6.setExit("south", room5); self.room6.setExit("west", katie2MazeEntrance); self.room6.setExit("northwest", room7); self.room7.setExit("southeast", room6); self.room7.setExit("west", tennisCourt); self.room7.setExit("northwest", darkCave); self.tennisCourt.setExit("north", room7); self.strawberryRoom.setExit("south", hedgehogRoom); self.cupcakeRoom.setExit("south", sprinklesRoom); self.sprinklesRoom.setExit("northeast", cupcakeRoom); self.sprinklesRoom.setExit("south", playland); self.playland.setExit("west", sprinklesRoom); self.playland.setExit("southeast", lollipopRoom); self.lollipopRoom.setExit("south", playland); self.lollipopRoom.setExit("west", tennisCourt); self.lollipopRoom.setExit("north", hedgehogRoom); self.sprinklesRoom.setExit("southeast", tennisCourt); self.hedgehogRoom.setExit("northwest", lollipopRoom); self.hedgehogRoom.setExit("southwest", home); self.volleyballCourt.setExit("south", strawberryRoom); self.tennisCourt.setExit("northwest", sprinklesRoom); # self.you = self.player = Character() self.person = Character("Bob") self.person.setDescription("a Lollipop Guild member") self.person.setStat(20) self.player.setStat(20) self.lollipopRoom.setNPC(person) self.rnd = Random() self.flashlight = Item("flashlight") self.tennisRacket = Item("tennis racket") self.cupcake = Item ("cupcake") self.smarties = Item ("smarties") self.licorice = Item ("licorice") self.snickers = Item ("Snickers") self.donut = Item ("donut") self.nerds = Item ("Nerds") self.reeses = Item ("Reeses") self.volleyball = Item ("volleyball") self.skittles = Item ("Skittles") self.candyCane = Item ("candy cane") self.mandMs = Item ("M&Ms") self.hersheyBar = Item ("Hershey bar") self.milkyWay = Item ("Milky Way") self.gummyBear = Item ("gummy bear") self.sourPatch = Item ("Sour Patch") self.lollipop = Item ("lollipop") self.jellybeans = Item ("jellybeans") self.ribbon = Item ("ribbon") self.flashlight.setDescription("This is a flashlight, its used for light") self.tennisRacket.setDescription("This is a tennis racket, its used for playing tennis...") self.cupcake.setDescription("a piece of candy!") self.smarties.setDescription("a piece of candy!") self.licorice.setDescription("a piece of candy!") self.snickers.setDescription("a piece of candy!") self.donut.setDescription("a piece of candy!") self.nerds.setDescription("a piece of candy!") self.reeses.setDescription("a piece of candy!") self.volleyball.setDescription("This a volleyball, its used for playing volleyball...") self.skittles.setDescription("a piece of candy!") self.candyCane.setDescription("a piece of candy!") self.m&ms.setDescription("a piece of candy!") self.hersheyBar.setDescription("a piece of candy!") self.milkyWay.setDescription("a piece of candy!") self.gummyBear.setDescription("a piece of candy!") self.sourPatch.setDescription("a piece of candy!") self.lollipop.setDescription("a piece of candy!") self.jellybeans.setDescription("a piece of candy!") self.ribbon.setDescription("A pretty ribbon!!!") self.katie2MazeEntrance.setItem(donut.getKey(), donut) self.bedroom.setItem(flashlight.getKey(), flashlight) self.darkCave.setItem(tennisRacket.getKey(), tennisRacket) self.strawberryRoom.setItem(gummyBear.getKey(), gummyBear) self.volleyballCourt.setItem(lollipop.getKey(), lollipop) self.tennisCourt.setItem(snickers.getKey(), snickers) self.cupcakeRoom.setItem(cupcake.getKey(), cupcake) self.nerdlyRoom.setItem(smarties.getKey(), smarties) self.sprinklesRoom.setItem(licorice.getKey(), licorice) self.playland.setItem(jellybeans.getKey(), jellybeans) self.lollipopRoom.setItem(milkyWay.getKey(), milkyWay) self.hedgehogRoom.setItem(sourPatch.getKey(), sourPatch) self.room1.setItem(nerds.getKey(), nerds) self.room2.setItem(reeses.getKey(), reeses) self.room3.setItem(volleyball.getKey(), volleyball) self.room4.setItem(skittles.getKey(), skittles) self.room5.setItem(candyCane.getKey(), candyCane) self.room6.setItem(m&ms.getKey(), m&ms) self.room7.setItem(hersheyBar.getKey(), hersheyBar) self.home.setItem(ribbon.getKey(), ribbon) def play (self): self.printWelcome() self.updateOutput() self.finished = false while self.finished != true: self.inputLine = self.io.getInput() self.finished = processCommand(inputLine) System.out.println("Byeeeeee!") def printWelcome (self): self.io = Console() self.io.clear() self.io.showOutput("") self.io.showOutput("Hiya! Welcome to my world...") self.io.showOutput("") self.io.showOutput("If you hurry up, you could get through my whole world before your parents get home!") self.io.showOutput("and even get some candy along the way!!!") self.io.showOutput(""); self.io.showOutput("..."); self.io.showOutput(""); self.io.showOutput(""); self.io.showOutput("..."); self.io.showOutput(""); self.io.showOutput(""); self.io.showOutput("..."); self.io.showOutput(""); self.io.showOutput(""); self.io.showOutput("..."); self.io.showOutput(""); self.io.showOutput("") def processCommand (self, inputLine): self.wantToQuit = false word1 = "no" word2 = null self.words = inputLine.split(" ") if words.length > 0: self.word1 = words[0] if words.length > 1: self.word2 = words[1] if word1.equals("help"): doHelp() elif word1.equals("go"): doGo(word2) elif word1.equals("get"): doGet(word2) elif word1.equals("drop"): doDrop(word2) elif word1.equals("examine"): doExamine(word2) elif word1.equals("show"): doShow(word2) elif word1.equals("quit"): wantToQuit = doQuit() else: io.showOutput("Um yeah... I don't know how to do that!"); return wantToQuit def doHelp (self): io.showOutput("You can use the commands: get, drop, examine, go, help, and quit") def doQuit (self): io.showOutput("Thanks for playing Spork, a combination of spam and pork!") return true def doGo (self, direction): if direction == null: print "Go where?" return self.nextRoom = currentRoom.getExit(direction) if nextRoom == null: io.showOutput("I can't go that way.") else: self.items = player.getItemString() for i in range(items.length-10): if currentRoom == volleyballCourt & (items.substring(i, i+10).equalsIgnoreCase("volleyball")) == false: return else: for i in range(items.length-13): if currentRoom == tennisCourt & (items.substring(i, i+13).equalsIgnoreCase("tennis racket")) == false: return currentRoom = nextRoom io.clear() io.showOutput("") io.showOutput("--------------------------------------------------------------"); io.showOutput("") updateOutput() def doGet (self, item): if item == null: print "Get what?" return self.itemFound = currentRoom.containsItem(item) if itemFound == false: io.showOutput("I can't find this item.") else: self.hand = currentRoom.getItem(item) player.setItem(item, hand) currentRoom.removeItem(item) io.clear() io.showOutput("") io.showOutput("--------------------------------------------------------------"); io.showOutput("") updateOutput() def doDrop (self, item): if item == null: print "Drop what?" return self.itemFound = player.hasItem(item); if itemFound == false: io.showOutput("You can't drop the " + item + " if you don't have it!") elif (currentRoom == darkCave): io.showOutput ("Can't you read the sign? ") io.showOutput("") io.showOutput("Sign: Don't drop things on the sidewalk") io.showOutput("") else: self.hand = player.getItem(item) currentRoom.setItem(item, hand) player.removeItem(item) io.clear() io.showOutput("") io.showOutput("--------------------------------------------------------------") io.showOutput("") updateOutput() def doExamine (self, item): if item == null: print "Drop what?" return if player.hasItem(item): io.showOutput(player.getItem(item).getDescription()) elif currentRoom.hasItem(item): io.showOutput("You need to pick up the " + item + " before you can examine it.") else: io.showOutput("I can't find an item.") def doShow (self, command): if command == null: print "Show what?" return elif command.equals("exit"): io.showOutput("Exits: " + currentRoom.getExitString()) else: io.showOutput("I don't know that instruction") def updateOutput (self): # if self.currentRoom == self.darkCave & self.currentRoom.getItemString() != "flashlight": # io.showOutput("Oh look, its dark...\n\n\nhmmmmmmm\n\nmaybe we should try to be able to SEE") # else: self.io.showOutput("You are in " + currentRoom.getKey()) self.io.showOutput(self.currentRoom.getDescription()) if currentRoom.getItemString() != "": self.io.showOutput("There is a " + currentRoom.getItemString() + " in the room!") if currentRoom.getExitString() != "": self.io.showOutput("Exits: " + currentRoom.getExitString()) # if currentRoom.getCharacterString() != "": # self.io.showOutput("Characters: " + currentRoom.getNPCName()) newGame = Game() currentRoom = Room() newGame.play()