This commit is contained in:
2026-10-05 19:04:05 +03:00
parent 7c2d313a81
commit 244ac43876
+41 -11
View File
@@ -1,14 +1,44 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() { fun main() {
val name = "Kotlin" println("=== ФОРМИРОВАНИЕ КОЛОДЫ ===")
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text val deck: MutableList<String> = mutableListOf()
// to see how IntelliJ IDEA suggests fixing it. repeat(3) { index ->
println("Hello, " + name + "!") print("Введите карту №${index + 1}: ")
val card = readln()
for (i in 1..5) { deck.add(card)
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
println("i = $i")
} }
println("Колода собрана (${deck.size} карт): ${deck.joinToString(", ")}")
print("\nКакую карту сбросить? ")
val discardedCard = readln()
val wasDiscarded: Boolean = deck.remove(discardedCard)
if (wasDiscarded) {
println("✔ Карта '$discardedCard' сброшена. Осталось: ${deck.size}")
} else {
println("✘ Карта '$discardedCard' не найдена в колоде.")
}
println("\n=== АНАЛИЗ РУКИ ===")
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("Карт Тренеров в руке: ${trainerCards.size} (${trainerCards.keys.joinToString(", ")})")
val energyCount = hand.count { it.value == "Energy" }
println("Карт энергии в руке: $energyCount")
val cardNames = hand.map { it.key }
println("Содержимое руки: ${cardNames.joinToString(", ")}")
println("\n=== УЧЕТ РЕСУРСОВ ===")
val resources = mutableMapOf("Trainer" to 2, "Energy" to 1)
print("Сколько энергии прикрепить? ")
val energyToAttach = readln().toInt()
resources["Energy"] = resources.getValue("Energy") + energyToAttach
println("Ресурсы на столе:")
for ((type, count) in resources) {
println("$type: $count шт.")
}
println()
println("========================================")
println("ИТОГ: Колода: ${deck.size} карт | Рука: ${hand.size} карт | Энергия на столе: ${resources["Energy"]}")
println("========================================")
} }