Initial commit
This commit is contained in:
commit
41dd944fca
34
build.gradle.kts
Normal file
34
build.gradle.kts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
plugins {
|
||||||
|
kotlin("jvm") version "2.0.0"
|
||||||
|
application
|
||||||
|
distribution
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
mainClass.set("xyz.maxwellj.gambling.MainKt")
|
||||||
|
layout.buildDirectory.dir("distributions/")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "xyz.maxwellj.gambling"
|
||||||
|
version = "0.0.1"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Jar> {
|
||||||
|
manifest {
|
||||||
|
attributes["Main-Class"] = "xyz.maxwellj.gambling.MainKt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation(kotlin("test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
kotlin {
|
||||||
|
jvmToolchain(17)
|
||||||
|
}
|
5
settings.gradle.kts
Normal file
5
settings.gradle.kts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
plugins {
|
||||||
|
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
|
||||||
|
}
|
||||||
|
rootProject.name = "xyz.maxwellj.gambling"
|
||||||
|
|
369
src/main/kotlin/Main.kt
Normal file
369
src/main/kotlin/Main.kt
Normal file
|
@ -0,0 +1,369 @@
|
||||||
|
package xyz.maxwellj.gambling
|
||||||
|
|
||||||
|
import java.security.KeyStore.TrustedCertificateEntry
|
||||||
|
import kotlin.random.Random
|
||||||
|
import kotlin.collections.listOf as listOf
|
||||||
|
|
||||||
|
fun genCards(gameType: Int): List<String> {
|
||||||
|
var cards = listOf("")
|
||||||
|
for (i in 1..4) {
|
||||||
|
if (i == 1) {
|
||||||
|
cards = cards + ("A♥")
|
||||||
|
} else if (i == 2) {
|
||||||
|
cards = cards + ("A♣")
|
||||||
|
} else if (i == 3) {
|
||||||
|
cards = cards + ("A♦")
|
||||||
|
} else if (i == 4) {
|
||||||
|
cards = cards + ("A♠")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in 2..10) {
|
||||||
|
val cardNumber = i
|
||||||
|
for (i in 1..4) {
|
||||||
|
if (i == 1) {
|
||||||
|
cards = cards + (cardNumber.toString() + "♥")
|
||||||
|
} else if (i == 2) {
|
||||||
|
cards = cards + (cardNumber.toString() + "♣")
|
||||||
|
} else if (i == 3) {
|
||||||
|
cards = cards + (cardNumber.toString() + "♦")
|
||||||
|
} else if (i == 4) {
|
||||||
|
cards = cards + (cardNumber.toString() + "♠")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in 1..4) {
|
||||||
|
if (i == 1) {
|
||||||
|
cards = cards + ("J♥")
|
||||||
|
} else if (i == 2) {
|
||||||
|
cards = cards + ("J♣")
|
||||||
|
} else if (i == 3) {
|
||||||
|
cards = cards + ("J♦")
|
||||||
|
} else if (i == 4) {
|
||||||
|
cards = cards + ("J♠")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in 1..4) {
|
||||||
|
if (i == 1) {
|
||||||
|
cards = cards + ("Q♥")
|
||||||
|
} else if (i == 2) {
|
||||||
|
cards = cards + ("Q♣")
|
||||||
|
} else if (i == 3) {
|
||||||
|
cards = cards + ("Q♦")
|
||||||
|
} else if (i == 4) {
|
||||||
|
cards = cards + ("Q♠")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in 1..4) {
|
||||||
|
if (i == 1) {
|
||||||
|
cards = cards + ("K♥")
|
||||||
|
} else if (i == 2) {
|
||||||
|
cards = cards + ("K♣")
|
||||||
|
} else if (i == 3) {
|
||||||
|
cards = cards + ("K♦")
|
||||||
|
} else if (i == 4) {
|
||||||
|
cards = cards + ("K♠")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gameType == 1) {
|
||||||
|
cards = cards + "Joker"
|
||||||
|
cards = cards + "Joker"
|
||||||
|
}
|
||||||
|
cards = cards.drop(1)
|
||||||
|
return(cards)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun genVals(gameType: Int): List<String> {
|
||||||
|
var cardValues = listOf("")
|
||||||
|
if (gameType == 0) {
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + "11"
|
||||||
|
}
|
||||||
|
} else if (gameType == 1) {
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + "14"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i in 2..10) {
|
||||||
|
val currentValue = i
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + currentValue.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gameType == 0) {
|
||||||
|
for (i in 1..12) {
|
||||||
|
cardValues = cardValues + "10"
|
||||||
|
}
|
||||||
|
} else if (gameType == 1) {
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + "11"
|
||||||
|
}
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + "12"
|
||||||
|
}
|
||||||
|
for (i in 1..4) {
|
||||||
|
cardValues = cardValues + "13"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (gameType == 1) {
|
||||||
|
cardValues = cardValues + "100"
|
||||||
|
cardValues = cardValues + "100"
|
||||||
|
}
|
||||||
|
cardValues = cardValues.drop(1)
|
||||||
|
return(cardValues)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun blackjack(): Int {
|
||||||
|
val lossCode = 1
|
||||||
|
var cards = genCards(0)
|
||||||
|
var cardValues = genVals(0)
|
||||||
|
println("Cards created!")
|
||||||
|
val seed = System.nanoTime()
|
||||||
|
var shuffledCards = cards.shuffled(Random(seed))
|
||||||
|
var shuffledValues = cardValues.shuffled(Random(seed))
|
||||||
|
println("Cards shuffled!")
|
||||||
|
println("Welcome to Blackjack! Your goal is to get as close to 21 as possible, or at least beat the dealer. If you're ready, press enter. If you need help, type 'help' and more instructions will be given.")
|
||||||
|
val userInput = readln()
|
||||||
|
if (userInput == "help") {
|
||||||
|
println("this is a work in progress")
|
||||||
|
} else {
|
||||||
|
println("Let's play!")
|
||||||
|
var yourHand = listOf(shuffledCards[0], shuffledCards[2])
|
||||||
|
var yourCount = shuffledValues[0].toInt() + shuffledValues[2].toInt()
|
||||||
|
var dealerHand = listOf(shuffledCards[1], shuffledCards[3])
|
||||||
|
var dealerCount = shuffledValues[1].toInt() + shuffledValues[3].toInt()
|
||||||
|
var deckCardNumber = 4
|
||||||
|
var agressiveDealer = 0
|
||||||
|
if (dealerCount == 21) {
|
||||||
|
println("Dealer wins with a blackjack! They had $dealerHand")
|
||||||
|
return(1)
|
||||||
|
} else if (yourCount == 21) {
|
||||||
|
println("Blackjack! You had $yourHand")
|
||||||
|
return(3)
|
||||||
|
}
|
||||||
|
println("The dealer's revealed card is ${dealerHand[1]}")
|
||||||
|
var haveYouFinished = 0
|
||||||
|
while (haveYouFinished == 0) {
|
||||||
|
println("You have ${yourHand}, giving you $yourCount points. Hit or stand?")
|
||||||
|
val userInput = readln()
|
||||||
|
if (userInput == "hit") {
|
||||||
|
println("Your card is ${shuffledCards[deckCardNumber]}")
|
||||||
|
yourHand = yourHand + shuffledCards[deckCardNumber]
|
||||||
|
if (shuffledValues[deckCardNumber] == "11") {
|
||||||
|
println("You got an ace! 1 or 11?")
|
||||||
|
val userInput = readln()
|
||||||
|
if (userInput == "11") {
|
||||||
|
println("Your ace is now worth 11.")
|
||||||
|
yourCount += 11
|
||||||
|
} else {
|
||||||
|
println("Your ace is now worth 1.")
|
||||||
|
yourCount += 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
yourCount += shuffledValues[deckCardNumber].toInt()
|
||||||
|
}
|
||||||
|
deckCardNumber += 1
|
||||||
|
if (yourCount == 21) {
|
||||||
|
println("You got 21! You win... unless the dealer can do better.")
|
||||||
|
val agressiveDealer = 1
|
||||||
|
haveYouFinished = 1
|
||||||
|
} else if (yourCount > 21) {
|
||||||
|
println("You went bust... Better luck next time!")
|
||||||
|
return(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("You chose to stand, let's see how the dealer does...")
|
||||||
|
val agressiveDealer = 0
|
||||||
|
haveYouFinished = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (agressiveDealer == 1) {
|
||||||
|
println("The dealer has ${dealerHand}, giving them ${dealerCount} points.")
|
||||||
|
while (dealerCount < yourCount) {
|
||||||
|
dealerHand += shuffledCards[deckCardNumber]
|
||||||
|
dealerCount += shuffledValues[deckCardNumber].toInt()
|
||||||
|
println("The dealer draws a ${shuffledCards[deckCardNumber]}")
|
||||||
|
deckCardNumber += 1
|
||||||
|
if (dealerCount == 21){
|
||||||
|
println("The dealer hit 21! You lost...")
|
||||||
|
println("You had $yourHand giving you $yourCount points. The dealer had $dealerHand giving them $dealerCount points.")
|
||||||
|
val lossCode = 1
|
||||||
|
} else if (dealerCount > 21){
|
||||||
|
println("The dealer went bust! You win!")
|
||||||
|
println("You had $yourHand giving you $yourCount points. The dealer had $dealerHand giving them $dealerCount points.")
|
||||||
|
val lossCode = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (dealerCount < 17) {
|
||||||
|
println("The dealer has ${dealerHand}, giving them ${dealerCount} points.")
|
||||||
|
dealerHand += shuffledCards[deckCardNumber]
|
||||||
|
dealerCount += shuffledValues[deckCardNumber].toInt()
|
||||||
|
println("The dealer draws a ${shuffledCards[deckCardNumber]}")
|
||||||
|
deckCardNumber += 1
|
||||||
|
if (dealerCount == 21) {
|
||||||
|
println("The dealer hit 21! You lost...")
|
||||||
|
val lossCode = 1
|
||||||
|
} else if (dealerCount > 21) {
|
||||||
|
println("The dealer went bust! You win!")
|
||||||
|
val lossCode = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
println("The dealer stayed on $dealerCount with $dealerHand")
|
||||||
|
if (yourCount > dealerCount) {
|
||||||
|
println("You got more points than the dealer! You win!")
|
||||||
|
println("You had $yourHand giving you $yourCount points. The dealer had $dealerHand giving them $dealerCount points.")
|
||||||
|
val lossCode = 2
|
||||||
|
} else if (yourCount < dealerCount) {
|
||||||
|
println("The dealer got more points than you... Better luck next time!")
|
||||||
|
println("You had $yourHand giving you $yourCount points. The dealer had $dealerHand giving them $dealerCount points.")
|
||||||
|
val lossCode = 1
|
||||||
|
} else if (yourCount == dealerCount) {
|
||||||
|
println("You and the dealer tied... No one won.")
|
||||||
|
println("You had $yourHand giving you $yourCount points. The dealer had $dealerHand giving them $dealerCount points.")
|
||||||
|
val lossCode = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println(lossCode)
|
||||||
|
return(lossCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun poopoohead(): Int {
|
||||||
|
println("Work in progress at the moment, expect bugs!")
|
||||||
|
var cards = genCards(1)
|
||||||
|
var cardValues = genVals(1)
|
||||||
|
println("Cards created!")
|
||||||
|
val seed = System.nanoTime()
|
||||||
|
var shuffledCards = cards.shuffled(Random(seed))
|
||||||
|
var shuffledValues = cardValues.shuffled(Random(seed))
|
||||||
|
println("Cards shuffled!")
|
||||||
|
var yourUnderhand = listOf(shuffledCards[0], shuffledCards[2], shuffledCards[4])
|
||||||
|
var yourUnderhandIndex = listOf(0, 2, 4)
|
||||||
|
var yourUnderhandObfuscated = listOf("?", "?", "?")
|
||||||
|
var dealerUnderhand = listOf(shuffledCards[1], shuffledCards[3], shuffledCards[5])
|
||||||
|
var dealerUnderhandIndex = listOf(1, 3, 5)
|
||||||
|
var dealerUnderhandObfuscated = listOf("?", "?", "?")
|
||||||
|
var yourOverhand = listOf(shuffledCards[6], shuffledCards[8], shuffledCards[10])
|
||||||
|
var yourOverhandIndex = listOf(6, 8, 10)
|
||||||
|
var dealerOverhand = listOf(shuffledCards[7], shuffledCards[9], shuffledCards[11])
|
||||||
|
var dealerOverhandIndex = listOf(7, 9, 11)
|
||||||
|
var yourHand = listOf(shuffledCards[12], shuffledCards[13], shuffledCards[14])
|
||||||
|
var yourHandIndex = listOf(12, 13, 14)
|
||||||
|
var dealerHand = listOf(shuffledCards[15], shuffledCards[16], shuffledCards[17])
|
||||||
|
var dealerHandIndex = listOf(15, 16, 17)
|
||||||
|
var dealerHandObfuscated = listOf("?", "?", "?")
|
||||||
|
val gameLoop = 1
|
||||||
|
var nextCard = 18
|
||||||
|
var currentCard = ""
|
||||||
|
var currentCardValue = 0
|
||||||
|
while (gameLoop == 1) {
|
||||||
|
println("--dealer--")
|
||||||
|
println(dealerHandObfuscated)
|
||||||
|
println(dealerOverhand)
|
||||||
|
println(dealerUnderhandObfuscated)
|
||||||
|
println("----------")
|
||||||
|
println(currentCard)
|
||||||
|
println("----------")
|
||||||
|
println(yourUnderhandObfuscated)
|
||||||
|
println(yourOverhand)
|
||||||
|
println(yourHand)
|
||||||
|
println("---you---")
|
||||||
|
println("Which card do you pick? Type which number along card you want")
|
||||||
|
val cardPicked = readln().toInt()
|
||||||
|
val cardPickedIndex = yourHandIndex[cardPicked]
|
||||||
|
val powerCard = 0
|
||||||
|
var canPlayCard = 0
|
||||||
|
var discardPile = listOf("")
|
||||||
|
discardPile = discardPile.drop(1)
|
||||||
|
var discardPileIndex = listOf(0)
|
||||||
|
println(currentCardValue)
|
||||||
|
for (i in yourHandIndex) {
|
||||||
|
if (shuffledValues[i].toInt() > currentCardValue) {
|
||||||
|
canPlayCard = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (canPlayCard == 1) {
|
||||||
|
if (shuffledValues[cardPickedIndex] == "2") {
|
||||||
|
currentCard = yourHand[cardPicked]
|
||||||
|
currentCardValue = 0
|
||||||
|
yourHandIndex = yourHandIndex.minus(yourHandIndex[cardPicked])
|
||||||
|
yourHand = yourHand.minus(yourHand[cardPicked])
|
||||||
|
yourHandIndex = yourHandIndex + nextCard
|
||||||
|
yourHand = yourHand + shuffledCards[nextCard]
|
||||||
|
nextCard += 1
|
||||||
|
val powerCard = 1
|
||||||
|
} else if (shuffledCards[cardPickedIndex] == "3") {
|
||||||
|
yourHandIndex = yourHandIndex.minus(yourHandIndex[cardPicked])
|
||||||
|
yourHand = yourHand.minus(yourHand[cardPicked])
|
||||||
|
yourHandIndex = yourHandIndex + nextCard
|
||||||
|
yourHand = yourHand + shuffledCards[nextCard]
|
||||||
|
nextCard += 1
|
||||||
|
val powerCard = 1
|
||||||
|
} else if (shuffledValues[cardPickedIndex].toInt() < currentCardValue - 1) {
|
||||||
|
if (powerCard == 0) {
|
||||||
|
println("you cant play that card nerd")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentCard = yourHand[cardPicked]
|
||||||
|
currentCardValue = shuffledValues[cardPickedIndex].toInt()
|
||||||
|
yourHandIndex = yourHandIndex.minus(yourHandIndex[cardPicked])
|
||||||
|
yourHand = yourHand.minus(yourHand[cardPicked])
|
||||||
|
yourHandIndex = yourHandIndex + nextCard
|
||||||
|
yourHand = yourHand + shuffledCards[nextCard]
|
||||||
|
nextCard += 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("You couldn't play! You pick up a bunch of cards. Press enter to continue")
|
||||||
|
currentCard = ""
|
||||||
|
currentCardValue = 0
|
||||||
|
readln()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
var moneyLeft = 1000
|
||||||
|
println("Welcome to the casino! You have some money, and need to make profit.")
|
||||||
|
while (moneyLeft > 0) {
|
||||||
|
println("You have $$moneyLeft.")
|
||||||
|
println("How much do you want to gamble? Enter a number")
|
||||||
|
val moneyGambled = readln().toInt()
|
||||||
|
if (moneyGambled > moneyLeft) {
|
||||||
|
println("You don't have that much money, so all or nothing I guess")
|
||||||
|
val moneyGambled = moneyLeft
|
||||||
|
}
|
||||||
|
println("Do you want to play blackjack or poopoohead?")
|
||||||
|
val userInput = readln()
|
||||||
|
val lossCode = 0
|
||||||
|
if (userInput == "blackjack") {
|
||||||
|
val lossCode = blackjack()
|
||||||
|
if (lossCode == 0) {
|
||||||
|
println("Since you tied, you lost no money. Happy days!")
|
||||||
|
} else if (lossCode == 1) {
|
||||||
|
println("You lost nerd. Minus $moneyGambled...")
|
||||||
|
moneyLeft -= moneyGambled
|
||||||
|
} else if (lossCode == 2) {
|
||||||
|
println("Nice! You doubled your money! Gain $moneyGambled!")
|
||||||
|
moneyLeft += moneyGambled
|
||||||
|
} else if (lossCode == 3) {
|
||||||
|
println("Wowsers! You drew a blackjack! You tripled that money! Gain ${moneyGambled * 2}")
|
||||||
|
moneyLeft += moneyGambled * 2
|
||||||
|
}
|
||||||
|
} else if (userInput == "poopoohead") {
|
||||||
|
val lossCode = poopoohead()
|
||||||
|
if (lossCode == 1) {
|
||||||
|
println("You lost nerd. Minus $moneyGambled...")
|
||||||
|
moneyLeft -= moneyGambled
|
||||||
|
} else if (lossCode == 2) {
|
||||||
|
println("Nice! You doubled your money! Gain $moneyGambled!")
|
||||||
|
moneyLeft += moneyGambled
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println("Next time select something please")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("imagine running out of money noob")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user