added logic for dice; modified layout to add more dice
This commit is contained in:
parent
5ecf349620
commit
efc650d86c
@ -54,17 +54,14 @@ class CoinActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// code behind for the 'flip' button
|
// code behind for the 'flip' button
|
||||||
fun onClickCoinFlip(view: View?) {
|
fun onClickCoinFlip(view: View?) {
|
||||||
when (Randomizer().randomCoinFlip()) {
|
val item: Array<Coin> = Coin.values()
|
||||||
0 -> {
|
when (Randomizer().randomCoinFlip(item)) {
|
||||||
mCoinStatus = Coin.Heads
|
0 -> mCoinStatus = Coin.Heads
|
||||||
mCoinTextView.text = mCoinStatus.toString()
|
1 -> mCoinStatus = Coin.Tails
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
mCoinStatus = Coin.Tails
|
|
||||||
mCoinTextView.text = mCoinStatus.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCoinTextView.text = mCoinStatus.toString()
|
||||||
|
|
||||||
if (mCoinTextView.visibility == View.INVISIBLE) {
|
if (mCoinTextView.visibility == View.INVISIBLE) {
|
||||||
mCoinTextView.visibility = View.VISIBLE
|
mCoinTextView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
@ -55,33 +55,72 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
// code behind for the 'roll' button
|
// code behind for the 'roll' button
|
||||||
fun onClickDieRoll(view: View?) {
|
fun onClickDieRoll(view: View?) {
|
||||||
when (Randomizer().randomDieRoll()) {
|
val item: Array<SixDie> = SixDie.values()
|
||||||
0 -> {
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
mDieStatus = Die.One
|
0 -> mDieStatus = SixDie.One
|
||||||
mDiceTextView.text = mDieStatus.toString()
|
1 -> mDieStatus = SixDie.Two
|
||||||
}
|
2 -> mDieStatus = SixDie.Three
|
||||||
1 -> {
|
3 -> mDieStatus = SixDie.Four
|
||||||
mDieStatus = Die.Two
|
4 -> mDieStatus = SixDie.Five
|
||||||
mDiceTextView.text = mDieStatus.toString()
|
5 -> mDieStatus = SixDie.Six
|
||||||
}
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
mDiceTextView.visibility = View.VISIBLE
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
@ -11,23 +11,43 @@
|
|||||||
android:id="@+id/rollButton"
|
android:id="@+id/rollButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
android:onClick="onClickDieRoll"
|
android:onClick="onClickDieRoll"
|
||||||
android:text="@string/btn_roll"
|
android:text="@string/btn_roll"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.498"
|
app:layout_constraintHorizontal_bias="0.498"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/diceTextView"
|
app:layout_constraintTop_toBottomOf="@+id/diceTextView" />
|
||||||
app:layout_constraintVertical_bias="0.159" />
|
|
||||||
|
<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
|
<TextView
|
||||||
android:id="@+id/diceTextView"
|
android:id="@+id/diceTextView"
|
||||||
android:layout_width="157dp"
|
android:layout_width="157dp"
|
||||||
android:layout_height="76dp"
|
android:layout_height="76dp"
|
||||||
android:layout_marginBottom="256dp"
|
android:layout_marginTop="144dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="1"
|
android:text="1"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
Loading…
Reference in New Issue
Block a user