Skip to content

Commit bead2af

Browse files
author
Asger Askov Blekinge
committed
Working app with xD6 rolla functionality
1 parent c984011 commit bead2af

File tree

27 files changed

+585
-0
lines changed

27 files changed

+585
-0
lines changed

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "26.0.1"
6+
defaultConfig {
7+
applicationId "dk.blekinge.diceroller"
8+
minSdkVersion 14
9+
targetSdkVersion 24
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:24.2.1'
28+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
29+
testCompile 'junit:junit:4.12'
30+
}

app/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/abr/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package dk.blekinge.diceroller;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("dk.blekinge.diceroller", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="dk.blekinge.diceroller">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
<activity android:name=".Buckets"></activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package dk.blekinge.diceroller;
2+
3+
import android.content.Intent;
4+
import android.graphics.Color;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import android.widget.ImageButton;
9+
import android.widget.TextView;
10+
11+
12+
public class Buckets extends AppCompatActivity {
13+
14+
private final int[] buckets = new int[6];
15+
16+
private int dicepool;
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_buckets);
22+
23+
24+
//Get the intent that started this activity and extract the message string
25+
Intent intent = getIntent();
26+
dicepool = intent.getIntExtra(MainActivity.DICEPOOL, 0);
27+
28+
rollDice(dicepool);
29+
30+
updateReport();
31+
}
32+
33+
private void updateReport() {
34+
TextView report = (TextView) findViewById(R.id.Status);
35+
36+
ImageButton[] dices = getDice();
37+
38+
int selected = 0;
39+
for (int i = 0; i < dices.length; i++) {
40+
ImageButton dice = dices[i];
41+
if (dice.isSelected()){
42+
selected += buckets[i];
43+
}
44+
}
45+
46+
47+
report.setText("Dice pool: "+dicepool+", selected dice: "+selected);
48+
}
49+
50+
private void rollDice(int dicepool) {
51+
for (int i = 0; i < dicepool; i++) {
52+
buckets[roll()]+=1;
53+
}
54+
55+
TextView count1 = (TextView) findViewById(R.id.count1);
56+
count1.setText(String.format("%d", buckets[0]));
57+
58+
TextView count2 = (TextView) findViewById(R.id.count2);
59+
count2.setText(String.format("%d", buckets[1]));
60+
61+
TextView count3 = (TextView) findViewById(R.id.count3);
62+
count3.setText(String.format("%d", buckets[2]));
63+
64+
TextView count4 = (TextView) findViewById(R.id.count4);
65+
count4.setText(String.format("%d", buckets[3]));
66+
67+
TextView count5 = (TextView) findViewById(R.id.count5);
68+
count5.setText(String.format("%d", buckets[4]));
69+
70+
TextView count6 = (TextView) findViewById(R.id.count6);
71+
count6.setText(String.format("%d", buckets[5]));
72+
}
73+
74+
private ImageButton[] getDice(){
75+
return new ImageButton[]{
76+
(ImageButton) findViewById(R.id.D1),
77+
(ImageButton) findViewById(R.id.D2),
78+
(ImageButton) findViewById(R.id.D3),
79+
(ImageButton) findViewById(R.id.D4),
80+
(ImageButton) findViewById(R.id.D5),
81+
(ImageButton) findViewById(R.id.D6)
82+
};
83+
}
84+
85+
int roll() {
86+
return (int)(6.0 * Math.random());
87+
}
88+
89+
public void reroll(View rerollButton){
90+
ImageButton[] dices = getDice();
91+
int rerollPool = 0;
92+
for (int i = 0; i < dices.length; i++) {
93+
ImageButton dice = dices[i];
94+
if (dice.isSelected()){
95+
rerollPool += buckets[i];
96+
buckets[i] = 0;
97+
toggleSelect(dice);
98+
}
99+
}
100+
rollDice(rerollPool);
101+
}
102+
103+
public void rollon(View rollonButton){
104+
ImageButton[] dices = getDice();
105+
dicepool = 0;
106+
for (int i = 0; i < dices.length; i++) {
107+
ImageButton dice = dices[i];
108+
if (dice.isSelected()){
109+
dicepool += buckets[i];
110+
toggleSelect(dice);
111+
}
112+
buckets[i] = 0;
113+
}
114+
rollDice(dicepool);
115+
116+
}
117+
118+
119+
120+
121+
public void toggleSelect(View view) {
122+
if (view instanceof ImageButton) {
123+
ImageButton imageButton = (ImageButton) view;
124+
if (imageButton.isSelected()){
125+
imageButton.setBackgroundColor(Color.WHITE);
126+
imageButton.setSelected(false);
127+
} else {
128+
imageButton.setBackgroundColor(Color.BLUE);
129+
imageButton.setSelected(true);
130+
}
131+
updateReport();
132+
}
133+
134+
}
135+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dk.blekinge.diceroller;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.EditText;
8+
9+
import static android.R.id.message;
10+
import static android.provider.AlarmClock.EXTRA_MESSAGE;
11+
12+
public class MainActivity extends AppCompatActivity {
13+
14+
public static final String DICEPOOL = "dicepool";
15+
16+
@Override
17+
protected void onCreate(Bundle savedInstanceState) {
18+
super.onCreate(savedInstanceState);
19+
setContentView(R.layout.activity_main);
20+
}
21+
22+
23+
public void RollX(View view) {
24+
Intent intent = new Intent(this, Buckets.class);
25+
EditText editText = (EditText) findViewById(R.id.editText);
26+
int dicePool = Integer.parseInt(editText.getText().toString());
27+
28+
intent.putExtra(DICEPOOL, dicePool);
29+
startActivity(intent);
30+
31+
}
32+
}

app/src/main/res/drawable/d1.png

11.5 KB
Loading

app/src/main/res/drawable/d2.png

13.6 KB
Loading

app/src/main/res/drawable/d3.png

16.1 KB
Loading

app/src/main/res/drawable/d4.png

15.7 KB
Loading

0 commit comments

Comments
 (0)