android+骰子动画,Android Studio中的复杂骰子滚轮应用程序

想通了的人可能会寻找在未来的答案:

static void rolls(){

//tells the progrom what characters to split the string by, "A" allows for either "+" or "-" at the begininning of the string

Pattern expressionFormat = Pattern.compile("((\\A|\\+|\\-){1}(\\d+[d])?\\d+)");

String equationAdd = et_roll1.getText().toString();

Matcher matcher = expressionFormat.matcher(equationAdd);

String rollsAdd = "";

while(matcher.find()){

rollsAdd = matcher.group();

String[] diedataArray = rollsAdd.split("(\\+|\\-)"); //tells the program to isolate values with either "+" or "-"

String dieData = diedataArray[0];

if (diedataArray[0].length() == 0) {

dieData = diedataArray[1];

}

//splits the users input data further by looking for a value of "d", the number to the left of the "d" = times to roll, the number to the right of the "d" = number of faces on the die

if (rollsAdd.length() > 2){

dieDataAdd = dieData.split("d");

int dieQty = Integer.parseInt(dieDataAdd[0]);

int dieFace = Integer.parseInt(dieDataAdd[1]);

int rollSum = 0;

//rolls a dice based on the users input....ie. 1d6 rolls a single 6 sides dice, 3d20 rolls 3 different 20 sides dice

for (int i = 0; i < dieQty; i++){

roll = r.nextInt(dieFace)+1;

rollSum += roll;

}

//program speicially looks for the "-" operator and then adds the value to the sumSubtract variable

if (rollsAdd.charAt(0) == '-'){

sumSubtract += rollSum;

}

// if the operator is "+", add its value to sumAdd variable

else{

sumAdd += rollSum;

}

}

//this accounts for any whole numbers that are not dice.....ie. 1d6+2, 2 being the modifier of the roll

else{

int modifier = Integer.parseInt(rollsAdd);

modTotal += modifier;

}

//these 2 IF statements test to see which value is the highest, then subtracts (only works if user inputs subtraction) the highest first in order to "always" show a positive number

if (sumAdd > sumSubtract){

sum = sumAdd - sumSubtract + modTotal;

}

else if (sumSubtract > sumAdd){

sum = sumSubtract - sumAdd + modTotal;

}

else{

sum = 0;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值