Add some self code

This commit is contained in:
Simon Rieger 2023-08-23 10:22:13 +02:00
parent c20faa0995
commit 08ee5d1b58
3 changed files with 69 additions and 21 deletions

View file

@ -1,3 +1,3 @@
TEAM_ID= TEAM_ID=X3U84U8A6F
BUNDLE_ID=com.myapplication.MyApplication BUNDLE_ID=com.myapplication.MyApplication
APP_NAME=My application APP_NAME=My application

View file

@ -1,38 +1,85 @@
import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column 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.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.Button
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import org.jetbrains.compose.resources.ExperimentalResourceApi import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.painterResource
@OptIn(ExperimentalResourceApi::class)
@Composable @Composable
fun App() { fun App() {
MaterialTheme { MaterialTheme {
var greetingText by remember { mutableStateOf("Hello, World!") } val runGame = remember { mutableStateOf(false) }
var showImage by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { if (!runGame.value) {
Button(onClick = { Column {
greetingText = "Hello, ${getPlatformName()}" Spacer(modifier = Modifier.size(50.dp))
showImage = !showImage Row(
}) { verticalAlignment = Alignment.CenterVertically,
Text(greetingText) horizontalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxWidth()
) {
Button(onClick = { runGame.value = true }) {
Text(text = "Start Game")
}
}
} }
AnimatedVisibility(showImage) { } else {
Image(
painterResource("compose-multiplatform.xml"), val fieldPos = remember { mutableStateListOf<Field>() }
null 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")
}
}
} }
} }
} }

View file

@ -0,0 +1 @@
data class Field(var isBuild: Boolean = false, var text: String = "x")