diff --git a/works/lab-05/scr/Main.kt b/works/lab-05/scr/Main.kt new file mode 100644 index 0000000..34883f7 --- /dev/null +++ b/works/lab-05/scr/Main.kt @@ -0,0 +1,69 @@ +import kotlin.random.Random + +fun main() { +showTask() + val deck: MutableList = mutableListOf() + + println("Enter the card name.") + repeat(3) + { + print("Card name:") + deck.add(readlnOrNull() ?: "Unknown card") + } + + val discardedCard: String = getString("\nWhich card would you like to discard your deck?", "Card"); br(2) + val wasDiscarded: Boolean = deck.remove(discardedCard) + + println("Result: $wasDiscarded") + for ((index, card) in deck.withIndex()) + println("\tCard №${index + 1} -> $card") + + +showTask(2) + val hand = mapOf( + "Pikachu" to "Pokemon", + "Potion" to "Trainer", + "Fire Energy" to "Energy", + "Professor's Research" to "Trainer" + ) + + val trainerCards = hand.filter { it.value == "Trainer" } + + println("Card with 'trainer':") + for((index, key) in trainerCards.keys.withIndex()) + println("\t$index -> $key") + + val trainerCardsValue = trainerCards.map { it.key.uppercase() } + + println("\nTrainer's cards: ${trainerCardsValue.joinToString(", ")}") + + val energyCount = hand.count { it.value == "Energy" } + + println("\nCards with 'Energy': $energyCount") + +showTask(3) + val energyToAttach = getString("Enter the digit.", "Digit"); br(2) + + val resources = mutableMapOf("Trainer" to 2, "Energy" to 1) + // resources["Energy"] = resources.getValue("Energy") + energyToAttach // Exception + + for ((type, count) in resources) + println("\t$type -> $count") +} + + +//============= System fun +//========================== +fun br(iterations: Byte = 1){ + for (i in 1..