Last active
December 8, 2023 17:08
-
-
Save daverave1212/bb955c54d40be072de3116125133831d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with `groovy caesars-casino.groovy` | |
// (c) 2011 Playtika | |
// This code is licensed under MIT license (see LICENSE.txt) | |
import java.util.Collections; | |
class CaesarsCasino { | |
static void main(String[] args) { | |
def symbolsOnLine = "\$@#7?" | |
def machine = new Machine(symbolsOnLine) | |
print "\033\143" | |
println machine.getStandings() + "\n" | |
println "Press any key to start" | |
System.in.read() | |
while (true) { | |
machine.spinAll() | |
println "Press any key to continue" | |
if (machine.money <= 0) { | |
println "Please buy more coins to play." | |
break | |
} | |
else { System.in.read() } | |
} | |
} | |
} | |
class SlotBelt { | |
def getRandomInt(min, max) { new Random().nextInt((max - min) + 1) + min } | |
public def line = "" | |
public static String shuffleString(String string) { | |
List<String> letters = Arrays.asList string.split("") | |
Collections.shuffle letters | |
String shuffled = "" | |
for (String letter : letters) { shuffled += letter } | |
shuffled | |
} | |
public SlotBelt(String baseLine) { | |
line = baseLine | |
line = shuffleString line | |
getRandomInt(0, 7).times { spinOnce() } | |
} | |
def spinOnce() { line = line[-1] + line[0..-2] } | |
} | |
class Machine { | |
int beltsShowing | |
SlotBelt[] belts | |
String symbols | |
int money = 0 | |
public Machine(symbols) { | |
this.symbols = symbols | |
money = 50000 | |
reset() | |
} | |
def reset() { | |
beltsShowing = 1 | |
belts = new SlotBelt[3].collect { new SlotBelt(symbols) } } | |
def displayAsIs(overhead="") { | |
print "\033\143"; println overhead | |
for (def row in 0..<3) { | |
def rowString = "" | |
for (def col in 0..<beltsShowing) | |
rowString += belts[col].line[row] + " " | |
println rowString | |
} | |
} | |
public def spinAll() { | |
beltsShowing = 1; money -= 5000 | |
for (def i in 0..<belts.length) { | |
7.times { | |
belts[beltsShowing-1].spinOnce() | |
displayAsIs getStandings() | |
sleep 180 | |
} | |
beltsShowing += 1 | |
} | |
if (isLineWin(0) || isLineWin(1) || isLineWin(2)) { | |
println "INCREDIBLE!!!" | |
money += new Random().nextInt(96461 - 13817) + 162 | |
} else { println ":(" } | |
} | |
def isLineWin(lineNum) { | |
for (def i in 1..<belts.length) { | |
if (!belts[i].line[lineNum].equals(belts[i-1].line[lineNum])) return false | |
} | |
true | |
} | |
public def getStandings() { "Current: $money" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment