Add some self code
This commit is contained in:
parent
c20faa0995
commit
08ee5d1b58
3 changed files with 69 additions and 21 deletions
|
@ -1,3 +1,3 @@
|
|||
TEAM_ID=
|
||||
TEAM_ID=X3U84U8A6F
|
||||
BUNDLE_ID=com.myapplication.MyApplication
|
||||
APP_NAME=My application
|
||||
|
|
|
@ -1,39 +1,86 @@
|
|||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.itemsIndexed
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalResourceApi::class)
|
||||
@Composable
|
||||
fun App() {
|
||||
MaterialTheme {
|
||||
var greetingText by remember { mutableStateOf("Hello, World!") }
|
||||
var showImage by remember { mutableStateOf(false) }
|
||||
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Button(onClick = {
|
||||
greetingText = "Hello, ${getPlatformName()}"
|
||||
showImage = !showImage
|
||||
}) {
|
||||
Text(greetingText)
|
||||
val runGame = remember { mutableStateOf(false) }
|
||||
|
||||
if (!runGame.value) {
|
||||
Column {
|
||||
Spacer(modifier = Modifier.size(50.dp))
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Button(onClick = { runGame.value = true }) {
|
||||
Text(text = "Start Game")
|
||||
}
|
||||
AnimatedVisibility(showImage) {
|
||||
Image(
|
||||
painterResource("compose-multiplatform.xml"),
|
||||
null
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
val fieldPos = remember { mutableStateListOf<Field>() }
|
||||
val selectedPos = remember { mutableStateOf(0) }
|
||||
val houses = remember { mutableStateOf(0) }
|
||||
val population = remember { mutableStateOf(0) }
|
||||
val maxPopulation = remember { mutableStateOf(0) }
|
||||
|
||||
if (fieldPos.size != 100) {
|
||||
for (i in 0..99) {
|
||||
fieldPos.add(i, Field(text = "x"))
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
Row {
|
||||
Text(
|
||||
text = "Einwohneranzahl ${population.value} / ${maxPopulation.value}"
|
||||
)
|
||||
}
|
||||
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(10)
|
||||
) {
|
||||
itemsIndexed(fieldPos) { field, item: Field ->
|
||||
TextButton(onClick = {
|
||||
fieldPos[field] = fieldPos[field].copy(text = "o")
|
||||
selectedPos.value = field
|
||||
}) {
|
||||
Text(text = item.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
Button(onClick = {
|
||||
fieldPos[selectedPos.value] = fieldPos[selectedPos.value].copy(text = "H", isBuild = true)
|
||||
houses.value++
|
||||
maxPopulation.value = houses.value * 5
|
||||
}) {
|
||||
Text("Haus")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1
shared/src/commonMain/kotlin/Field.kt
Normal file
1
shared/src/commonMain/kotlin/Field.kt
Normal file
|
@ -0,0 +1 @@
|
|||
data class Field(var isBuild: Boolean = false, var text: String = "x")
|
Loading…
Reference in a new issue