generated from admin/template
change code
This commit is contained in:
@@ -1,14 +1,53 @@
|
||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
fun calcDamage(power: Int, multiplier: Double = 1.0): Int = (power * multiplier).toInt()
|
||||
fun checkStatus(hp: Int): String {
|
||||
return if (hp > 0) "В строю" else "Нокаут"
|
||||
}
|
||||
fun printBattleLog(attacker: String, defender: String, damage: Int) {
|
||||
println("[БОЙ] $attacker атакует $defender и наносит $damage урона!")
|
||||
}
|
||||
fun useTrainerCard(cardName: String, healAmount: Int = 20, drawCards: Int = 0) {
|
||||
println("Применена карта '$cardName': восстанавливает $healAmount HP, берёт карт: $drawCards.")
|
||||
}
|
||||
fun processTurn(hp: Int, damage: Int, effect: (Int) -> Int): Int {
|
||||
val hpAfterDamage = hp - damage
|
||||
return effect(hpAfterDamage)
|
||||
}
|
||||
fun main() {
|
||||
val name = "Kotlin"
|
||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
||||
// to see how IntelliJ IDEA suggests fixing it.
|
||||
println("Hello, " + name + "!")
|
||||
|
||||
for (i in 1..5) {
|
||||
//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("=== ИНИЦИАЛИЗАЦИЯ БОЯ ===")
|
||||
print("Введите имя вашего Покемона: ")
|
||||
val playerPokemon = readln()
|
||||
print("Введите стартовое HP (по умолчанию 60): ")
|
||||
val hpInput = readln()
|
||||
val startHp = if (hpInput.isBlank()) 60 else hpInput.toInt()
|
||||
val enemyPokemon = "Charizard"
|
||||
println()
|
||||
println("=== РАУНД 1: АТАКА И КРАТКИЕ ФУНКЦИИ ===")
|
||||
val basePower = 20
|
||||
val weaknessMultiplier = 1.5
|
||||
println("Атакующий: $playerPokemon | Защищающийся: $enemyPokemon")
|
||||
println("Базовый урон: $basePower | Множитель слабости: $weaknessMultiplier")
|
||||
val damageDealt = calcDamage(basePower, weaknessMultiplier)
|
||||
printBattleLog(playerPokemon, enemyPokemon, damageDealt)
|
||||
val enemyHp = 100 - damageDealt
|
||||
val enemyStatus = checkStatus(enemyHp)
|
||||
println("Статус $enemyPokemon: $enemyStatus")
|
||||
println()
|
||||
println("=== РАУНД 2: ИСПОЛЬЗОВАНИЕ КАРТ (ИМЕНОВАННЫЕ АРГУМЕНТЫ) ===")
|
||||
println("Применяем карту Potion:")
|
||||
useTrainerCard("Potion")
|
||||
println("Применяем карту Professor's Research (только берутся карты):")
|
||||
useTrainerCard(cardName = "Professor's Research", drawCards = 3)
|
||||
println()
|
||||
println("=== РАУНД 3: ФУНКЦИЯ ВЫСШЕГО ПОРЯДКА И ЛЯМБДА ===")
|
||||
println("$enemyPokemon наносит ответный урон!")
|
||||
print("Введите полученный $playerPokemon урон: ")
|
||||
val incomingDamage = readln().toInt()
|
||||
println("Применяем зелье лечения (+15 HP) через лямбда-эффект...")
|
||||
val finalHp = processTurn(startHp, incomingDamage) { currentHp -> currentHp + 15 }
|
||||
println("Итоговое HP $playerPokemon после атаки и лечения: $finalHp")
|
||||
println("Текущий статус $playerPokemon: ${checkStatus(finalHp)}")
|
||||
println()
|
||||
println("========================================")
|
||||
println("ИТОГ БОЯ: Бой завершен успешно. Все функции выполнены.")
|
||||
println("========================================")
|
||||
}
|
||||
Reference in New Issue
Block a user