If you think the Android project DiceInDark listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/* Dice in the dark. D & D app for the blind and seeing impaired,
* Copyright (C) <2013r> <Lovisa Irpa Helgadottir>
*/*www.java2s.com*/
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/package com.plovergames.diceindark;
import java.util.Random;
import android.util.Log;
import com.plovergames.framework.GameObject;
publicclass Die extends GameObject {
publicstaticfinalfloat X = 1.0f;
publicstaticfinalfloat Y = 1.0f;
publicstaticfinalfloat DIE_WIDTH = 1.0f;
publicstaticfinalfloat DIE_HEIGHT = 1.0f;
publicfinal Random rand;
int sides;
int[] result;
//int result;
int numberOfDice;
boolean hasResult = false;
String name;
public Die(int sides) {
super(X, Y, DIE_WIDTH, DIE_HEIGHT);
this.sides = sides;
rand = new Random();
this.name = "d"+sides;
this.numberOfDice=1;
result = newint[sides];
}
publicvoid shake(){
//Log.d("Die", "Shake");
hasResult=false;
}
publicvoid thrown(){
//Log.d("Die","thrown");
//result=rand.nextInt(sides)+1;
int j= numberOfDice;
// result[0]=rand.nextInt(j);
for(int i=0; i<sides-1; i++){
result[i] = rand.nextInt(j);
j-=result[i];
Log.v("Die result",""+result[i]);
}
result[sides-1]= j;
Log.v("Die result",""+result[sides-1]);
shuffleArray(result);
hasResult=true;
}
privatestaticvoid shuffleArray(int[] a) {
int n = a.length;
Random random = new Random();
random.nextInt();
for (int i = 0; i < n; i++) {
int change = i + random.nextInt(n - i);
swap(a, i, change);
}
}
privatestaticvoid swap(int[] a, int i, int change) {
int helper = a[i];
a[i] = a[change];
a[change] = helper;
}
}