diff --git a/works/lesson5/.gitignore b/works/lesson5/.gitignore new file mode 100644 index 0000000..3ddbf4c --- /dev/null +++ b/works/lesson5/.gitignore @@ -0,0 +1,32 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Kotlin ### +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/works/lesson5/src/Main.kt b/works/lesson5/src/Main.kt new file mode 100644 index 0000000..16692f3 --- /dev/null +++ b/works/lesson5/src/Main.kt @@ -0,0 +1,72 @@ +import java.util.Scanner + +fun main() { + val scanner = Scanner(System.`in`) + + println("ФОРМИРОВАНИЕ КОЛОДЫ") + + val deck: MutableList = mutableListOf() + + for (i in 1..3) { + print("Введите карту №$i: ") + val card = scanner.nextLine() + deck.add(card) + } + + println("Колода собрана (${deck.size} карт): ${deck.joinToString(", ")}") + println() + + print("Какую карту сбросить? ") + val discardedCard = scanner.nextLine() + + val wasDiscarded = deck.remove(discardedCard) + + if (wasDiscarded == true) { + println("✔ Карта '$discardedCard' сброшена. Осталось: ${deck.size}") + } else { + println("❌ Карта '$discardedCard' не найдена в колоде. Осталось: ${deck.size}") + } + println() + + println("АНАЛИЗ РУКИ") + + 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" } + + val trainerNames = trainerCards.keys.joinToString(", ") + println("Карт Тренеров в руке: ${trainerCards.size} ($trainerNames)") + + val energyCountInHand = hand.count { it.value == "Energy" } + println("Карт энергии в руке: $energyCountInHand") + + val allHandNames = hand.map { it.key } + println("Содержимое руки: ${allHandNames.joinToString(", ")}") + println() + + println("УЧЕТ РЕСУРСОВ") + + print("Сколько энергии прикрепить? ") + val energyToAttach = scanner.nextInt() + + val resources = mutableMapOf("Trainer" to 2, "Energy" to 1) + + val currentEnergy = resources["Energy"] + if (currentEnergy != null) { + resources["Energy"] = currentEnergy + energyToAttach + } + + println("Ресурсы на столе:") + for ((type, count) in resources) { + println("$type: $count шт.") + } + println() + + println("ИТОГ: Колода: ${deck.size} карт | Рука: ${hand.size} карт | Энергия на столе: ${resources["Energy"]}") +}