Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object CrapsVersionFinal extends App {
- println("This is the Craps game. In order to win you must roll either a 7 or 11 on your first roll.")
- println("If you roll a 2 first you lose. Anything else and you roll again.")
- println("On any more rolls you undertake, you must roll the same number as the first roll to win.")
- println("If you roll a 7 you lose. Anything else and you re-roll. Repeat ad-infinitum.")
- println("Press enter to begin.")
- var Cheater = readLine();
- println();
- var RepeatGame = false
- var Wins = 0
- var Losses = 0
- var number = 6
- var Cheats = false
- def printWandL() {
- println("Total Wins: "+Wins+"")
- println("Total Losses: "+Losses+"")
- }
- def DiceRoll():Long = {
- var Roll = Math.round(Math.random()*number)
- if (Cheats == false) {
- if (Roll == 0) {
- var IsZero = true
- while (IsZero == true) {
- Roll = Math.round(Math.random()*number)
- if (Roll != 0) {
- IsZero = false
- return Roll
- }
- }
- }
- else {
- return Roll
- }
- }
- return 1
- }
- if (Cheater.equalsIgnoreCase("I want to be a winner")) {
- var Cheats = true
- Wins = 1337
- Losses = 0
- do {
- printWandL();
- var Total = 7
- Wins += 1
- println("You rolled a 3 and a 4. Your total is 7, therefore you win!")
- println("Play again? Y/N.")
- var Response = readLine();
- if (Response.equalsIgnoreCase("Yes") || Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes.")) {
- Cheats = true
- println("Press enter to roll again.")
- readLine();
- }
- else {
- Cheats = false
- println("Game terminated. You sure are a winner.")
- printWandL();
- var exit = true
- while(exit == true) {
- }
- }
- }
- while (Cheats == true)
- }
- else {
- }
- do {
- printWandL();
- var resultRollOne = DiceRoll();
- var resultRollTwo = DiceRoll();
- var Total = resultRollOne + resultRollTwo
- var StoredTotal = Total
- if (Total == 7 || Total == 11) {
- Wins += 1
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you win.")
- println("Play again? Y/N.")
- var Response = readLine();
- if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
- RepeatGame = true
- }
- else {
- println("Game terminated. Have a nice day.")
- printWandL();
- RepeatGame = false
- }
- }
- else if (Total == 2) {
- Losses += 1
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you lose.")
- println("Play again? Y/N.")
- var Response = readLine();
- if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
- RepeatGame = true
- }
- else {
- println("Game terminated. Have a nice day.")
- printWandL();
- RepeatGame = false
- }
- }
- else {
- var RepeatGameTwo = true
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", which results in no win nor penalty.")
- do {
- println("Press enter to roll again.")
- readLine();
- resultRollOne = DiceRoll();
- resultRollTwo = DiceRoll();
- Total = resultRollOne + resultRollTwo
- if (StoredTotal == Total) {
- Wins += 1
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+".")
- println("Your second roll was the same as the first ("+Total+"), therefore you win.")
- println("Play again? Y/N.")
- var Response = readLine();
- if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
- RepeatGame = true
- RepeatGameTwo = false
- }
- else {
- println("Game terminated. Have a nice day.")
- printWandL();
- RepeatGame = false
- RepeatGameTwo = false
- }
- }
- else if (Total == 7) {
- Losses += 1
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", therefore you lose.")
- println("Play again? Y/N.")
- var Response = readLine();
- if (Response.equalsIgnoreCase("Y") || Response.equalsIgnoreCase("Yes")) {
- RepeatGame = true
- RepeatGameTwo = false
- }
- else {
- println("Game terminated. Have a nice day.")
- printWandL();
- RepeatGame = false
- RepeatGameTwo = false
- }
- }
- else {
- println("You rolled a "+resultRollOne+" and a "+resultRollTwo+", your total is "+Total+", which results in no win nor penalty.")
- }
- }
- while (RepeatGameTwo == true)
- }
- }
- while (RepeatGame == true)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement