Skip to content

Commit

Permalink
refs #35 2012/02/15 nightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaneet committed Feb 14, 2012
1 parent 611fece commit 57531d8
Show file tree
Hide file tree
Showing 17 changed files with 486 additions and 406 deletions.
34 changes: 22 additions & 12 deletions models/src/main/scala/Board.scala
@@ -1,7 +1,7 @@
package com.github.alphaneet.suparobo

object Board {
sealed case class Status(id: Int, symbol: Symbol, rangeCost: Int) {
abstract sealed case class Status(id: Int, symbol: Symbol, rangeCost: Int) {
val isMove: Boolean = (rangeCost > 0)
}

Expand Down Expand Up @@ -46,33 +46,43 @@ class Board(
defaultData.toArray
}

def pos(index: Int) = Position(index % width, index / width)(this)
def pos(x: Int, y: Int): Position = {
checkRectangle(x, y)
Position(x, y)
}
def pos(index: Int): Position = {
apply(index)
Position(index % width, index / width)
}
def index(pos: Position): Int = index(pos.x, pos.y)
def index(x: Int, y: Int): Int = x + y * width

def apply(pos: Position): Board.Status = apply(pos.x, pos.y)
def apply(x: Int, y: Int): Board.Status = {
def index(x: Int, y: Int): Int = {
checkRectangle(x, y)
apply(index(x, y))
}
x + y * width
}

def lastIndex = size - 1

def apply(pos: Position): Board.Status = apply(index(pos.x, pos.y))
def apply(x: Int, y: Int): Board.Status = apply(index(x, y))
def apply(index: Int): Board.Status = try {
data(index)
} catch {
case _: ArrayIndexOutOfBoundsException =>
throw new OutsideBoardException("index: " + index)
}

def update(pos: Position, status: Board.Status) { update(pos.x, pos.y, status) }
def update(pos: Position, status: Board.Status) {
update(index(pos.x, pos.y), status)
}
def update(x: Int, y: Int, status: Board.Status) {
checkRectangle(x, y)
update(index(x, y), status)
}
}
def update(index: Int, status: Board.Status): Unit = try {
data(index) = status
} catch {
case _: ArrayIndexOutOfBoundsException =>
throw new OutsideBoardException("index: " + index)
}
}

def checkWidth(x: Int) {
if (x < 0 || x >= width) throw new OutsideBoardException("x = " + x)
Expand Down
103 changes: 36 additions & 67 deletions models/src/main/scala/Character.scala
@@ -1,8 +1,6 @@
package com.github.alphaneet.suparobo

// TK: 一時的に適当に定義。あとで model.scala と混ぜる。
object CharacterProfile {

def loadProfiles(filename: String): List[CharacterProfile] =
loadProfiles(scala.xml.XML.loadFile(filename))

Expand All @@ -17,14 +15,12 @@ object CharacterProfile {
)
} toList
}

def empty() = CharacterProfile(0, "", 'None)
}

case class CharacterProfile(
id: Int,
name: String,
symbol: Symbol
id: Int = 0,
name: String = "",
symbol: Symbol = 'None
) extends NotNull

object CharacterParameter {
Expand All @@ -43,70 +39,43 @@ object CharacterParameter {
to int 'cost
)
} getOrElse {
this.empty()
CharacterParameter()
}
}

def empty() = CharacterParameter(
hitPoint = 0,
moveRangePoint = 0,
attackPoint = 0,
attackRangePoint = 0,
guardPoint = 0,
cost = 0
)
}

case class CharacterParameter(
var hitPoint: Int,
var moveRangePoint: Int,
var attackPoint: Int,
var attackRangePoint: Int,
var guardPoint: Int,
var cost: Int
) extends NotNull {

// TK: いらんかも?様子見
/*
def update(
hitPoint: Int,
moveRangePoint: Int,
attackPoint: Int,
attackRangePoint: Int,
guardPoint: Int,
cost: Int
): Unit = this update CharacterParameter(
hitPoint,
moveRangePoint,
attackPoint,
attackRangePoint,
guardPoint,
cost
)
def update(param: CharacterParameter) {
this.hitPoint = param.hitPoint
this.moveRangePoint = param.moveRangePoint
this.attackPoint = param.attackPoint
this.attackRangePoint = param.attackRangePoint
this.guardPoint = param.guardPoint
this.cost = param.cost
}
*/
}
var hitPoint: Int = 0,
var moveRangePoint: Int = 0,
var attackPoint: Int = 0,
var attackRangePoint: Int = 0,
var guardPoint: Int = 0,
var cost: Int = 0
) extends NotNull

object Character {
def empty(): Character = new Character {
val profile = CharacterProfile.empty()
val param = CharacterParameter.empty()
def apply() = new Character {
val profile = CharacterProfile()
val param = CharacterParameter()
}
}

abstract class Character extends NotNull {
@cloneable trait Character extends NotNull {
// TK: 重複がないかのチェック処理を入れるべきかも
// その時はChampion と Minion はID領域は別にするかも検証(多分 XML ファイル分かれてるので別にしたほうがいい
// その時はChampion と Minion はID領域は別にするかも検証
// 多分 XML ファイル分かれてるので別にしたほうがいい
val profile: CharacterProfile
val param: CharacterParameter

var pos = Position()

override def hashCode = profile.hashCode
override def equals(that: Any): Boolean = that match {
case x: Character => profile == x.profile
case _ => false
}
override def clone(): this.type = super.clone.asInstanceOf[this.type]
override def toString = "%s %s %s".format(profile, param, pos)
}

object Champion {
Expand All @@ -129,7 +98,7 @@ object Champion {
}
}

abstract class Champion extends Character
trait Champion extends Character

object Minion {
def loadMinions(
Expand All @@ -150,7 +119,8 @@ object Minion {
}
}
}
abstract class Minion extends Character

trait Minion extends Character

// 今回ではタイプによる特別処理はしないのでこれらは使わない。
// パラメーター調整でタイプを表現する。
Expand All @@ -160,11 +130,10 @@ trait Tank
trait Carry
trait Fighter

// ここらへんマクロ実装されたら回したい
abstract class TankChampion extends Character with Tank
abstract class CarryChampion extends Character with Carry
abstract class FighterChampion extends Character with Fighter
trait TankChampion extends Character with Tank
trait CarryChampion extends Character with Carry
trait FighterChampion extends Character with Fighter

abstract class TankMinion extends Minion with Tank
abstract class CarryMinion extends Minion with Carry
abstract class FighterMinion extends Minion with Fighter
trait TankMinion extends Minion with Tank
trait CarryMinion extends Minion with Carry
trait FighterMinion extends Minion with Fighter
16 changes: 3 additions & 13 deletions models/src/main/scala/Deck.scala
Expand Up @@ -4,23 +4,13 @@ class Deck(val maxCost: Int) extends NotNull {
var champion: Option[Champion] = None
val minions = scala.collection.mutable.LinkedHashSet[Minion]()

def foreach(f: Character => Unit) {
champion foreach { f(_) }
minions foreach { f(_) }
}
def characters: List[Character] =
champion.map(List(_)).getOrElse(Nil) ::: minions.toList

def clear() {
champion = None
minions.clear()
}

def existsChampion(other: Champion): Boolean = {
champion exists(_ == other)
}

def existsMinion(other: Minion): Boolean = {
minions exists(_ == other)
}
}

def entry(): this.type = {
if (champion.isEmpty) throw new NoSuchChampionException
Expand Down
54 changes: 42 additions & 12 deletions models/src/main/scala/Game.scala
Expand Up @@ -3,7 +3,7 @@ package com.github.alphaneet.suparobo
case class GameMaker(
inside: Option[Player] = None,
outside: Option[Player] = None,
board: Option[Board] = None
board: Option[Board] = None
) {
def createGame() = Game(
inside getOrElse (throw new NoSuchInsidePlayerException),
Expand All @@ -13,7 +13,7 @@ case class GameMaker(
}

object Game {
sealed case class Status(id: Int) extends NotNull
abstract sealed case class Status(id: Int) extends NotNull
object SETUP extends Status(1)
object PLAY extends Status(2)
object END extends Status(3)
Expand All @@ -25,29 +25,59 @@ case class Game(
board: Board
) extends NotNull {
import Game._

private var _status: Status = SETUP
private def status_=(status: Status) { _status = status }
def status = _status
def status = _status

def isSetup = status == SETUP
def isPlay = status == PLAY
def isEnd = status == END

def gotoSetup() {}
def gotoPlay() {
if (isComplateSetup) {
status = PLAY
} else {
throw new IllegalGotoGameStatusException(status + " -> " + PLAY)
val players = List(inside, outside)

def charactersSet: Set[Character] = {
(Set[Character]() /: players)(_ ++ _.deck.characters)
}

def setup() {
// TK: チェック入れなあかん。山(移動不可)だったらおけないとか
{
var i = board.lastIndex
inside.deck.characters.foreach {
c =>
c.pos = board.pos(i)
i -= 1
}
}

{
var i = 0
outside.deck.characters.foreach {
c =>
c.pos = board.pos(i)
i += i
}
}
}
def gotoEnd() {}


def isComplateSetup: Boolean = {
if(!isSetup) return false


true
}

def gotoSetup() {
}

def gotoPlay() {
if (isComplateSetup) {
status = PLAY
} else {
throw new IllegalGameStatusException(status + " -> " + PLAY)
}
}

def gotoEnd() {}
}

21 changes: 3 additions & 18 deletions models/src/main/scala/Position.scala
@@ -1,21 +1,6 @@
package com.github.alphaneet.suparobo

case class Position (
private var _x: Int,
private var _y: Int
)(implicit
board: Board
) extends NotNull {
board.checkRectangle(_x, _y)

def x = _x
def y = _y

def x_=(x: Int) { board.checkWidth(x); _x = x }
def y_=(y: Int) { board.checkHeight(y); _y = y }

def +=(pos: Position) { x += pos.x; y += pos.y }
def -=(pos: Position) { x -= pos.x; y -= pos.y }

def index = x + y * board.width
case class Position(var x: Int = 0, var y: Int = 0) extends NotNull {
def +=(pos: Position) { x += pos.x; y += pos.y }
def -=(pos: Position) { x -= pos.x; y -= pos.y }
}
4 changes: 2 additions & 2 deletions models/src/main/scala/exceptions.scala
Expand Up @@ -29,5 +29,5 @@ class NoSuchOutsidePlayerException(msg: String = "") extends Exception(msg)
// ステージが選択されていない場合
class NoSuchBoardException(msg: String = "") extends Exception(msg)

//
class IllegalGotoGameStatusException(msg: String = "") extends Exception(msg)
// そのステータスは現状許可されてない場合
class IllegalGameStatusException(msg: String = "") extends Exception(msg)

0 comments on commit 57531d8

Please sign in to comment.