diff --git a/korge-tic-tac-toe/resources/main.fla b/korge-tic-tac-toe/resources/main.fla index 350cd82..d89ac50 100644 Binary files a/korge-tic-tac-toe/resources/main.fla and b/korge-tic-tac-toe/resources/main.fla differ diff --git a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/Board.kt b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/Board.kt index 3cfb1d7..e163f3e 100644 --- a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/Board.kt +++ b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/Board.kt @@ -49,8 +49,9 @@ class Board(val width: Int = 3, val height: Int = width, val lineSize: Int = wid val moreMovements: Boolean get() = cells.any { it.value == Chip.EMPTY } val winnerLine: List? get() { - for (line in lines) if (line.chipLine != null) return line - return null + val out = arrayListOf() + for (line in lines) if (line.chipLine != null) out += line + return if (out.isEmpty()) null else out.toSet().toList() } val winner: Chip? get() { diff --git a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/BoardMediator.kt b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/BoardMediator.kt index d612a93..c24b1e8 100644 --- a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/BoardMediator.kt +++ b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/BoardMediator.kt @@ -2,9 +2,14 @@ package com.soywiz.korge.tictactoe import com.soywiz.korge.animate.play import com.soywiz.korge.input.onClick +import com.soywiz.korge.tween.Easings +import com.soywiz.korge.tween.rangeTo +import com.soywiz.korge.tween.tween +import com.soywiz.korge.tween.withEasing import com.soywiz.korge.view.View import com.soywiz.korge.view.get import com.soywiz.korio.async.Signal +import com.soywiz.korio.async.async import com.soywiz.korio.util.Extra var Board.Cell.view by Extra.Property { null } @@ -19,8 +24,36 @@ fun Board.Cell.set(type: Chip) { }) } +fun Board.Cell.setAnimate(type: Chip) { + set(type) + async { + view?.tween( + (View::alpha..0.7..1.0).withEasing(Easings.LINEAR), + (View::scale..0.8..1.0).withEasing(Easings.EASE_OUT_ELASTIC), + time = 300 + ) + } +} + fun Board.Cell.highlight(highlight: Boolean) { view["highlight"].play(if (highlight) "highlight" else "none") + async { + view?.tween( + View::scale..0.1..1.2, + View::rotationDegrees..360.0, + time = 600, easing = Easings.EASE_OUT_ELASTIC + ) + } +} + +fun Board.Cell.lowlight(lowlight: Boolean) { + async { + view?.tween( + View::scale..0.8, + View::alpha..0.5, + time = 300, easing = Easings.EASE_OUT_QUAD + ) + } } fun Board.reset() { diff --git a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/TicTacToe.kt b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/TicTacToe.kt index 2a07185..712ad38 100644 --- a/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/TicTacToe.kt +++ b/korge-tic-tac-toe/src/com.soywiz.korge.tictactoe/TicTacToe.kt @@ -57,9 +57,8 @@ class TicTacToeMainScene( is Game.Result.DRAW -> results["result"].setText("DRAW") is Game.Result.WIN -> { results["result"].setText("WIN") - for (cell in result.cells) { - cell.highlight(true) - } + for (cell in result.cells) cell.highlight(true) + for (cell in game.board.cells.toList() - result.cells) cell.lowlight(true) } } sceneView += results @@ -91,7 +90,7 @@ class Game(val board: Board, val players: List) { val pos = currentPlayer.move() println(pos) if (board.cells[pos].value == Chip.EMPTY) { - board.cells[pos].set(currentPlayer.chip) + board.cells[pos].setAnimate(currentPlayer.chip) break } }