-
-
Save BlackPrincess/9056368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Id[T](id:Int) { | |
override def toString = "id:"+this.id.toString | |
def == (other: Id[T]) : Boolean = toString == other.toString | |
def next = Id(id + 1) | |
} | |
object AutoId { | |
var _v : Int = 0 | |
def apply[T](): Id[T] = { | |
_v += 1 | |
Id[T](_v) | |
} | |
} | |
trait Entity[T] { | |
val id : Id[T] = AutoId[T] | |
} | |
sealed trait Job extends Entity[Job] | |
case object Knight extends Job | |
case object Rogue extends Job | |
case object Wizard extends Job | |
class Status(val str:Int, val int:Int, val dex:Int) | |
class Actor (val name: String, val status: Status, val job: Job) extends Entity[Actor] | |
class Party(val actors: Seq[Actor]) extends Entity[Party] | |
class BattleSession(parties: Seq[Party]) extends Entity[BattleSession]{ | |
def init = { | |
//... | |
} | |
def process = { | |
parties.foreach { p => | |
println(s"====== Party id:${p.id} turn is comming ======") | |
p.actors.foreach { actor => | |
println(s"${actor.name} action") | |
} | |
} | |
} | |
} | |
val players = new Party( | |
actors = Seq( | |
new Actor ( | |
name = "mizchi", | |
status = new Status(10,10,10), | |
job = Knight), | |
new Actor ( | |
name = "bob", | |
status = new Status(10,11,11), | |
job = Rogue), | |
new Actor ( | |
name = "Chik", | |
status = new Status(10,11,16), | |
job = Wizard) | |
) | |
) | |
val enemies = new Party( | |
actors = Seq( | |
new Actor ( | |
name = "goblin1", | |
status = new Status(5,4,6), | |
job = Rogue), | |
new Actor ( | |
name = "globin2", | |
status = new Status(5,5,5), | |
job = Rogue) | |
) | |
) | |
var session = new BattleSession(List(players, enemies)) | |
session.process | |
println( | |
session | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment