Добавил новые работы
This commit is contained in:
@@ -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
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="2.4" />
|
||||
<option name="languageVersion" value="2.4" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.4.10" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.10/kotlin-stdlib-2.4.10.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.10/kotlin-stdlib-2.4.10-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.10/kotlin-stdlib-2.4.10-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" default="true" project-jdk-name="openjdk-27" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/lab-06.iml" filepath="$PROJECT_DIR$/lab-06.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
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
|
||||
): Unit {
|
||||
println("[БОЙ] $attacker атакует $defender и наносит $damage урона!")
|
||||
}
|
||||
|
||||
fun useTrainerCard(
|
||||
cardName: String,
|
||||
healAmount: Int = 20,
|
||||
drawCards: Int = 0
|
||||
): Unit {
|
||||
println(
|
||||
"Применена карта '$cardName': восстанавливает $healAmount HP, " +
|
||||
"берёт карт: $drawCards."
|
||||
)
|
||||
}
|
||||
|
||||
fun processTurn(
|
||||
hp: Int,
|
||||
damage: Int,
|
||||
effect: (Int) -> Int
|
||||
): Int {
|
||||
val remainingHp = hp - damage
|
||||
return effect(remainingHp)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
println("=== ИНИЦИАЛИЗАЦИЯ БОЯ ===")
|
||||
|
||||
print("Введите имя вашего Покемона: ")
|
||||
val pokemonName = readln()
|
||||
|
||||
print("Введите стартовое HP (по умолчанию 60): ")
|
||||
val startHp = readln().toIntOrNull() ?: 60
|
||||
|
||||
println()
|
||||
|
||||
println("=== РАУНД 1: АТАКА И КРАТКИЕ ФУНКЦИИ ===")
|
||||
|
||||
val defender = "Charizard"
|
||||
val baseDamage = 20
|
||||
val weaknessMultiplier = 1.5
|
||||
|
||||
println("Атакующий: $pokemonName | Защищающийся: $defender")
|
||||
println("Базовый урон: $baseDamage | Множитель слабости: $weaknessMultiplier")
|
||||
|
||||
val damage = calcDamage(baseDamage, weaknessMultiplier)
|
||||
printBattleLog(pokemonName, defender, damage)
|
||||
|
||||
val charizardHp = 100 - damage
|
||||
println("Статус $defender: ${checkStatus(charizardHp)}.")
|
||||
|
||||
println()
|
||||
|
||||
println("=== РАУНД 2: ИСПОЛЬЗОВАНИЕ КАРТ (ИМЕНОВАННЫЕ АРГУМЕНТЫ) ===")
|
||||
|
||||
println("Применяем карту Potion:")
|
||||
useTrainerCard("Potion")
|
||||
|
||||
println("Применяем карту Professor's Research (только берутся карты):")
|
||||
useTrainerCard(
|
||||
cardName = "Professor's Research",
|
||||
drawCards = 3
|
||||
)
|
||||
|
||||
println()
|
||||
|
||||
println("=== РАУНД 3: ФУНКЦИЯ ВЫСШЕГО ПОРЯДКА И ЛЯМБДА ===")
|
||||
|
||||
println("$defender наносит ответный урон!")
|
||||
print("Введите полученный $pokemonName урон: ")
|
||||
val receivedDamage = readln().toIntOrNull() ?: 0
|
||||
|
||||
println("Применяем зелье лечения (+15 HP) через лямбда-эффект...")
|
||||
|
||||
val finalHp = processTurn(
|
||||
hp = startHp,
|
||||
damage = receivedDamage,
|
||||
effect = { currentHp -> currentHp + 15 }
|
||||
)
|
||||
|
||||
println("Итоговое HP $pokemonName после атаки и лечения: $finalHp")
|
||||
println("Текущий статус $pokemonName: ${checkStatus(finalHp)}")
|
||||
|
||||
println()
|
||||
println("========================================")
|
||||
println("ИТОГ БОЯ: Бой завершен успешно. Все функции выполнены.")
|
||||
println("========================================")
|
||||
}
|
||||
Reference in New Issue
Block a user