added logic for dice; modified layout to add more dice

This commit is contained in:
Wyatt J. Miller 2020-09-24 16:17:40 -04:00
parent 5ecf349620
commit efc650d86c
3 changed files with 95 additions and 39 deletions

View File

@ -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> = 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
}

View File

@ -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> = 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> = 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> = 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
}

View File

@ -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" />
<Button
android:id="@+id/rollTenButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="onClickDieTenRoll"
android:text="Roll D10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rollButton" />
<Button
android:id="@+id/rollTwentyButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="onClickDieTwentyRoll"
android:text="Roll D20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rollTenButton" />
<TextView
android:id="@+id/diceTextView"
android:layout_width="157dp"
android:layout_height="76dp"
android:layout_marginBottom="256dp"
android:layout_marginTop="144dp"
android:gravity="center"
android:text="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />