Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. package engine
  2.  
  3. import o1.adventure.Action
  4. import o1.adventure.Area
  5. import o1.adventure.Item
  6. import o1.adventure.Player
  7. import scala.Vector
  8.  
  9.  
  10. class Adventure {
  11.  
  12. /** The title of the adventure game. */
  13. val title = "Cook's Assistant Quest"
  14.  
  15. private val castle = new Area("Castle", "You are in the Lumbridge castle. You see the cook here.")
  16. private val frontYard = new Area("Front yard", "You are in the front yard of the Lumbridge castle.")
  17. private val goblinField = new Area("Goblin field", "You are surrounded by goblins. Luckily they don't seem aggressive.")
  18. private val cowField = new Area("Cow field", "You are in the cow field. You see plenty of cows. Maybe you should try to milk one of them.")
  19. private val chickenCoop = new Area("Chicken coop", "You are in a chicken coop. Chickens are flocking around you.")
  20. private val grainField = new Area("Grain field", "You are in a grain field.")
  21. private val mill = new Area("Mill", "You are in the mill. This could probably be used for making flour.")
  22. private val northCastle = new Area("North of castle", "You are north of the castle.")
  23.  
  24. private val destination = castle
  25.  
  26. private val egg = new Item("battery", "It's a small battery cell. Looks new.")
  27. private val grain = new Item("remote", "It's the remote control for your TV.\nWhat it was doing in the forest, you have no idea.\nProblem is, there's no battery.")
  28. private val bucket = ???
  29. private val pot = ???
  30.  
  31. castle.setNeighbors(Vector("east" -> frontYard))
  32. frontYard.setNeighbors(Vector("north" -> northCastle, "east" -> goblinField, "west" -> castle))
  33. goblinField.setNeighbors(Vector("north" -> cowField, "west" -> frontYard))
  34. cowField.setNeighbors(Vector("north" -> chickenCoop, "south" -> goblinField, "west" -> northCastle))
  35. chickenCoop.setNeighbors(Vector("south" -> cowField))
  36. northCastle.setNeighbors(Vector("north" -> grainField, "east" -> goblinField, "south" -> frontYard))
  37. grainField.setNeighbors(Vector("south" -> northCastle, "west" -> mill))
  38. mill.setNeighbors(Vector("east" -> grainField))
  39.  
  40.  
  41. val player = new Player(castle)
  42.  
  43.  
  44. var turnCount = 0
  45.  
  46. val timeLimit = 40
  47.  
  48.  
  49. def isComplete = this.player.location == this.destination && this.player.has("remote") && this.player.has("battery")
  50.  
  51. def isOver = this.isComplete || this.player.hasQuit || this.turnCount == this.timeLimit
  52.  
  53. def welcomeMessage = "You are lost in the woods. Find your way back home.\n\nBetter hurry, 'cause Scalatut elämät is on real soon now. And you can't miss Scalkkarit, right?"
  54.  
  55.  
  56. def goodbyeMessage = {
  57. if (this.isComplete)
  58. "Home at last... and phew, just in time! Well done!"
  59. else if (this.turnCount == this.timeLimit)
  60. "Oh no! Time's up. Starved of entertainment, you collapse and weep like a child.\nGame over!"
  61. else // game over due to player quitting
  62. "Quitter!"
  63. }
  64.  
  65.  
  66. def playTurn(command: String) = {
  67. val action = new Action(command)
  68. val outcomeReport = action.execute(this.player)
  69. if (outcomeReport.isDefined) {
  70. this.turnCount += 1
  71. }
  72. outcomeReport.getOrElse("Unknown command: \"" + command + "\".")
  73. }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement