diff --git a/app/src/main/java/com/wyattjmiller/dicerollerapp/CoinActivity.kt b/app/src/main/java/com/wyattjmiller/dicerollerapp/CoinActivity.kt index bb651b3..dc30cfa 100644 --- a/app/src/main/java/com/wyattjmiller/dicerollerapp/CoinActivity.kt +++ b/app/src/main/java/com/wyattjmiller/dicerollerapp/CoinActivity.kt @@ -54,17 +54,14 @@ class CoinActivity : AppCompatActivity() { // code behind for the 'flip' button fun onClickCoinFlip(view: View?) { - when (Randomizer().randomCoinFlip()) { - 0 -> { - mCoinStatus = Coin.Heads - mCoinTextView.text = mCoinStatus.toString() - } - 1 -> { - mCoinStatus = Coin.Tails - mCoinTextView.text = mCoinStatus.toString() - } + val item: Array = Coin.values() + when (Randomizer().randomCoinFlip(item)) { + 0 -> mCoinStatus = Coin.Heads + 1 -> mCoinStatus = Coin.Tails } + mCoinTextView.text = mCoinStatus.toString() + if (mCoinTextView.visibility == View.INVISIBLE) { mCoinTextView.visibility = View.VISIBLE } diff --git a/app/src/main/java/com/wyattjmiller/dicerollerapp/DiceActivity.kt b/app/src/main/java/com/wyattjmiller/dicerollerapp/DiceActivity.kt index bfaaa7d..aec6bdb 100644 --- a/app/src/main/java/com/wyattjmiller/dicerollerapp/DiceActivity.kt +++ b/app/src/main/java/com/wyattjmiller/dicerollerapp/DiceActivity.kt @@ -55,33 +55,72 @@ class DiceActivity : AppCompatActivity() { // code behind for the 'roll' button fun onClickDieRoll(view: View?) { - when (Randomizer().randomDieRoll()) { - 0 -> { - mDieStatus = Die.One - mDiceTextView.text = mDieStatus.toString() - } - 1 -> { - mDieStatus = Die.Two - mDiceTextView.text = mDieStatus.toString() - } - 2 -> { - mDieStatus = Die.Three - mDiceTextView.text = mDieStatus.toString() - } - 3 -> { - mDieStatus = Die.Four - mDiceTextView.text = mDieStatus.toString() - } - 4 -> { - mDieStatus = Die.Five - mDiceTextView.text = mDieStatus.toString() - } - 5 -> { - mDieStatus = Die.Six - mDiceTextView.text = mDieStatus.toString() - } + val item: Array = SixDie.values() + when (Randomizer().randomDieRoll(item)) { + 0 -> mDieStatus = SixDie.One + 1 -> mDieStatus = SixDie.Two + 2 -> mDieStatus = SixDie.Three + 3 -> mDieStatus = SixDie.Four + 4 -> mDieStatus = SixDie.Five + 5 -> mDieStatus = SixDie.Six } + mDiceTextView.text = mDieStatus.toString() + + if (mDiceTextView.visibility == View.INVISIBLE) { + mDiceTextView.visibility = View.VISIBLE + } + } + + fun onClickDieTenRoll(view: View?) { + val item: Array = TenDie.values() + when (Randomizer().randomDieRoll(item)) { + 0 -> mDieStatus = TenDie.One + 1 -> mDieStatus = TenDie.Two + 2 -> mDieStatus = TenDie.Three + 3 -> mDieStatus = TenDie.Four + 4 -> mDieStatus = TenDie.Five + 5 -> mDieStatus = TenDie.Six + 6 -> mDieStatus = TenDie.Seven + 7 -> mDieStatus = TenDie.Eight + 8 -> mDieStatus = TenDie.Nine + 9 -> mDieStatus = TenDie.Ten + } + + mDiceTextView.text = mDieStatus.toString() + + if (mDiceTextView.visibility == View.INVISIBLE) { + mDiceTextView.visibility = View.VISIBLE + } + } + + fun onClickDieTwentyRoll(view: View?) { + val item: Array = TwentyDie.values() + when (Randomizer().randomDieRoll(item)) { + 0 -> mDieStatus = TwentyDie.One + 1 -> mDieStatus = TwentyDie.Two + 2 -> mDieStatus = TwentyDie.Three + 3 -> mDieStatus = TwentyDie.Four + 4 -> mDieStatus = TwentyDie.Five + 5 -> mDieStatus = TwentyDie.Six + 6 -> mDieStatus = TwentyDie.Seven + 7 -> mDieStatus = TwentyDie.Eight + 8 -> mDieStatus = TwentyDie.Nine + 9 -> mDieStatus = TwentyDie.Ten + 10 -> mDieStatus = TwentyDie.Eleven + 11 -> mDieStatus = TwentyDie.Twelve + 12 -> mDieStatus = TwentyDie.Thirteen + 13 -> mDieStatus = TwentyDie.Fourteen + 14 -> mDieStatus = TwentyDie.Fifteen + 15 -> mDieStatus = TwentyDie.Sixteen + 16 -> mDieStatus = TwentyDie.Seventeen + 17 -> mDieStatus = TwentyDie.Eighteen + 18 -> mDieStatus = TwentyDie.Nineteen + 19 -> mDieStatus = TwentyDie.Twenty + } + + mDiceTextView.text = mDieStatus.toString() + if (mDiceTextView.visibility == View.INVISIBLE) { mDiceTextView.visibility = View.VISIBLE } diff --git a/app/src/main/res/layout/activity_dice.xml b/app/src/main/res/layout/activity_dice.xml index 03a6492..dae0ca1 100644 --- a/app/src/main/res/layout/activity_dice.xml +++ b/app/src/main/res/layout/activity_dice.xml @@ -11,23 +11,43 @@ android:id="@+id/rollButton" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="32dp" android:onClick="onClickDieRoll" android:text="@string/btn_roll" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.498" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/diceTextView" - app:layout_constraintVertical_bias="0.159" /> + app:layout_constraintTop_toBottomOf="@+id/diceTextView" /> + +