Created
February 13, 2018 22:36
-
-
Save joshskeen/91b2e3be8f48bd97f4ce1bf7cebc939e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.File | |
import kotlin.math.roundToInt | |
var playerGold = 10 | |
var playerSilver = 10 | |
var firstNames = listOf("Little Eli", "Gwenevere", "Mookie", "Julius") | |
var lastNames = listOf("Aurelius", "Jenkins", "Falteroy", "Skeen") | |
fun main(args: Array<String>) { | |
val readText = File("data/drinkdata.csv").readText() | |
val availableDrinks = readText.split("\n").map { it.split(",") } | |
val generatePatrons = generatePlayers() | |
generatePatrons.forEach { patron -> | |
orderDrink(patron, availableDrinks.shuffled().first()) //parses a csv of the drinks | |
} | |
} | |
fun generatePlayers(): List<String> { | |
val patrons = (1..20).map { | |
firstNames.shuffled().first() + " " + lastNames.shuffled().first() | |
} | |
//an alternative - which uses set and converts back to list under the hood :D | |
//.distinct() | |
println(patrons) | |
val uniquePatrons = patrons.toSet().toList() | |
return uniquePatrons | |
} | |
//spirit,deluxe seadog,7.991 | |
private fun orderDrink(character: String = "Madrigal", drinkData: List<String>) { | |
val drinkType = drinkData[0] | |
val drinkName = drinkData[1] | |
val drinkPrice = drinkData[2] | |
//a faster way to show this would be to use .split - also would be more real world..and frankly | |
// possibly easier to understand as well with a little bit of explanation that we'll see all the details of list | |
println("SimTavern -> orderDrink type: $drinkType , name: $drinkName , price: $drinkPrice") | |
val bartenderRemarks = | |
"Ah, a delicious $drinkType...nothing satisfies like a $drinkName." | |
println("Bartender: $bartenderRemarks") | |
purchaseDrink(drinkPrice.toDouble()) | |
println("$character consumes a $drinkName.") | |
println("$character exclaims: " + l33tSpeak("${drinkName}s are delicious!")) | |
} | |
fun purchaseDrink(price: Double) { | |
displayBalance() | |
// exchange rate: 1 gold = 100 silvers. if a player buys a drink costing 5.932, | |
// it should result in a remaining balance of 4.17 after rounding .16999 to .17 (after modulus) | |
val balanceTotal = playerGold + (playerSilver / 100.0) | |
println("total purse, converted to gold: " + balanceTotal) | |
val remaining = balanceTotal - price | |
println("total purse remaining, in gold: ${String.format("%.2f", remaining)}") | |
val remainingGold = remaining.toInt() | |
val remainingSilver = (remaining % 1 * 100).roundToInt() //any way to skip the round to int? | |
playerGold = remainingGold | |
playerSilver = remainingSilver | |
displayBalance() | |
} | |
//FMC : deal with a negative balance | |
private fun displayBalance() { | |
println("player's account balance: gold: $playerGold , silver: $playerSilver") | |
} | |
private fun l33tSpeak(nameOfDrink: String) = | |
nameOfDrink.replace(Regex("[aeiou]")) { | |
when (it.value) { | |
"a" -> "4" | |
"e" -> "3" | |
"i" -> "1" | |
"o" -> "0" | |
else -> it.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment