dice roller
Wed Nov 20 2024 19:18:32 GMT+0000 (Coordinated Universal Time)
Saved by @wtlab
package com.example.dicerollerapp
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.Button
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.dicerollerapp.ui.theme.DiceRollerAppTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
diceRollerApp()
}
}
@Composable
fun diceRollerApp(){
diceWithImageBtn(Modifier.fillMaxSize().wrapContentSize(Alignment.Center))
}
@Composable
fun diceWithImageBtn(modifier:Modifier){
var res by remember { mutableStateOf(1) }
var z= when(res){
3->R.drawable.three
4->R.drawable.fourr
else->R.drawable.five
}
Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center){
Image(painterResource(z),contentDescription = null)
Spacer(Modifier.padding(16.dp))
Button(onClick = {res=(1..6).random()}) {
Text(text = "roll", fontSize = 24.sp)
}
}
}
}



Comments