Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************ANDY MECHALAKOS********************
- //******COMP SCI 110**PROF. DUNCAN***************
- //******PROJECT 2- ADVENTURE GAME****************
- println ("Welcome to Doofenschmirtz, the game.")
- println ("The main objective of this game is to collect all the parts before Perry saves the day.")
- println ("In order to play, move through doors by typing N,W,S or E to move.")
- println ("You have 20 minutes to build the device by collecting the parts and going to the workshop.")
- println ("Every time you walk through a door, time moves by 1 minute.")
- //Declaring names of the parts
- var part1 = 0
- var part2 = 0
- var part3 = 0
- var part4 = 0
- var finaldevice = 0
- var time = 21
- def getRequest(): String = {
- println("Where do you want to go?")
- readLine()
- }
- // All of the room code below
- def room1() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- //Map of the game
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ X ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 1")
- println("------")
- println (+ time +" Minutes Remaining.")
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- println("You cannot go there.")
- return room1() // Go back to room 1
- case "E" =>
- // Go to room 6
- return room6()
- case "S" =>
- // Go to room 2
- return room2()
- case "W" =>
- // Go to room 3
- return room3()
- }
- }
- def room2() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ X ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 2")
- println("------")
- println (+ time +" Minutes Remaining.")
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- // Go to room 1
- return room1() // Go to room 1
- case "E" =>
- println ("You cannot go there")
- return room2() // stay in room 2
- case "S" =>
- // Go to room 7
- return room7()
- case "W" =>
- // Go to room 4
- return room4()
- }
- }
- def room3() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ X ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 3")
- println("------")
- println (+ time +" Minutes Remaining.")
- if (part3 == 1) {
- if (part4 == 0) {
- println ("You Collected part number 4!")
- println ()
- println ("You may have collected all the parts but Perry is moving faster")
- println ("to stop you.")
- if (time > 5) {
- time = 5
- }
- } else {
- println ("You need part 3 first, please find it and return here.")
- }
- part4 = 1
- }
- // Get and process the request (moving on to the next state/room)
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- println("You cannot go there.")
- return room3() // Go back to room 3
- case "E" =>
- // Go to room 1
- return room1()
- case "S" =>
- // Go to room 4
- return room4()
- case "W" =>
- println("You cannot go there.")
- return room3() // Go back to room 3
- }
- }
- def room4() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ X ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 4")
- println("------")
- println (+ time +" Minutes Remaining.")
- if (part1 == 1) {
- if (part2 == 0) {
- println ("You collected part number 2!")
- }
- part2 = 1
- } else {
- println ("You need part 1 first, please find it and return here.")
- }
- // Get and process the request (moving on to the next state/room)
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- // Go to room 3
- return room3()
- case "E" =>
- // Go to room 2
- return room2()
- case "S" =>
- println("You cannot go there.")
- return room4() // Go back to room 4
- case "W" =>
- println("You cannot go there.")
- return room4() // Go back to room 4
- }
- }
- def room6() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ X ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 6")
- println("------")
- println (+ time +" Minutes Remaining.")
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- println("You cannot go there.")
- return room6() // Go back to room 1
- case "E" =>
- // Go to room 9
- return room9()
- case "S" =>
- // Go to room 5
- return room5()
- case "W" =>
- // Go to room 1
- return room1()
- }
- }
- def room9() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ X ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 9")
- println("------")
- println (+ time +" Minutes Remaining.")
- if (part1 == 0) {
- println ("You collected part number 1!")
- }
- part1 = 1
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- println("You cannot go there.")
- return room9() // Go back to room 1
- case "E" =>
- println ("You cannot go there")
- return room9()
- case "S" =>
- // Go to room 10
- return room10()
- case "W" =>
- // Go to room 6
- return room6()
- }
- }
- def room10() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[ X ]*")
- // Print the message
- println()
- println("------")
- println("Room 10/Workshop")
- println("------")
- println (+ time +" Minutes Remaining.")
- if (part1 == 1 && part2 == 1 && part3 == 1 && part4 == 1) {
- finaldevice = 1
- println ("Congratulations, you won!")
- sys.exit(1)
- }
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- return room9() // Go to room 9
- case "E" =>
- println ("You cannot go there")
- return room10()
- case "S" =>
- println ("You cannot go there")
- return room10()
- case "W" =>
- // Go to room 8
- return room8()
- }
- }
- def room8() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ X ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 8")
- println("------")
- println (+ time +" Minutes Remaining.")
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- return room5() // Go to room 5
- case "E" =>
- // go to room 10
- return room10()
- case "S" =>
- println ("You cannot go there")
- return room8()
- case "W" =>
- // Go to room 7
- return room7()
- }
- }
- def room5() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]****[ X ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ 7 ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 5")
- println("------")
- println (+ time +" Minutes Remaining.")
- if (part2 == 1) {
- if (part3 == 0) {
- println ("You collected part number 3!")
- }
- part3 = 1
- } else {
- println ("You need part 2 first, please find it and return here.")
- }
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- return room6() // Go to room 6
- case "E" =>
- println ("You cannot go there")
- return room5()
- case "S" =>
- //go to room 8
- return room8()
- case "W" =>
- println ("You cannot go there")
- return room5()
- }
- }
- def room7() {
- time -= 1
- if (time == 0) {
- println ("Sorry, you failed to assemble the device in time. Maybe another day")
- sys.exit(1)
- }
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println()
- println ("___North___")
- println ("West-||-East")
- println ("___South___")
- println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
- println ("****|********|********|*******|***")
- println ("**[ 4 ]----[ 2 ]----[ 5 ]*****|***")
- println ("*************|********|*******|***")
- println ("***********[ X ]----[ 8 ]---[W-S]*")
- // Print the message
- println()
- println("------")
- println("Room 7")
- println("------")
- println (+ time +" Minutes Remaining.")
- val move = getRequest.toUpperCase
- move match {
- case "N" =>
- return room2() // Go to room 2
- case "E" =>
- //go to room 8
- return room8()
- case "S" =>
- println ("You cannot go there")
- return room7()
- case "W" =>
- println ("You cannot go there")
- return room7()
- }
- }
- room1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement