diff --git a/DiceRoller/.gitignore b/DiceRoller/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/DiceRoller/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/DiceRoller/.idea/$CACHE_FILE$ b/DiceRoller/.idea/$CACHE_FILE$ new file mode 100644 index 0000000..f9784d3 --- /dev/null +++ b/DiceRoller/.idea/$CACHE_FILE$ @@ -0,0 +1,17 @@ + + + + + + + + + + + Android + + + + + + \ No newline at end of file diff --git a/DiceRoller/.idea/.gitignore b/DiceRoller/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/DiceRoller/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/DiceRoller/.idea/.name b/DiceRoller/.idea/.name new file mode 100644 index 0000000..a2ed666 --- /dev/null +++ b/DiceRoller/.idea/.name @@ -0,0 +1 @@ +Dice Roller \ No newline at end of file diff --git a/DiceRoller/.idea/compiler.xml b/DiceRoller/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/DiceRoller/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DiceRoller/.idea/dictionaries b/DiceRoller/.idea/dictionaries new file mode 100644 index 0000000..584b056 --- /dev/null +++ b/DiceRoller/.idea/dictionaries @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DiceRoller/.idea/gradle.xml b/DiceRoller/.idea/gradle.xml new file mode 100644 index 0000000..23a89bb --- /dev/null +++ b/DiceRoller/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/DiceRoller/.idea/jarRepositories.xml b/DiceRoller/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/DiceRoller/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/DiceRoller/.idea/misc.xml b/DiceRoller/.idea/misc.xml new file mode 100644 index 0000000..d5d35ec --- /dev/null +++ b/DiceRoller/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/DiceRoller/app/.gitignore b/DiceRoller/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/DiceRoller/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/DiceRoller/app/build.gradle b/DiceRoller/app/build.gradle new file mode 100644 index 0000000..354217c --- /dev/null +++ b/DiceRoller/app/build.gradle @@ -0,0 +1,45 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.diceroller" + minSdkVersion 19 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/DiceRoller/app/proguard-rules.pro b/DiceRoller/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/DiceRoller/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/DiceRoller/app/src/androidTest/java/com/example/diceroller/ExampleInstrumentedTest.kt b/DiceRoller/app/src/androidTest/java/com/example/diceroller/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..56697a2 --- /dev/null +++ b/DiceRoller/app/src/androidTest/java/com/example/diceroller/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.diceroller + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.diceroller", appContext.packageName) + } +} \ No newline at end of file diff --git a/DiceRoller/app/src/main/AndroidManifest.xml b/DiceRoller/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1c65d16 --- /dev/null +++ b/DiceRoller/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DiceRoller/app/src/main/java/com/example/diceroller/MainActivity.kt b/DiceRoller/app/src/main/java/com/example/diceroller/MainActivity.kt new file mode 100644 index 0000000..4f0b3df --- /dev/null +++ b/DiceRoller/app/src/main/java/com/example/diceroller/MainActivity.kt @@ -0,0 +1,62 @@ +package com.example.diceroller + +import android.os.Bundle +import android.widget.Button +import android.widget.ImageView +import androidx.appcompat.app.AppCompatActivity + +/** + * This activity allows the user to roll a dice and view the result + * on the screen. + */ +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + // assign a variable for the button + val rollButton: Button = findViewById(R.id.button) + // add an event listener for the button + rollButton.setOnClickListener { rollDice() } + + rollDice() + } + +/* + +Roll the dice and update the screen with the result. + */ + + private fun rollDice() { + // Create new Dice object with 6 sides and roll it + val dice = Dice(6) + val diceRoll = dice.roll() + + // Find the ImageView in the layout + val diceImage: ImageView = findViewById(R.id.imageView) + + // Determine which drawable resource ID to use based on the dice roll + val drawableResource = when (diceRoll) { + 1 -> R.drawable.dice_1 + 2 -> R.drawable.dice_2 + 3 -> R.drawable.dice_3 + 4 -> R.drawable.dice_4 + 5 -> R.drawable.dice_5 + else -> R.drawable.dice_6 + } + + // Update the ImageView with the correct drawable resource ID + diceImage.setImageResource(drawableResource) + // Update the content description + diceImage.contentDescription = diceRoll.toString() + + } +} + +// Dice Class + +class Dice(private val numSides: Int) { + // return random value based on Dice side number + fun roll(): Int { + return (1..numSides).random() + } +} \ No newline at end of file diff --git a/DiceRoller/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/DiceRoller/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/DiceRoller/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/DiceRoller/app/src/main/res/drawable/dice_1.png b/DiceRoller/app/src/main/res/drawable/dice_1.png new file mode 100644 index 0000000..9cfbd95 Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_1.png differ diff --git a/DiceRoller/app/src/main/res/drawable/dice_2.png b/DiceRoller/app/src/main/res/drawable/dice_2.png new file mode 100644 index 0000000..9166ca8 Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_2.png differ diff --git a/DiceRoller/app/src/main/res/drawable/dice_3.png b/DiceRoller/app/src/main/res/drawable/dice_3.png new file mode 100644 index 0000000..1e0e53d Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_3.png differ diff --git a/DiceRoller/app/src/main/res/drawable/dice_4.png b/DiceRoller/app/src/main/res/drawable/dice_4.png new file mode 100644 index 0000000..cc24c0f Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_4.png differ diff --git a/DiceRoller/app/src/main/res/drawable/dice_5.png b/DiceRoller/app/src/main/res/drawable/dice_5.png new file mode 100644 index 0000000..49d5c61 Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_5.png differ diff --git a/DiceRoller/app/src/main/res/drawable/dice_6.png b/DiceRoller/app/src/main/res/drawable/dice_6.png new file mode 100644 index 0000000..777d7a1 Binary files /dev/null and b/DiceRoller/app/src/main/res/drawable/dice_6.png differ diff --git a/DiceRoller/app/src/main/res/drawable/ic_launcher_background.xml b/DiceRoller/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/DiceRoller/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DiceRoller/app/src/main/res/layout/activity_main.xml b/DiceRoller/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b6ad63e --- /dev/null +++ b/DiceRoller/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + +