So I have recently decided to recreate the game of "Dice 10,000" using Java programming and I'm having some issues getting some of the rules to work. There are 4 rules that I cannot get to work.
1) 3 of any number = 10x the face value of the 3 dice
2) A full straight (1 - 6) = 3,000 points
3) 3 pairs = 1,000 points
4) 3 One's = 1,000 points
I'm just not sure how to get these to work... I believe I would use a set, but I am very, very inexperienced with sets and how to use them and what methods they contain. I can probably figure the second one without a set, but it is the 1st, 3rd, and 4th ones giving me the most trouble.
//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
}
}
Sorry, I know it's a lot right now. Hopefully you guys can give me some sample code to get me going? Thanks a ton.
All the Best
Andrew
EDIT: As of now, I will not be able to respond until tomorrow morning. I apologize for lack of feedback, but it is late. I'll get back with tries and responses tomorrow.
Map<Integer, Integer>for pairs, where the key will be the dice's number and the value the number of occurrences.if(/*There are three fives*/)Also, could you post an answer describing how to use a Map? I will gladly accept it if my problem is solved by it. for now, however, I'm off to bed. I will feedback tomorrow.Map<Integer, Integer>you can iterate through the values and see if any of them is bigger then 6 ( three pairs ) or check to see if the map has only one entry ( a full straight ).diceKeeparenulluntil assigned. Therefore, If the player keeps dice number 5, then dice numbers 1 - 4 will benulluntil "kept". Because of this, I cannot use Collections.sort(diceKeep) or a BubbleSort or a Selection Sort (All throw aNullPointerException)