Advertisement
Guest User

Untitled

a guest
May 6th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 13.01 KB | None | 0 0
  1. //************ANDY MECHALAKOS********************
  2. //******COMP SCI 110**PROF. DUNCAN***************
  3. //******PROJECT 2- ADVENTURE GAME****************
  4.  
  5.  
  6. println ("Welcome to Doofenschmirtz, the game.")
  7. println ("The main objective of this game is to collect all the parts before Perry saves the day.")
  8. println ("In order to play, move through doors by typing N,W,S or E to move.")
  9. println ("You have 20 minutes to build the device by collecting the parts and going to the workshop.")
  10. println ("Every time you walk through a door, time moves by 1 minute.")
  11. //Declaring names of the parts
  12. var part1 = 0
  13. var part2 = 0
  14. var part3 = 0
  15. var part4 = 0
  16. var finaldevice = 0
  17. var time = 21
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. def getRequest(): String = {
  25.    println("Where do you want to go?")
  26.    readLine()
  27.    }
  28. // All of the room code below
  29. def room1() {
  30.   time -= 1
  31.   if (time == 0) {
  32.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  33.     sys.exit(1)
  34.   }
  35.    
  36. println()
  37. println()
  38. println()
  39. println()
  40. println()
  41. println()
  42. println()
  43. println()
  44. println()
  45. //Map of the game
  46. println ("___North___")
  47. println ("West-||-East")
  48. println ("___South___")
  49. println ("**[ 3 ]----[ X ]----[ 6 ]---[ 9 ]*")
  50. println ("****|********|********|*******|***")
  51. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  52. println ("*************|********|*******|***")
  53. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  54. // Print the message
  55.    println()
  56.    println("------")
  57.    println("Room 1")
  58.    println("------")
  59.     println (+ time +" Minutes Remaining.")
  60.    
  61.  
  62.    
  63.    
  64.     val move = getRequest.toUpperCase
  65.    move match {
  66.       case "N" =>
  67.          println("You cannot go there.")
  68.          return room1()  // Go back to room 1
  69.       case "E" =>
  70.          // Go to room 6
  71.          
  72.          return room6()  
  73.       case "S" =>
  74.          // Go to room 2
  75.          return room2()
  76.       case "W" =>
  77.          // Go to room 3
  78.          
  79.          return room3()
  80.          
  81.      
  82.    }
  83. }
  84. def room2() {
  85. time -= 1
  86. if (time == 0) {
  87.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  88.     sys.exit(1)
  89.   }
  90. println()
  91. println()
  92. println()
  93. println()
  94. println()
  95. println()
  96. println()
  97. println()
  98. println()
  99. println ("___North___")
  100. println ("West-||-East")
  101. println ("___South___")
  102. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  103. println ("****|********|********|*******|***")
  104. println ("**[ 4 ]----[ X ]****[ 5 ]*****|***")
  105. println ("*************|********|*******|***")
  106. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  107. // Print the message
  108.    println()
  109.    println("------")
  110.    println("Room 2")
  111.    println("------")
  112.     println (+ time +" Minutes Remaining.")
  113.    
  114.    
  115.  val move = getRequest.toUpperCase
  116.    move match {
  117.       case "N" =>
  118.          // Go to room 1
  119.          return room1()  // Go to room 1
  120.       case "E" =>
  121.          println ("You cannot go there")
  122.          return room2()  // stay in room 2
  123.       case "S" =>
  124.          // Go to room 7
  125.        
  126.          return room7()
  127.       case "W" =>
  128.          // Go to room 4
  129.          
  130.          return room4()
  131.    
  132.    }
  133. }
  134.  
  135.  
  136. def room3() {
  137.   time -= 1
  138.   if (time == 0) {
  139.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  140.     sys.exit(1)
  141.   }
  142.  
  143.   println()
  144. println()
  145. println()
  146. println()
  147. println()
  148. println()
  149. println()
  150. println()
  151. println()
  152. println ("___North___")
  153. println ("West-||-East")
  154. println ("___South___")
  155. println ("**[ X ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  156. println ("****|********|********|*******|***")
  157. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  158. println ("*************|********|*******|***")
  159. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  160.  
  161.    // Print the message
  162.    println()
  163.    println("------")
  164.    println("Room 3")
  165.    println("------")
  166.     println (+ time +" Minutes Remaining.")
  167.    
  168.    if (part3 == 1) {
  169.    if (part4 == 0) {
  170.  
  171.    println ("You Collected part number 4!")
  172.    println ()
  173.    println ("You may have collected all the parts but Perry is moving faster")
  174.    println ("to stop you.")
  175.    if (time > 5) {
  176.      time = 5
  177.    }
  178.     } else {
  179.    println ("You need part 3 first, please find it and return here.")
  180.    }
  181.  part4 = 1
  182.    }
  183.    // Get and process the request (moving on to the next state/room)
  184.    val move = getRequest.toUpperCase
  185.    move match {
  186.       case "N" =>
  187.          println("You cannot go there.")
  188.          return room3()  // Go back to room 3
  189.       case "E" =>
  190.          // Go to room 1
  191.          return room1()
  192.       case "S" =>
  193.          // Go to room 4
  194.          
  195.          return room4()
  196.          
  197.       case "W" =>
  198.          println("You cannot go there.")
  199.          return room3()  // Go back to room 3
  200.      
  201.    }
  202. }
  203.  
  204.  
  205. def room4() {
  206. time -= 1
  207. if (time == 0) {
  208.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  209.     sys.exit(1)
  210.   }
  211.  
  212. println()
  213. println()
  214. println()
  215. println()
  216. println()
  217. println()
  218. println()
  219. println()
  220. println()
  221. println ("___North___")
  222. println ("West-||-East")
  223. println ("___South___")
  224. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  225. println ("****|********|********|*******|***")
  226. println ("**[ X ]----[ 2 ]****[ 5 ]*****|***")
  227. println ("*************|********|*******|***")
  228. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  229.  
  230.    // Print the message
  231.    println()
  232.    println("------")
  233.    println("Room 4")
  234.    println("------")
  235.    println (+ time +" Minutes Remaining.")
  236.   if (part1 == 1) {
  237.    if (part2 == 0) {
  238.    println ("You collected part number 2!")
  239.    }
  240.    part2 = 1
  241.    } else {
  242.    println ("You need part 1 first, please find it and return here.")
  243.    }
  244.    // Get and process the request (moving on to the next state/room)
  245. val move = getRequest.toUpperCase
  246.    move match {
  247.       case "N" =>
  248.          // Go to room 3
  249.          return room3()
  250.       case "E" =>
  251.          // Go to room 2
  252.          return room2()
  253.       case "S" =>
  254.          println("You cannot go there.")
  255.          return room4()  // Go back to room 4
  256.       case "W" =>
  257.          println("You cannot go there.")
  258.          return room4()  // Go back to room 4
  259.      
  260.    }
  261. }
  262. def room6() {
  263.   time -= 1
  264.   if (time == 0) {
  265.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  266.     sys.exit(1)
  267.   }
  268. println()
  269. println()
  270. println()
  271. println()
  272. println()
  273. println()
  274. println()
  275. println()
  276. println()
  277. println ("___North___")
  278. println ("West-||-East")
  279. println ("___South___")
  280. println ("**[ 3 ]----[ 1 ]----[ X ]---[ 9 ]*")
  281. println ("****|********|********|*******|***")
  282. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  283. println ("*************|********|*******|***")
  284. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  285. // Print the message
  286.    println()
  287.    println("------")
  288.    println("Room 6")
  289.    println("------")
  290.  
  291. println (+ time +" Minutes Remaining.")
  292.  
  293. val move = getRequest.toUpperCase
  294.    move match {
  295.       case "N" =>
  296.          println("You cannot go there.")
  297.          return room6()  // Go back to room 1
  298.       case "E" =>
  299.          // Go to room 9
  300.          
  301.          return room9()  
  302.       case "S" =>
  303.          // Go to room 5
  304.          return room5()
  305.       case "W" =>
  306.          // Go to room 1
  307.          
  308.          return room1()
  309.      
  310.    }
  311. }
  312. def room9() {
  313.     time -= 1
  314.     if (time == 0) {
  315.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  316.     sys.exit(1)
  317.   }
  318. println()
  319. println()
  320. println()
  321. println()
  322. println()
  323. println()
  324. println()
  325. println()
  326. println()
  327. println ("___North___")
  328. println ("West-||-East")
  329. println ("___South___")
  330. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ X ]*")
  331. println ("****|********|********|*******|***")
  332. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  333. println ("*************|********|*******|***")
  334. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  335. // Print the message
  336.    println()
  337.    println("------")
  338.    println("Room 9")
  339.    println("------")
  340.  
  341.    println (+ time +" Minutes Remaining.")
  342.  
  343.  
  344.  
  345. if (part1 == 0) {
  346.    println ("You collected part number 1!")
  347.    }
  348.  part1 = 1
  349.  
  350. val move = getRequest.toUpperCase
  351.    move match {
  352.       case "N" =>
  353.          println("You cannot go there.")
  354.          return room9()  // Go back to room 1
  355.       case "E" =>
  356.          println ("You cannot go there")
  357.          
  358.          return room9()  
  359.       case "S" =>
  360.          // Go to room 10
  361.          return room10()
  362.       case "W" =>
  363.          // Go to room 6
  364.          
  365.          return room6()
  366.      
  367.    }
  368. }
  369. def room10() {
  370.  
  371. time -= 1
  372. if (time == 0) {
  373.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  374.     sys.exit(1)
  375.   }
  376. println()
  377. println()
  378. println()
  379. println()
  380. println()
  381. println()
  382. println()
  383. println()
  384. println()
  385. println ("___North___")
  386. println ("West-||-East")
  387. println ("___South___")
  388. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  389. println ("****|********|********|*******|***")
  390. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  391. println ("*************|********|*******|***")
  392. println ("***********[ 7 ]----[ 8 ]---[ X ]*")
  393. // Print the message
  394.    println()
  395.    println("------")
  396.    println("Room 10/Workshop")
  397.    println("------")
  398.    println (+ time +" Minutes Remaining.")
  399.         if (part1 == 1 && part2 == 1 && part3 == 1 && part4 == 1) {
  400.        finaldevice = 1
  401.        println ("Congratulations, you won!")
  402.        sys.exit(1)
  403.        
  404.       }
  405.  
  406.  
  407. val move = getRequest.toUpperCase
  408.    move match {
  409.       case "N" =>
  410.          
  411.          return room9()  // Go to room 9
  412.       case "E" =>
  413.          println ("You cannot go there")
  414.          
  415.          return room10()  
  416.       case "S" =>
  417.          println ("You cannot go there")
  418.          return room10()
  419.       case "W" =>
  420.          // Go to room 8
  421.          
  422.          return room8()
  423.      
  424.    }
  425. }
  426. def room8() {
  427.   time -= 1
  428.   if (time == 0) {
  429.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  430.     sys.exit(1)
  431.   }
  432. println()
  433. println()
  434. println()
  435. println()
  436. println()
  437. println()
  438. println()
  439. println()
  440. println()
  441. println ("___North___")
  442. println ("West-||-East")
  443. println ("___South___")
  444. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  445. println ("****|********|********|*******|***")
  446. println ("**[ 4 ]----[ 2 ]****[ 5 ]*****|***")
  447. println ("*************|********|*******|***")
  448. println ("***********[ 7 ]----[ X ]---[W-S]*")
  449. // Print the message
  450.    println()
  451.    println("------")
  452.    println("Room 8")
  453.    println("------")
  454.  
  455. println (+ time +" Minutes Remaining.")
  456. val move = getRequest.toUpperCase
  457.    move match {
  458.       case "N" =>
  459.          
  460.          return room5()  // Go to room 5
  461.       case "E" =>
  462.         // go to room 10
  463.          
  464.          return room10()  
  465.       case "S" =>
  466.          println ("You cannot go there")
  467.          return room8()
  468.       case "W" =>
  469.          // Go to room 7
  470.          
  471.          return room7()
  472.      
  473.    }
  474. }
  475.  
  476. def room5() {
  477. time -= 1
  478. if (time == 0) {
  479.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  480.     sys.exit(1)
  481.   }
  482. println()
  483. println()
  484. println()
  485. println()
  486. println()
  487. println()
  488. println()
  489. println()
  490. println()
  491. println ("___North___")
  492. println ("West-||-East")
  493. println ("___South___")
  494. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  495. println ("****|********|********|*******|***")
  496. println ("**[ 4 ]----[ 2 ]****[ X ]*****|***")
  497. println ("*************|********|*******|***")
  498. println ("***********[ 7 ]----[ 8 ]---[W-S]*")
  499. // Print the message
  500.    println()
  501.    println("------")
  502.    println("Room 5")
  503.    println("------")
  504.    println (+ time +" Minutes Remaining.")
  505.    if (part2 == 1) {
  506. if (part3 == 0) {
  507.    println ("You collected part number 3!")
  508.    }
  509.    part3 = 1
  510.  } else {
  511.    println ("You need part 2 first, please find it and return here.")
  512.    }
  513. val move = getRequest.toUpperCase
  514.    move match {
  515.       case "N" =>
  516.          
  517.          return room6()  // Go to room 6
  518.       case "E" =>
  519.         println ("You cannot go there")
  520.          return room5()  
  521.       case "S" =>
  522.          //go to room 8
  523.          return room8()
  524.       case "W" =>
  525.         println ("You cannot go there")
  526.          return room5()
  527.      
  528.    }
  529. }
  530. def room7() {
  531.     time -= 1
  532.     if (time == 0) {
  533.     println ("Sorry, you failed to assemble the device in time. Maybe another day")
  534.     sys.exit(1)
  535.   }
  536. println()
  537. println()
  538. println()
  539. println()
  540. println()
  541. println()
  542. println()
  543. println()
  544. println()
  545. println ("___North___")
  546. println ("West-||-East")
  547. println ("___South___")
  548. println ("**[ 3 ]----[ 1 ]----[ 6 ]---[ 9 ]*")
  549. println ("****|********|********|*******|***")
  550. println ("**[ 4 ]----[ 2 ]----[ 5 ]*****|***")
  551. println ("*************|********|*******|***")
  552. println ("***********[ X ]----[ 8 ]---[W-S]*")
  553. // Print the message
  554.    println()
  555.    println("------")
  556.    println("Room 7")
  557.    println("------")
  558.    println (+ time +" Minutes Remaining.")
  559. val move = getRequest.toUpperCase
  560.    move match {
  561.       case "N" =>
  562.          
  563.          return room2()  // Go to room 2
  564.       case "E" =>
  565.         //go to room 8
  566.          return room8()  
  567.       case "S" =>
  568.          println ("You cannot go there")
  569.          return room7()
  570.       case "W" =>
  571.         println ("You cannot go there")
  572.          return room7()
  573.      
  574.    }
  575. }
  576. room1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement