Start creating test battle

This commit is contained in:
Matt Soucy 2019-12-07 12:30:21 -05:00
parent 2683ce69a9
commit 49f469475d
2 changed files with 59 additions and 8 deletions

View File

@ -0,0 +1,45 @@
package me.msoucy.ptures
import me.msoucy.ptures.controller.Engine
import me.msoucy.ptures.controller.SingleBattle
import me.msoucy.ptures.model.Creature
import me.msoucy.ptures.model.Skills
import me.msoucy.ptures.model.Team
import me.msoucy.ptures.view.BattleViewText
import me.msoucy.ptures.view.PlayerViewText
val CreatureA = with(Creature()) {
name = "CreatureA"
genes.atk = 7
genes.def = 3
skills.add(Skills.Tackle)
skills.add(Skills.DoubleKick)
this
}
val CreatureB = with(Creature()) {
name = "CreatureB"
skills.add(Skills.Tackle)
skills.add(Skills.Ember)
this
}
val TeamA = with(Team(PlayerViewText(1))) {
creatures.add(CreatureA)
this
}
val TeamB = with(Team(PlayerViewText(2))) {
creatures.add(CreatureB)
this
}
val TestBattle = SingleBattle(TeamA, TeamB)
object PTureTest {
@JvmStatic
fun main(arg: Array<String>) {
println("Hello, world!")
val e = Engine(TestBattle)
e.resolveTurn(BattleViewText())
}
}

View File

@ -10,8 +10,8 @@ class SkillViewText(skill: Skill) : SkillView(skill) {
println(skill.name) println(skill.name)
} }
override fun displayEnumerated(idx: Int) { override fun displayEnumerated(idx : Int) {
println("${idx + 1}: ${skill.name}") println("-: ${skill.name}")
} }
} }
@ -25,15 +25,17 @@ class CreatureViewText(playerId: Int, creature: Creature) : CreatureView(playerI
skillViews.forEachIndexed { index, skillView -> skillViews.forEachIndexed { index, skillView ->
skillView.displayEnumerated(index) skillView.displayEnumerated(index)
} }
var idx = -1 var chosenSkill : Skill? = null
while (idx != -1) { while (chosenSkill == null) {
print("> ") print("> ")
val tmpIdx = readLine()?.toIntOrNull() ?: -1 val tmpName = readLine() ?: ""
if (tmpIdx in creature.skills.indices) { val possibleSkills = creature.skills.filter { it.name == tmpName }
idx = tmpIdx if(possibleSkills.isNotEmpty())
{
chosenSkill = possibleSkills.first()
} }
} }
return creature.skills[idx] return chosenSkill
} }
private fun chooseTarget(skill: Skill, possibleTargets: List<Creature>): List<Creature> { private fun chooseTarget(skill: Skill, possibleTargets: List<Creature>): List<Creature> {
@ -68,4 +70,8 @@ class CreatureViewText(playerId: Int, creature: Creature) : CreatureView(playerI
class PlayerViewText(playerId: Int) : PlayerView(playerId) { class PlayerViewText(playerId: Int) : PlayerView(playerId) {
override fun creatureViewFor(creature: Creature) = CreatureViewText(playerId, creature) override fun creatureViewFor(creature: Creature) = CreatureViewText(playerId, creature)
}
class BattleViewText : BattleView() {
} }