Files
kotlin-kvasnickiy/works/lab-04/scr-1/Main.kt
T
2026-10-19 15:19:58 +03:00

92 lines
2.7 KiB
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
fun main() {
showTask()
var deckSize: Short = 60
var cardsInHand : Short = 0
val targetDraw: Short = getString("How many cards to take?", "Quantity").toShort(); br(2)
while(deckSize > 0 && cardsInHand != targetDraw)
{
cardsInHand++
deckSize--
println("[ДОБОР] Взята карта №$cardsInHand В руке: $cardsInHand карт, в колоде осталось: $deckSize")
}
showTask(2)
var energyCost: Short = 0
while(true)
{
energyCost = getString("Set the energy cost.", "Cost").toShort(); br(2)
if (energyCost > -1)
break
println("Energy cost cannot be less than 0.")
}
showTask(3)
var enemyHp: Short = getString("Set enemy Hp.", "Hp").toShort(); br(2)
var round: Byte = 1
val maxRound: Byte = 10
while(round <= maxRound)
{
if(round % 2 == 0)
println("Раунд $round: [Эффект Защиты] Раунд пропускается.\n")
else
{
enemyHp = (enemyHp - 25).toShort()
if (enemyHp < 0)
enemyHp = 0
println("Раунд $round: Нанесено 25 урона. У противника осталось $enemyHp HP.")
if(enemyHp == 0.toShort()) {
println("Покемон противника упал без сил! Прерываем бой.")
break
}
}
round++
}
showTask(4)
var damageCounters: Byte = 0
val maxCounters: Byte = 5
while(damageCounters < maxCounters)
{
println("Наложен жетон урона №${damageCounters + 1}")
damageCounters++
}
showTask(5)
var statusDuration = 3 // Продолжительность
while (statusDuration > 0) { // Пока продолжительность больше 0
println("Покемон находится под действием эффекта 'Паралич'. Осталось ходов: $statusDuration") // Вывести строку с информацией
statusDuration-- // Уменьшить продолжительность на 1
}
println("Действие эффекта 'Паралич' закончилось!") // Вывести строку с информацией
}
//============= System fun
//==========================
fun br(iterations: Byte = 1){
for (i in 1..<iterations)
println()
}
fun showTask(number: Byte = 1){
if (number != 1.toByte())
br(3)
println("=== Task № $number ===")
}
fun getString(question: String, variable: String): String{
print("$question\n$variable: ")
return readlnOrNull() ?: "null"
}