Initial commit
This commit is contained in:
commit
160949c0e5
8
.classpath
Normal file
8
.classpath
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
bin/
|
||||
gen/
|
||||
33
.project
Normal file
33
.project
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>DiceUp</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
23
AndroidManifest.xml
Normal file
23
AndroidManifest.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.ianonavy.diceup"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name=".DiceUpActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
40
proguard.cfg
Normal file
40
proguard.cfg
Normal file
@ -0,0 +1,40 @@
|
||||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends android.app.Activity {
|
||||
public void *(android.view.View);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
11
project.properties
Normal file
11
project.properties
Normal file
@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-3
|
||||
BIN
res/drawable/green_sticker.png
Normal file
BIN
res/drawable/green_sticker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 499 B |
BIN
res/drawable/ic_launcher.png
Normal file
BIN
res/drawable/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
res/drawable/red_sticker.png
Normal file
BIN
res/drawable/red_sticker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 474 B |
BIN
res/drawable/yellow_sticker.png
Normal file
BIN
res/drawable/yellow_sticker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 461 B |
61
res/layout/main.xml
Normal file
61
res/layout/main.xml
Normal file
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/score"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="@string/default_score"
|
||||
android:textSize="72pt" />
|
||||
|
||||
<TableLayout android:id="@+id/dice" android:layout_width="fill_parent" android:layout_height="wrap_content" >
|
||||
|
||||
<TableRow android:id="@+id/row1" android:layout_width="wrap_content" android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView android:id="@+id/die1" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die2" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die3" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die4" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die5" style="@style/Die" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow android:id="@+id/row2" android:layout_width="wrap_content" android:layout_height="wrap_content" >
|
||||
|
||||
<ImageView android:id="@+id/die6" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die7" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die8" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die9" style="@style/Die" />
|
||||
<ImageView android:id="@+id/die10" style="@style/Die" />
|
||||
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/row3"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/roll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dip"
|
||||
android:text="@string/roll" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/reset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dip"
|
||||
android:text="@string/reset" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
</LinearLayout>
|
||||
11
res/values/strings.xml
Normal file
11
res/values/strings.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="hello">Hello World, DiceUpActivity!</string>
|
||||
<string name="app_name">DiceUp</string>
|
||||
<string name="default_score">0</string>
|
||||
<string name="roll">Dice Up</string>
|
||||
<string name="hold">Hold</string>
|
||||
<string name="reset">Reset</string>
|
||||
|
||||
</resources>
|
||||
9
res/values/styles.xml
Normal file
9
res/values/styles.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Die">
|
||||
<item name="android:layout_gravity">center_horizontal</item>
|
||||
<item name="android:layout_width">fill_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:src">@drawable/green_sticker</item>
|
||||
</style>
|
||||
</resources>
|
||||
79
src/com/ianonavy/diceup/DiceUpActivity.java
Normal file
79
src/com/ianonavy/diceup/DiceUpActivity.java
Normal file
@ -0,0 +1,79 @@
|
||||
package com.ianonavy.diceup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class DiceUpActivity extends Activity {
|
||||
|
||||
Die[] dice;
|
||||
Button roll, hold, reset;
|
||||
TextView score;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
dice = new Die[10];
|
||||
for (int i = 0; i < 10; i ++) {
|
||||
dice[i] = new Die(this, i);
|
||||
}
|
||||
roll = (Button) findViewById(R.id.roll);
|
||||
reset = (Button) findViewById(R.id.reset);
|
||||
|
||||
score = (TextView) findViewById(R.id.score);
|
||||
|
||||
roll.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int numGreenLast = 0;
|
||||
int numGreen = 0;
|
||||
int numRed = 0;
|
||||
|
||||
for (Die die : dice) {
|
||||
if (die.isGreen()) {
|
||||
numGreenLast++;
|
||||
die.roll();
|
||||
|
||||
if (die.isRed()) {
|
||||
numRed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (die.isGreen()) {
|
||||
numGreen++;
|
||||
}
|
||||
}
|
||||
|
||||
score.setText("" + (Integer.parseInt(score.getText().toString()) + numGreen));
|
||||
|
||||
if (numGreenLast == 0) {
|
||||
for (Die die : dice) {
|
||||
die.reset();
|
||||
}
|
||||
}
|
||||
|
||||
Log.d("numRed", "" + numRed);
|
||||
Log.d("numGreenLast", "" + numGreenLast);
|
||||
if (numRed == numGreenLast && numRed != 0) {
|
||||
score.setText(getText(R.string.default_score));
|
||||
}
|
||||
}
|
||||
});
|
||||
reset.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
score.setText(getString(R.string.default_score));
|
||||
for (Die die : dice) {
|
||||
die.reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
108
src/com/ianonavy/diceup/Die.java
Normal file
108
src/com/ianonavy/diceup/Die.java
Normal file
@ -0,0 +1,108 @@
|
||||
package com.ianonavy.diceup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class Die {
|
||||
ImageView image;
|
||||
State state;
|
||||
|
||||
public enum State {
|
||||
RED,
|
||||
YELLOW,
|
||||
GREEN
|
||||
}
|
||||
|
||||
int nRed, nYellow, nGreen;
|
||||
float numFaces, pRed, pYellow, pGreen;
|
||||
boolean reset;
|
||||
|
||||
public Die(Activity activity, int imageID) {
|
||||
this(activity, 1, 2, 3, imageID);
|
||||
}
|
||||
|
||||
public Die(Activity activity, int nRed, int nYellow, int nGreen, int imageID) {
|
||||
this.nRed = nRed;
|
||||
this.nYellow = nYellow;
|
||||
this.nGreen = nGreen;
|
||||
|
||||
numFaces = nRed + nYellow + nGreen;
|
||||
pRed = nRed / numFaces;
|
||||
pYellow = nYellow / numFaces;
|
||||
pGreen = nGreen / numFaces;
|
||||
|
||||
image = (ImageView) activity.findViewById(getDieID(imageID));
|
||||
state = State.GREEN;
|
||||
|
||||
reset = true;
|
||||
}
|
||||
|
||||
public void roll() {
|
||||
reset = false;
|
||||
double random = Math.random();
|
||||
if (random < pRed) {
|
||||
setRed();
|
||||
} else if (random < pRed + pYellow) {
|
||||
setYellow();
|
||||
} else {
|
||||
setGreen();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRed() {
|
||||
this.state = State.RED;
|
||||
image.setImageResource(R.drawable.red_sticker);
|
||||
}
|
||||
|
||||
public void setYellow() {
|
||||
this.state = State.YELLOW;
|
||||
image.setImageResource(R.drawable.yellow_sticker);
|
||||
}
|
||||
|
||||
public void setGreen() {
|
||||
this.state = State.GREEN;
|
||||
image.setImageResource(R.drawable.green_sticker);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
reset = true;
|
||||
setGreen();
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public int getDieID(int i) {
|
||||
int id = 0;
|
||||
switch (i) {
|
||||
case 0: id = R.id.die1; break;
|
||||
case 1: id = R.id.die2; break;
|
||||
case 2: id = R.id.die3; break;
|
||||
case 3: id = R.id.die4; break;
|
||||
case 4: id = R.id.die5; break;
|
||||
case 5: id = R.id.die6; break;
|
||||
case 6: id = R.id.die7; break;
|
||||
case 7: id = R.id.die8; break;
|
||||
case 8: id = R.id.die9; break;
|
||||
case 9: id = R.id.die10; break;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isRed() {
|
||||
return this.state == State.RED;
|
||||
}
|
||||
|
||||
public boolean isYellow() {
|
||||
return this.state == State.YELLOW;
|
||||
}
|
||||
|
||||
public boolean isGreen() {
|
||||
return this.state == State.GREEN;
|
||||
}
|
||||
|
||||
public boolean isReset() {
|
||||
return reset;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user