Advertisement
Guest User

The coding is be real

a guest
Oct 1st, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 4.48 KB | None | 0 0
  1. object CrapsVersionFinal extends App {
  2. println("This is the Craps game. In order to win you must roll either a 7 or 11 on your first roll.")
  3. println("If you roll a 2 first you lose. Anything else and you roll again.")
  4. println("On any more rolls you undertake, you must roll the same number as the first roll to win.")
  5. println("If you roll a 7 you lose. Anything else and you re-roll. Repeat ad-infinitum.")
  6. println("Press enter to begin.")
  7. var Cheater = readLine();
  8. println();
  9. var RepeatGame = false
  10. var Wins = 0
  11. var Losses = 0
  12. def printWandL()    {
  13.   println("Total Wins: "+Wins+"")
  14.   println("Tota Losses: "+Losses+"")
  15. }
  16. if (Cheater.equalsIgnoreCase("I want to be a winner"))  {
  17.   var Cheats = true
  18.   Wins = 1000000
  19.   Losses = 0
  20.   do    {
  21.       printWandL();
  22.       var resultRollOne = 3
  23.       var resultRollTwo = 4
  24.       var Total = resultRollOne+resultRollTwo
  25.       println("You rolled a "+resultRollOne+" and a "+resultRollTwo+". Your total is "+Total+", therefore you win!")
  26.       Wins = Wins + 1
  27.       println("Play again? Y/N.")
  28.       var Response = readLine();
  29.       if (Response.equalsIgnoreCase("Yes")  || Response.equalsIgnoreCase("Y")   || Response.equalsIgnoreCase("Yes."))   {
  30.         Cheats = true
  31.         println("Press enter to roll again.")
  32.         readLine();
  33.       }
  34.       else  {
  35.         Cheats = false
  36.         println("Game terminated. You sure are a winner.")
  37.         printWandL();
  38.         var exit = true
  39.         while(exit == true) {        
  40.         }
  41.       }
  42.   }
  43.   while (Cheats == true)
  44. }
  45. do {
  46.     printWandL();
  47.     var number = 6
  48.     def DiceRoll():Long = {
  49.       var Roll = Math.round(Math.random()*number)
  50.       if (Roll == 0)    {
  51.         var IsZero = true
  52.         while (IsZero == true)  {
  53.             Roll = Math.round(Math.random()*number)
  54.             if (Roll != 0)  {
  55.                 IsZero = false
  56.                 return Roll
  57.             }
  58.         }
  59.       }
  60.       else  {
  61.         return Roll
  62.       }
  63.       return 1
  64.     }
  65.     var resultRollOne = DiceRoll();
  66.     var resultRollTwo = DiceRoll();
  67.     var Total = resultRollOne + resultRollTwo
  68.     var StoredTotal = Total
  69.     if (Total == 7 || Total == 11)  {
  70.         println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you win.")
  71.         println("Play again? Y/N.")
  72.         var Response = readLine();
  73.         if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
  74.           RepeatGame = true
  75.         }
  76.         else    {
  77.           println("Game terminated. Have a nice day.")
  78.           printWandL();
  79.           RepeatGame = false
  80.         }
  81.         Wins = Wins + 1
  82.     }
  83.     else if (Total == 2)    {
  84.       println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you lose.")
  85.       println("Play again? Y/N.")
  86.       var Response = readLine();
  87.         if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
  88.             RepeatGame = true
  89.         }
  90.       else  {
  91.             println("Game terminated. Have a nice day.")
  92.             printWandL();
  93.             RepeatGame = false
  94.       }
  95.       Losses = Losses + 1
  96.     }
  97.     else    {
  98.       var RepeatGameTwo = true
  99.       println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", which results in no win nor penalty.")
  100.       do    {
  101.           println("Press enter to roll again.")
  102.           readLine();
  103.           resultRollOne = DiceRoll();
  104.           resultRollTwo = DiceRoll();
  105.           Total = resultRollOne + resultRollTwo
  106.           if (StoredTotal == Total) {
  107.               println("You rolled a "+resultRollOne+" and a "+resultRollTwo+".")
  108.               println("Your second roll was the same as the first ("+Total+"), therefore you win.")
  109.               println("Play again? Y/N.")
  110.               var Response = readLine();
  111.               if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes"))   {
  112.                   RepeatGame = true
  113.                   RepeatGameTwo = false
  114.         }
  115.               else  {
  116.                   println("Game terminated. Have a nice day.")
  117.                   printWandL();
  118.                   RepeatGame = false
  119.                   RepeatGameTwo = false
  120.               }
  121.               Wins = Wins + 1
  122.           }
  123.           else if (Total == 7)  {
  124.               StoredTotal = 0
  125.               println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you lose.")
  126.               println("Play again? Y/N.")
  127.               var Response = readLine();
  128.               if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes"))   {
  129.                   RepeatGame = true
  130.                   RepeatGameTwo = false
  131.               }
  132.               else  {
  133.                   println("Game terminated. Have a nice day.")
  134.                   printWandL();
  135.                   RepeatGame = false
  136.                   RepeatGameTwo = false
  137.               }
  138.               Losses = Losses + 1
  139.           }
  140.           else  {
  141.               println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", which results in no win nor penalty.")
  142.       }
  143.       }
  144.       while (RepeatGameTwo == true)
  145. }
  146. }
  147. while (RepeatGame == true)
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement