Monday 15 August 2011

function - I have two scala projects - basically the same - one works and one does not. Can someone tell me why? -


For the class, we have to make a test-based game in which we walk like the gigantic rooms of old school text games. .

I started by defining the function for different rooms so that it can easily be switched when typed in the room.

This time, the following code works best in REPL, but I want to work all the time:

  def roomOne (): unit = {println ("you Println ("Which door do you want to go through?") Println ("2 doors are: north and west") Var input = readLine ("& gt; & gt;") Subchair match {case "NORTH" => RoomFor () Case "West" = & gt; Roumanine () case "East" => {Println ("You can not go there.") Room one ()} case "south" = & gt; {Println ("You can not go there.") RoomOne ()}}} def roomFour (): unit = {println ("You are currently in cell 4.") Println ("There are two doors: East and South Println ("Do you want to go through the door?"}} Def roomNine (): unit = {println ("you are currently in cell 9") println ("3 doors: north, east and south" ) Println ( "would you like to go through what door?"}} Def startGame (): Unit = {var input = readLine ( "& gt; & gt;") Kupprkas match {case "YES" = & gt; Room one () case "no" => gt; {println ("when you start If you are ready to do, please type \ "yes \".) StartGame ()}}}}}}}}}} "(" ********************************************************************** ************************** **************************************************************** *******) "println (" ************************************************************************************* ************************** **************************************************************** ***************************************** println For some parts? ") StartGame ()   

and the following code does not work at REPL:

  def roomOne (): Unit = {Println ("You are currently in cell 1.") Println ("There are two doors: Short and west ") println (" Which door do you want to go through? ") Var input = readLine (" & Gt; & Gt; ") Ktouprkas match {case" North "= & gt; Rumfor () Case" West "= & gt; Rumnin () Case" East "= & gt; {Println (" you can not be there. " } Room one ()} "south" => gt; {Println ("You can not go there.") RoomOne ()}}} def roomFour (): unit = {println ("You are currently in cell 4 are. ") Println (" two doors: East and South ") Println (" would you like to go through what door? ") Var input = readLine (" & gt; & gt; ") Kuprap case match {case "NORTH"> & gt; {Println ("You can not go there.") RoomFor ()} Case "West" => gt; {Println ( "You can not go there.") Rumfor ()} Case "East" = & gt; Rumfiv () Case "South" = & gt; RoomOne ()}} def roomFive (): Unit = {println ( "You current cell 5 in. ") Println (" three doors: East, South and west ") are println (" which door do you want to Println ( "north, east and south") println ( "how do you door Would you prefer? ")" Diff Roomman "(): Unit = {println (" Are you currently in cell 9 "to go through?")} Def startGame (): Unit = {var input = readLine () "& Gt; & Gt; "). Case Case Match {Case" Yes "=> Case One () Case" No "=> (Println (" When you're ready to start, please type \ "Yes \". ) StartGame ()}}}}}}} println "(" ***************************************************************** "(" *********************** ************************************************** ********************************************** **************************************************************************************************** ************** ************************************************************************************ ************) println ( "Hello Mr. Doafensharmats. what parts to make what Super Dome Inketr are willing to look for it?") StartGame ()   

Can anyone help me? I am trying different things throughout the day and I can not seem to do this work. Why does some work first and does not always? Why does not the second work?

Thank you.

By looking at the pastebine, Pasting your code in REPL. Try it out:

  Scala> Enter paste / paste mode (ctrl-D to end) ... Paste stuff ... ... Ctrl-d    

No comments:

Post a Comment