Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Created April 16, 2014 14:58
Show Gist options
  • Save DeepSky8/10889696 to your computer and use it in GitHub Desktop.
Save DeepSky8/10889696 to your computer and use it in GitHub Desktop.
You can't have an if inside a case
object WagerGameAction extends GameAction {
def execute(gameState: GameState): GameState = gameState match {
case Wager(stake) => {
println(wagers)
print(increments25)
print(increments25ForYou)
val betVal = readLine()
val realBet = confirm(scala.math.abs(betVal.toInt))
if (!afford(realBet, stake)) {
println("You don't have enough credits to back that bet. You have " + stake + " credits. ")
Wager(stake)
} else {
val flip = r.nextInt(2)
print(headsTails)
println(freddyBet)
val tails = readLine()
val result = wager(realBet, call(tails), stake, flip)
println(readOut(feedBack(result)))
val (_, _, newTotal) = result
print("Are you ready for another match of Outback CoinFlip? You can wager up to " + newTotal + " credits. ")
val input = readLine()
input.toLowerCase match {
case "yes" => Wager(newTotal)
case "no" => End
case _ => StartAgain(newTotal)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment