jeudi 10 juin 2021

want to add a second dice and get random result diffrent than the first

Hi everybody im trying to practice a little bit further than what i ve been asking to do.

Good ol dice roller one activity android app.

i successfully added another imageView but when rolling i d like to show different result.

whats the best practice ?

heres my code

private fun rollDice() {
    val dice = Dice(6)
    val diceRoll = dice.roll()
    //val resultTextView: TextView = findViewById(R.id.textView)
    //resultTextView.text = diceRoll.toString()
    val diceImage: ImageView = findViewById(R.id.imageView)
    val diceImage2: ImageView = findViewById(R.id.imageView2)
    //diceImage.setImageResource(R.drawable.dice_2)
    val drawableResource = when (diceRoll) {
        1 -> R.drawable.dice_1
        2 -> R.drawable.dice_2
        3 -> R.drawable.dice_3
        4 -> R.drawable.dice_4
        else -> R.drawable.dice_5

    }
    // set up dice image accordingly
    diceImage.setImageResource(drawableResource)
    diceImage2.setImageResource(drawableResource)

    //mets a jour la description du contenu affiché
    diceImage.contentDescription = diceRoll.toString()
}

}




Aucun commentaire:

Enregistrer un commentaire