Skip to content

Commit

Permalink
refs #35 2012/02/04 nightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
alphaneet committed Feb 4, 2012
1 parent dcd1e1f commit 6ad1be6
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 67 deletions.
2 changes: 1 addition & 1 deletion models/src/main/scala/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Board {
}
}

case class Board(
class Board(
val width: Int,
val height: Int,
val name: String = "",
Expand Down
23 changes: 20 additions & 3 deletions models/src/main/scala/Deck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Deck(val maxCost: Int) extends NotNull {

def foreach(f: Character => Unit) {
champion foreach { f(_) }
minions foreach { f(_) }
minions foreach { f(_) }
}

def clear() {
Expand Down Expand Up @@ -35,8 +35,9 @@ class Deck(val maxCost: Int) extends NotNull {
} catch {
case _ => false
}

def isCostOver: Boolean = nowCost > maxCost

def isMaxCost: Boolean = nowCost == maxCost
def isCostOver: Boolean = nowCost > maxCost

def nowCost: Int =
champion.map(_.param.cost).getOrElse(0) + minions.foldLeft(0)(_ + _.param.cost)
Expand Down Expand Up @@ -92,4 +93,20 @@ class Deck(val maxCost: Int) extends NotNull {

this
}

def random(champions: List[Champion], minions: List[Minion]): this.type = {
import scala.util.Random.{nextInt, shuffle}

this.clear()
this.champion = Option(champions(nextInt(champions.size)))

shuffle(minions) foreach {
minion =>
this.minions += minion
if (this.isCostOver) this.minions -= minion
if (this.isMaxCost) return this
}

this
}
}
3 changes: 3 additions & 0 deletions models/src/main/scala/Game.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.github.alphaneet.suparobo


// TK: GameReady とかの Option 用のクラスを用意すべきかも
// GameDeliver という名前を思いついた
case class Game(
self: Option[Player] = None,
other: Option[Player] = None,
Expand Down
4 changes: 3 additions & 1 deletion models/src/main/scala/Player.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.github.alphaneet.suparobo

class Player
case class Player(deck: Deck) extends NotNull {

}
10 changes: 9 additions & 1 deletion processing2D/BoardSelectScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ case class BoardSelectScene(
filename =>

val board = Board.loadXML(BOARDS_PATH + filename)
val sprite = createBoardSprite(board, viewerRect)
val sprite = createBoardSprite(
board,
viewerRect,
(g, rect) => {
g.stroke(C5R, C5G, C5B)
g.noFill()
g.rect(0, 0, rect.width - 1, rect.height - 1)
}
)
val buttonImages = List(
(C2, C5),
(C1, C4),
Expand Down
12 changes: 10 additions & 2 deletions processing2D/DeckMakeScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ case class DeckMakeScene(implicit applet: SPApplet, i18n: I18N)
registerButtons(
menuBtnMgr,
List(
('save, t("save"), save _),
('save, t("save"), confirmAndSave _),
('clear, t("clear"), clear _),
('back, t("back"), back _)
)
)


def confirmAndSave() {
dialog.confirm(nowDeckName + " " + t("confirm.save")) {
save {
dialog.message(t("execute.save"))
}
}
}

def back() {
dialog.confirm(t("TitleScene.back")) {
TitleScene()
Expand Down
45 changes: 17 additions & 28 deletions processing2D/DeckScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ abstract class DeckScene(

val dialog = new MyDialog

val champions: List[Champion] = Champion.loadChampions(
CHARACTERS_PATH + "championProfiles.xml",
CHARACTERS_PATH + "championParameters.xml"
)

val minions: List[Minion] = Minion.loadMinions(
CHARACTERS_PATH + "minionProfiles.xml",
CHARACTERS_PATH + "minionParameters.xml"
)

val decks: List[Deck] = List.range(0, MAX_DECK) map { i => createDeck() }
var nowDeck = decks(0)

Expand Down Expand Up @@ -203,25 +193,24 @@ abstract class DeckScene(
}

def nowDeckName: String = t("deck") + (decks.indexOf(nowDeck) + 1)

def save() {
dialog.confirm(nowDeckName + " " + t("confirm.save")) {
try {
val filename = DECKS_PATH + "deck" + decks.indexOf(nowDeck) + ".xml"
nowDeck.entry().saveXML(filename)
dialog.message(t("execute.save"))
} catch {
case _: NoSuchChampionException =>
dialog.message(t("NoSuchChampionException"))
case _: OverCostException =>
dialog.message(t("OverCostException"))
case ex =>
ex.printStackTrace(Console.err)
dialog.message(ex.getClass.getSimpleName)
}
}

def save(success: => Unit = {}) {
try {
val filename = DECKS_PATH + "deck" + decks.indexOf(nowDeck) + ".xml"
nowDeck.entry().saveXML(filename)
success
} catch {
case _: NoSuchChampionException =>
println(nowDeck)
dialog.message(t("NoSuchChampionException"))
case _: OverCostException =>
dialog.message(t("OverCostException"))
case ex =>
ex.printStackTrace(Console.err)
dialog.message(ex.getClass.getSimpleName)
}
}

def clear() {
dialog.confirm(nowDeckName + " " + t("confirm.clear")) {
nowDeck.clear()
Expand Down
21 changes: 16 additions & 5 deletions processing2D/DeckSelectScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ case class DeckSelectScene(
menuBtnMgr,
List(
('entry, t("entry"), entry _),
('save, t("save"), save _),
('save, t("clear"), clear _),
('back, t("back"), back _)
)
)
Expand All @@ -24,7 +24,15 @@ case class DeckSelectScene(
)

val boardViewer: Option[Sprite] = game.board.map {
createBoardSprite(_, layout.rect('viewer))
createBoardSprite(
_,
layout.rect('viewer),
(g, rect) => {
g.stroke(C5R, C5G, C5B)
g.noFill()
g.rect(0, 0, rect.width - 1, rect.height - 1)
}
)
}

def back() {
Expand All @@ -35,14 +43,17 @@ case class DeckSelectScene(

def entry() {
dialog.confirm(nowDeckName + " " + t("DeckSelectScene.entryMessage")) {
save {
val self = Option(Player(nowDeck))
GameScene(game.copy(self = self))
}
}
}

override def draw() {
applet.background(C2)

applet.background(C2)
title.draw()
boardNameLabel.draw()
boardNameLabel.draw()
boardViewer foreach { _.draw() }
super.draw()
}
Expand Down
85 changes: 85 additions & 0 deletions processing2D/GameScene.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.github.alphaneet.suparobo

case class GameScene(
game: Game
)(implicit
applet: SPApplet,
i18n: I18N
) extends Scene(applet) with MyUtil {
// implicit val layout = new LayoutXML(LAYOUTS_PATH + "BoardSelectScene.xml")
implicit val gg = new GraphicsGenerator(applet)

val board = game.board.get // TK: ちょい適当 @ で直す
object boardViewer {
val width = applet.width
val height = width * (board.height / board.width)

private var _scale = 1.0f
def scale = _scale
def scale_=(scale: Float) {
_scale = rangeOfNumber(scale, 0.375f, 1.0f)
val halfW = width >> 1
val prevH = sprite.height

sprite.width = (width * _scale).toInt
sprite.height = (height * _scale).toInt

sprite.x = (halfW - _scale * halfW).toInt
y += (prevH - sprite.height) / 2
}

def y = sprite.y
def y_=(y: Int) {
sprite.y = rangeOfNumber(y, -sprite.height + applet.height, 0)
}

val sprite: Sprite = createBoardSprite(board, new Rectangle(0, 0, width, height))

def draw() {
sprite.draw()

applet.stroke(C5R, C5G, C5B)
applet.noFill()

val w = sprite.width.toFloat / board.width
val h = sprite.height.toFloat / board.height
val (sx, ex) = (sprite.x, sprite.x + sprite.width)
val (sy, ey) = (sprite.y, sprite.y + sprite.height)
(0 to board.width) foreach {
i =>
val x = sx + w * i
applet.line(x, sy, x, ey)
}
(0 to board.height) foreach {
i =>
val y = sy + h * i
applet.line(sx, y, ex, y)
}
}
}

var action: Action = readyAction

trait Action extends NotNull {
action = this
def draw(): Unit
}

def readyAction = new Action {
def draw() {
}
}

override def draw() {
applet.background(C2)
boardViewer.draw()
}

override def mouseWheelMoved() {
boardViewer.scale += applet.mouseWheelRotation.toFloat / 100
}

override def mouseDragged() {
boardViewer.y += (applet.mouseY - applet.pmouseY)
}
}
6 changes: 5 additions & 1 deletion processing2D/TitleScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ case class TitleScene(implicit applet: SPApplet, i18n: I18N) extends Scene(apple
size = 12
)

def start() { BoardSelectScene() }
def start() {
val other = Option(Player(createDeck.random(champions, minions)))
BoardSelectScene(Game(other = other))
}

def network() { println("未実装") }
def deck() { DeckMakeScene() }
def replay() { println("未実装") }
Expand Down
13 changes: 12 additions & 1 deletion processing2D/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ object Main extends SPApplet {
frameRate(24)
val i18n = createI18N("ja")
title = i18n.t("title")
TitleScene()(this, i18n)
// TitleScene()(this, i18n)

// TK: test
def create = Option(new Player(createDeck.random(champions, minions)))
GameScene(
Game(
self = create,
other = create,
// board = Option(new Board(10, 20))
board = Option(Board.loadXML(BOARDS_PATH + "stage3.xml"))
)
)(this, i18n)
}
}

Expand Down
Loading

0 comments on commit 6ad1be6

Please sign in to comment.