|
|
@ -7,8 +7,11 @@ import data.GameFrame |
|
|
|
import kotlinx.browser.document |
|
|
|
import kotlinx.browser.document |
|
|
|
import kotlinx.browser.window |
|
|
|
import kotlinx.browser.window |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import kotlinx.coroutines.delay |
|
|
|
import org.jetbrains.compose.web.attributes.* |
|
|
|
import org.jetbrains.compose.web.attributes.InputType |
|
|
|
import org.jetbrains.compose.web.css.* |
|
|
|
import org.jetbrains.compose.web.attributes.checked |
|
|
|
|
|
|
|
import org.jetbrains.compose.web.attributes.disabled |
|
|
|
|
|
|
|
import org.jetbrains.compose.web.css.marginTop |
|
|
|
|
|
|
|
import org.jetbrains.compose.web.css.px |
|
|
|
import org.jetbrains.compose.web.dom.* |
|
|
|
import org.jetbrains.compose.web.dom.* |
|
|
|
import org.jetbrains.compose.web.renderComposable |
|
|
|
import org.jetbrains.compose.web.renderComposable |
|
|
|
import org.w3c.dom.HTMLElement |
|
|
|
import org.w3c.dom.HTMLElement |
|
|
@ -31,20 +34,12 @@ fun main() { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
body.onclick = { |
|
|
|
|
|
|
|
game.moveBirdUp() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderComposable(rootElementId = "root") { |
|
|
|
renderComposable(rootElementId = "root") { |
|
|
|
|
|
|
|
|
|
|
|
Div( |
|
|
|
Div( |
|
|
|
attrs = { |
|
|
|
attrs = { |
|
|
|
style { |
|
|
|
style { |
|
|
|
display(DisplayStyle.Flex) |
|
|
|
property("text-align", "center") |
|
|
|
justifyContent(JustifyContent.Center) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
onClick { |
|
|
|
|
|
|
|
game.moveBirdUp() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) { |
|
|
|
) { |
|
|
@ -60,29 +55,19 @@ fun main() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Div { |
|
|
|
Header(gameFrame) |
|
|
|
|
|
|
|
|
|
|
|
// Title |
|
|
|
Div( |
|
|
|
GameTitle() |
|
|
|
attrs = { |
|
|
|
Score(gameFrame) |
|
|
|
style { |
|
|
|
Br() |
|
|
|
marginTop(30.px) |
|
|
|
|
|
|
|
|
|
|
|
if (gameFrame.isGameOver || gameFrame.isGameWon) { |
|
|
|
|
|
|
|
Div( |
|
|
|
|
|
|
|
attrs = { |
|
|
|
|
|
|
|
style { |
|
|
|
|
|
|
|
display(DisplayStyle.Flex) |
|
|
|
|
|
|
|
flexDirection(FlexDirection.Column) |
|
|
|
|
|
|
|
justifyContent(JustifyContent.Center) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
GameStatus(gameFrame) |
|
|
|
|
|
|
|
TryAgain() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if (gameFrame.isGameOver || gameFrame.isGameWon) { |
|
|
|
|
|
|
|
GameResult(gameFrame) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
// Play area |
|
|
|
repeat(ComposeBirdGame.ROWS) { rowIndex -> |
|
|
|
repeat(ComposeBirdGame.ROWS) { rowIndex -> |
|
|
|
Div { |
|
|
|
Div { |
|
|
|
repeat(ComposeBirdGame.COLUMNS) { columnIndex -> |
|
|
|
repeat(ComposeBirdGame.COLUMNS) { columnIndex -> |
|
|
@ -90,12 +75,6 @@ fun main() { |
|
|
|
InputType.Radio, |
|
|
|
InputType.Radio, |
|
|
|
|
|
|
|
|
|
|
|
attrs = { |
|
|
|
attrs = { |
|
|
|
|
|
|
|
|
|
|
|
style { |
|
|
|
|
|
|
|
width(25.px) |
|
|
|
|
|
|
|
height(25.px) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val tube = gameFrame.tubes.find { it.position == columnIndex } |
|
|
|
val tube = gameFrame.tubes.find { it.position == columnIndex } |
|
|
|
val isTube = tube?.coordinates?.get(rowIndex) ?: false |
|
|
|
val isTube = tube?.coordinates?.get(rowIndex) ?: false |
|
|
|
val isBird = |
|
|
|
val isBird = |
|
|
@ -126,27 +105,20 @@ fun main() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
private fun TryAgain() { |
|
|
|
private fun Header(gameFrame: GameFrame) { |
|
|
|
Button( |
|
|
|
// Game title |
|
|
|
attrs = { |
|
|
|
H1 { |
|
|
|
onClick { |
|
|
|
Text(value = "🐦 Compose Bird!") |
|
|
|
window.location.reload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Text("Try Again!") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Game score |
|
|
|
|
|
|
|
Text(value = "Your Score: ${gameFrame.score} || Top Score: ${ComposeBirdGame.TOTAL_TUBES}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
private fun GameStatus(gameFrame: GameFrame) { |
|
|
|
private fun GameResult(gameFrame: GameFrame) { |
|
|
|
H2( |
|
|
|
// Game Status |
|
|
|
attrs = { |
|
|
|
H2 { |
|
|
|
style { |
|
|
|
|
|
|
|
alignSelf(AlignSelf.Center) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if (gameFrame.isGameWon) { |
|
|
|
if (gameFrame.isGameWon) { |
|
|
|
Text("🚀 Won the game! 🚀") |
|
|
|
Text("🚀 Won the game! 🚀") |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -154,32 +126,15 @@ private fun GameStatus(gameFrame: GameFrame) { |
|
|
|
Text("💀 Game Over 💀") |
|
|
|
Text("💀 Game Over 💀") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
|
|
|
|
private fun Score(gameFrame: GameFrame) { |
|
|
|
|
|
|
|
Div( |
|
|
|
|
|
|
|
attrs = { |
|
|
|
|
|
|
|
style { |
|
|
|
|
|
|
|
display(DisplayStyle.Flex) |
|
|
|
|
|
|
|
justifyContent(JustifyContent.Center) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
Text("Your Score: ${gameFrame.score} || Top Score: ${ComposeBirdGame.TOTAL_TUBES}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
// Try Again |
|
|
|
private fun GameTitle() { |
|
|
|
Button( |
|
|
|
H1( |
|
|
|
|
|
|
|
attrs = { |
|
|
|
attrs = { |
|
|
|
style { |
|
|
|
onClick { |
|
|
|
display(DisplayStyle.Flex) |
|
|
|
window.location.reload() |
|
|
|
justifyContent(JustifyContent.Center) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) { |
|
|
|
) { |
|
|
|
Text("🐦 Compose Bird!") |
|
|
|
Text("Try Again!") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |