added logic to layout
This commit is contained in:
parent
3634ac9da4
commit
0c16d2798b
@ -6,10 +6,13 @@ import android.util.Log
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import kotlin.random.Random
|
||||||
|
import kotlin.random.nextInt
|
||||||
|
|
||||||
class DiceActivity : AppCompatActivity() {
|
class DiceActivity : AppCompatActivity() {
|
||||||
|
|
||||||
// Private member variables per the layout
|
// Private member variables per the layout
|
||||||
|
private lateinit var mMetaStatusTextView: TextView
|
||||||
private lateinit var mDiceTextView: TextView
|
private lateinit var mDiceTextView: TextView
|
||||||
private lateinit var mRollButton: Button
|
private lateinit var mRollButton: Button
|
||||||
|
|
||||||
@ -21,10 +24,11 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_dice)
|
setContentView(R.layout.activity_dice)
|
||||||
|
|
||||||
|
mMetaStatusTextView = findViewById(R.id.metaStatusTextView)
|
||||||
mDiceTextView = findViewById(R.id.diceTextView)
|
mDiceTextView = findViewById(R.id.diceTextView)
|
||||||
mRollButton = findViewById(R.id.rollButton)
|
mRollButton = findViewById(R.id.rollButton)
|
||||||
|
|
||||||
// I realize that you toggle visability in xml
|
// I realize that you toggle visibility in xml
|
||||||
mDiceTextView.visibility = View.INVISIBLE
|
mDiceTextView.visibility = View.INVISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +57,25 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code behind for the 'roll d4' button
|
||||||
|
fun onClickDieFourRoll(view: View?) {
|
||||||
|
val item: Array<FourDie> = FourDie.values()
|
||||||
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
|
0 -> mDieStatus = FourDie.One
|
||||||
|
1 -> mDieStatus = FourDie.Two
|
||||||
|
2 -> mDieStatus = FourDie.Three
|
||||||
|
3 -> mDieStatus = FourDie.Four
|
||||||
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D4!"
|
||||||
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// code behind for the 'roll' button
|
// code behind for the 'roll' button
|
||||||
fun onClickDieRoll(view: View?) {
|
fun onClickDieRoll(view: View?) {
|
||||||
val item: Array<SixDie> = SixDie.values()
|
val item: Array<SixDie> = SixDie.values()
|
||||||
@ -65,6 +88,7 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
5 -> mDieStatus = SixDie.Six
|
5 -> mDieStatus = SixDie.Six
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D6!"
|
||||||
mDiceTextView.text = mDieStatus.toString()
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
if (mDiceTextView.visibility == View.INVISIBLE) {
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
@ -72,6 +96,29 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code behind for the 'roll d8' button
|
||||||
|
fun onClickDieEightRoll(view: View?) {
|
||||||
|
val item: Array<EightDie> = EightDie.values()
|
||||||
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
|
0 -> mDieStatus = EightDie.One
|
||||||
|
1 -> mDieStatus = EightDie.Two
|
||||||
|
2 -> mDieStatus = EightDie.Three
|
||||||
|
3 -> mDieStatus = EightDie.Four
|
||||||
|
4 -> mDieStatus = EightDie.Five
|
||||||
|
5 -> mDieStatus = EightDie.Six
|
||||||
|
6 -> mDieStatus = EightDie.Seven
|
||||||
|
7 -> mDieStatus = EightDie.Eight
|
||||||
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D8!"
|
||||||
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// code behind for the 'roll d10' button
|
||||||
fun onClickDieTenRoll(view: View?) {
|
fun onClickDieTenRoll(view: View?) {
|
||||||
val item: Array<TenDie> = TenDie.values()
|
val item: Array<TenDie> = TenDie.values()
|
||||||
when (Randomizer().randomDieRoll(item)) {
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
@ -87,6 +134,7 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
9 -> mDieStatus = TenDie.Ten
|
9 -> mDieStatus = TenDie.Ten
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D10!"
|
||||||
mDiceTextView.text = mDieStatus.toString()
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
if (mDiceTextView.visibility == View.INVISIBLE) {
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
@ -94,6 +142,34 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code behind the 'roll d12' button
|
||||||
|
fun onClickDieTwelveRoll(view: View?) {
|
||||||
|
val item: Array<TwelveDie> = TwelveDie.values()
|
||||||
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
|
0 -> mDieStatus = TwelveDie.One
|
||||||
|
1 -> mDieStatus = TwelveDie.Two
|
||||||
|
2 -> mDieStatus = TwelveDie.Three
|
||||||
|
3 -> mDieStatus = TwelveDie.Four
|
||||||
|
4 -> mDieStatus = TwelveDie.Five
|
||||||
|
5 -> mDieStatus = TwelveDie.Six
|
||||||
|
6 -> mDieStatus = TwelveDie.Seven
|
||||||
|
7 -> mDieStatus = TwelveDie.Eight
|
||||||
|
8 -> mDieStatus = TwelveDie.Nine
|
||||||
|
9 -> mDieStatus = TwelveDie.Ten
|
||||||
|
10 -> mDieStatus = TwelveDie.Eleven
|
||||||
|
11 -> mDieStatus = TwelveDie.Twelve
|
||||||
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D12!"
|
||||||
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// code behind the 'roll d20' button
|
||||||
fun onClickDieTwentyRoll(view: View?) {
|
fun onClickDieTwentyRoll(view: View?) {
|
||||||
val item: Array<TwentyDie> = TwentyDie.values()
|
val item: Array<TwentyDie> = TwentyDie.values()
|
||||||
when (Randomizer().randomDieRoll(item)) {
|
when (Randomizer().randomDieRoll(item)) {
|
||||||
@ -119,10 +195,22 @@ class DiceActivity : AppCompatActivity() {
|
|||||||
19 -> mDieStatus = TwentyDie.Twenty
|
19 -> mDieStatus = TwentyDie.Twenty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D20!"
|
||||||
mDiceTextView.text = mDieStatus.toString()
|
mDiceTextView.text = mDieStatus.toString()
|
||||||
|
|
||||||
if (mDiceTextView.visibility == View.INVISIBLE) {
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
mDiceTextView.visibility = View.VISIBLE
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// code behind the 'roll d100' button
|
||||||
|
// I'm not going to make an enum that's a hundred lines long lol
|
||||||
|
fun onClickDie100Roll(view: View?) {
|
||||||
|
mMetaStatusTextView.text = "You have rolled a D100!"
|
||||||
|
mDiceTextView.text = Random.nextInt(0..100).toString()
|
||||||
|
|
||||||
|
if (mDiceTextView.visibility == View.INVISIBLE) {
|
||||||
|
mDiceTextView.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,12 @@
|
|||||||
package com.wyattjmiller.dicerollerapp
|
package com.wyattjmiller.dicerollerapp
|
||||||
|
|
||||||
|
enum class FourDie : Die {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four
|
||||||
|
}
|
||||||
|
|
||||||
enum class SixDie : Die {
|
enum class SixDie : Die {
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
@ -9,6 +16,17 @@ enum class SixDie : Die {
|
|||||||
Six
|
Six
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class EightDie : Die {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four,
|
||||||
|
Five,
|
||||||
|
Six,
|
||||||
|
Seven,
|
||||||
|
Eight
|
||||||
|
}
|
||||||
|
|
||||||
enum class TenDie : Die {
|
enum class TenDie : Die {
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
@ -22,6 +40,21 @@ enum class TenDie : Die {
|
|||||||
Ten
|
Ten
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class TwelveDie : Die {
|
||||||
|
One,
|
||||||
|
Two,
|
||||||
|
Three,
|
||||||
|
Four,
|
||||||
|
Five,
|
||||||
|
Six,
|
||||||
|
Seven,
|
||||||
|
Eight,
|
||||||
|
Nine,
|
||||||
|
Ten,
|
||||||
|
Eleven,
|
||||||
|
Twelve,
|
||||||
|
}
|
||||||
|
|
||||||
enum class TwentyDie : Die {
|
enum class TwentyDie : Die {
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
|
Loading…
Reference in New Issue
Block a user