1
因此,我最近决定使用Java编程重新创建“Dice 10,000”游戏,并且遇到一些问题需要执行某些规则。有4条规则我无法工作。如何计算Java中ArrayList中特定项目的数量
1)任何数量= 10倍的面的3个骰子的值的3
2)一个完整的直的(1 - 6)= 3000点
3)3双= 1000点
4)3 One's = 1,000分
我只是不确定如何让这些工作...我相信我会使用一套,但我对套非常非常缺乏经验,以及如何使用它们和他们包含什么方法。我大概可以算出第二个,但是第一,第三和第四个给我的麻烦最多。
//Andrew M
import java.util.*;
import java.io.*;
class Zilch
{
public static Random r = new Random();
public static ArrayList<Integer> diceList = new ArrayList<Integer>();
public static int count = 0, humanScore = 0, compScore = 0, humanBank = 0, compBank = 0, lastMove = 0;
public static ArrayList<Integer> diceKeep = new ArrayList<Integer>();
public static boolean gameOn = true, x = true;
//-----------------------------------------------------------------------------------
public static void main(String[] args)
{
for (int j = 1; j <= 6; j++)
{
diceList.add(j);
diceKeep.add(null);
}
do
{
do
{
x = true;
for (int k = 0; k < diceKeep.size(); k++)
{
if (diceKeep.get(k) != null)
{
System.out.println("Dice #" + (k + 1) + ": " + diceKeep.get(k) + " -- kept.");
}
}
System.out.println();
System.out.println();
boolean b = true;
for (int i = 0; i < diceList.size(); i++)
{
if(diceList.get(i) != 0)
{
diceList.set(i, r.nextInt(6) + 1);
System.out.println("Dice #" + (i+1) + " is a " + diceList.get(i));
}
}
System.out.println();
System.out.println("Select which dice to roll again... (Select one at a time, 1 - 6), then type \"go\" to complete your turn.");
Scanner input = new Scanner(System.in);
/*-----------UNNECCESARY CODE--------------*/
else
if (selection.equals("go"))
{
System.out.println();
System.out.println();
if (diceKeep.get(0) == 1)
{
humanBank = humanBank + 100;
lastMove = 100;
}
else
if (diceKeep.get(0) == 5)
{
humanBank = humanBank + 500;
lastMove = 500;
}
/*--------------I NEED THE RULES TO GO HERE---*/
b = false;
}
}
while(b == true);
//-----------------------------------------------------------------------
if(gameOn == true)
{
x = true;
//Place Score Card Here
}
}
while (x == true);
}
while (1< 2); //Just here for testing purposes, for now
}
}
对不起,我知道现在很多。希望你们可以给我一些示例代码让我走?万分感谢。
一切顺利
安德鲁
编辑:截至目前,我将无法到明天早上做出回应。我对缺乏反馈表示歉意,但已经晚了。明天我会回复尝试和回应。
有很多的这样做的方法。如果是我,我会使用一个Map来配对,其中关键字是骰子的编号,值是出现次数。 –
Titus
嗯,我期待把这个放在if语句中,比如说if(/ *有三个fives * /)'还有,你能发表一个描述如何使用Map的答案吗?如果我的问题得到解决,我会很乐意接受。但现在,我正在睡觉。我会明天反馈。 –
使用Map可以遍历这些值并查看它们中的任何一个是否大于6(三对),或者检查地图是否只有一个条目(完整直线)。 –
Titus