Skip to content

Commit

Permalink
class implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cerver1 committed Oct 8, 2024
1 parent fa3a35a commit 6c39db2
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 12 deletions.
7 changes: 7 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/org/stsd/uno/Answer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.stsd.uno

data class Answer(
val id: String,
val value: String,
val points: Int
)
111 changes: 99 additions & 12 deletions composeApp/src/wasmJsMain/kotlin/org/stsd/uno/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,119 @@ package org.stsd.uno

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.painterResource

import uno.composeapp.generated.resources.Res
import uno.composeapp.generated.resources.compose_multiplatform

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun App() {
MaterialTheme {
var showContent by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { showContent = !showContent }) {
Text("Click me!")
}
AnimatedVisibility(showContent) {
val greeting = remember { Greeting().greet() }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Image(painterResource(Res.drawable.compose_multiplatform), null)
Text("Compose: $greeting")
val teams = List(2) { Team("Team $it", "${13 * it}")}
val gameState = GameState(
teams = teams,
selectedTeam = teams[1],
points = 100,
strikes = 2
)

Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(64.dp)
) {

Card(
modifier = Modifier.size(200.dp)
) {
Text(
modifier = Modifier.wrapContentSize(),
text = gameState.points.toString(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.h2
)
}

Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(64.dp)
) {
Card(
modifier = Modifier.size(150.dp)
) {
Text(
modifier = Modifier.wrapContentSize(),
text = teams[0].points,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.h3
)
}
FlowColumn(
maxItemsInEachColumn = 4,
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
val answers = List(6) { Answer(it.toString(), "Test", it * 2) }

answers.forEach { answer ->
Card {
Row(
modifier = Modifier
.padding(15.dp)
.fillMaxWidth(0.3f)
) {
Text(
modifier = Modifier.weight(1f),
text = answer.value
)
Text(answer.points.toString())
}
}
}
}
Card(
modifier = Modifier.size(150.dp)
) {
Text(
modifier = Modifier.wrapContentSize(),
text = teams[1].points,
textAlign = TextAlign.Center,
style = MaterialTheme.typography.h3
)
}
}

Row(
horizontalArrangement = Arrangement.spacedBy(64.dp)
) {
repeat(gameState.strikes) {
Card(
modifier = Modifier.size(200.dp)
) {
Text(
modifier = Modifier
.wrapContentSize()
.padding(20.dp),
text = "X",
textAlign = TextAlign.Center,
style = MaterialTheme.typography.h3
)
}
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/org/stsd/uno/GameState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.stsd.uno

data class GameState(
val teams: List<Team>,
val selectedTeam: Team,
val strikes: Int,
val points: Int
)
6 changes: 6 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/org/stsd/uno/Question.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.stsd.uno

data class Question(
val value: String,
val id: String
)
6 changes: 6 additions & 0 deletions composeApp/src/wasmJsMain/kotlin/org/stsd/uno/Team.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.stsd.uno

data class Team(
val name: String,
val points: String
)

0 comments on commit 6c39db2

Please sign in to comment.