Finish up the project
This commit is contained in:
parent
f6cfb5794a
commit
2a44fd5f5b
@ -4,11 +4,9 @@ public class DiceCup{
|
|||||||
private ArrayList<MyDie> dice;
|
private ArrayList<MyDie> dice;
|
||||||
private int creditBalance;
|
private int creditBalance;
|
||||||
|
|
||||||
|
|
||||||
public DiceCup(int Dx) {
|
public DiceCup(int Dx) {
|
||||||
dice = new ArrayList<MyDie>();
|
dice = new ArrayList<MyDie>();
|
||||||
creditBalance = 10;
|
creditBalance = 10;
|
||||||
|
|
||||||
MyDie die;
|
MyDie die;
|
||||||
|
|
||||||
for (int i = 0; i <3; i++){
|
for (int i = 0; i <3; i++){
|
||||||
@ -24,11 +22,9 @@ public class DiceCup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Accessors */
|
/* Accessors */
|
||||||
|
|
||||||
public int getCredits(){
|
public int getCredits(){
|
||||||
return creditBalance;
|
return creditBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<MyDie> getDice(){
|
public ArrayList<MyDie> getDice(){
|
||||||
return dice;
|
return dice;
|
||||||
}
|
}
|
||||||
@ -41,17 +37,17 @@ public class DiceCup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
|
||||||
public void roll(){
|
public void roll(){
|
||||||
for (MyDie die:dice){
|
for (MyDie die:dice){
|
||||||
die.roll();
|
die.roll();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void updateCredits(){
|
public void updateCredits(){
|
||||||
creditBalance -=1;
|
creditBalance -=1;
|
||||||
|
checkTriplets();
|
||||||
|
checkDoubles();
|
||||||
|
checkLarge();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enoughCredits(){
|
public boolean enoughCredits(){
|
||||||
if (creditBalance > 0){
|
if (creditBalance > 0){
|
||||||
return true;
|
return true;
|
||||||
@ -60,11 +56,10 @@ public class DiceCup{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRoll(int [] values){
|
public void testRoll(int [] values){
|
||||||
//roll dice until desired 3 int array happens
|
//roll dice until desired 3 int array happens
|
||||||
if (enoughCredits()){
|
if (enoughCredits()){
|
||||||
updateCredits();
|
creditBalance -= 1;
|
||||||
for (int i =0; i<dice.size(); i++){
|
for (int i =0; i<dice.size(); i++){
|
||||||
while (dice.get(i).getValue() != values[i]){
|
while (dice.get(i).getValue() != values[i]){
|
||||||
dice.get(i).roll();
|
dice.get(i).roll();
|
||||||
@ -74,15 +69,13 @@ public class DiceCup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Win conditions */
|
/* Win conditions */
|
||||||
|
|
||||||
public void checkTriplets(){
|
public void checkTriplets(){
|
||||||
if ( dice.get(0).compareTo(dice.get(1)) == 0 &&
|
if ( dice.get(0).compareTo(dice.get(1)) == 0 &&
|
||||||
dice.get(0).compareTo(dice.get(2)) == 0){
|
dice.get(0).compareTo(dice.get(2)) == 0){
|
||||||
creditBalance +=1;
|
creditBalance +=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void checkDoubles(){
|
||||||
public void checkDouble(){
|
|
||||||
if ( dice.get(0).compareTo(dice.get(1)) == 0 ||
|
if ( dice.get(0).compareTo(dice.get(1)) == 0 ||
|
||||||
dice.get(0).compareTo(dice.get(2)) == 0 ||
|
dice.get(0).compareTo(dice.get(2)) == 0 ||
|
||||||
dice.get(1).compareTo(dice.get(2)) == 0){
|
dice.get(1).compareTo(dice.get(2)) == 0){
|
||||||
|
@ -10,10 +10,10 @@ public class GameManager{
|
|||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
ArrayList<MyDie> dice = diceCup.getDice();
|
ArrayList<MyDie> dice = diceCup.getDice();
|
||||||
return "GameManager{\n" +
|
return "GameManager{" +
|
||||||
"Die 1 = " + dice.get(0).getValue() +
|
"\nDie 1 = " + dice.get(0).getValue() +
|
||||||
"\nDie 2 = " + dice.get(1).getValue() +
|
"\nDie 2 = " + dice.get(1).getValue() +
|
||||||
"Die 3 = " + dice.get(2).getValue() + "}\n";
|
"\nDie 3 = " + dice.get(2).getValue() + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiceCup getDice(){
|
public DiceCup getDice(){
|
||||||
@ -25,36 +25,40 @@ public class GameManager{
|
|||||||
Scanner scnr = new Scanner(System.in);
|
Scanner scnr = new Scanner(System.in);
|
||||||
int diceSides;
|
int diceSides;
|
||||||
|
|
||||||
System.out.println("Do you want to play with 6 or 8 dice?\n");
|
System.out.println("Do you want to play with 6 or 8 dice?");
|
||||||
diceSides = scnr.nextInt();
|
diceSides = scnr.nextInt();
|
||||||
|
scnr.nextLine();
|
||||||
GameManager game = new GameManager(diceSides);
|
GameManager game = new GameManager(diceSides);
|
||||||
|
|
||||||
String userInput;
|
String userInput;
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
System.out.println("Type Roll to play, Stop to end\n");
|
System.out.println("Type Roll to play, Stop to end");
|
||||||
userInput = scnr.next();
|
userInput = scnr.nextLine();
|
||||||
|
|
||||||
if (userInput.toLowerCase() == "stop"){
|
if (userInput.toLowerCase().equals("stop")){break;}
|
||||||
break;}
|
if (game.diceCup.enoughCredits()){
|
||||||
if (userInput.toLowerCase() == "roll"){
|
|
||||||
System.out.println("Credits before bet: " +
|
if (userInput.toLowerCase().equals("roll")){
|
||||||
|
System.out.println("\nCredits before bet: " +
|
||||||
game.diceCup.getCredits());
|
game.diceCup.getCredits());
|
||||||
// Roll Dice
|
// Roll Dice
|
||||||
game.diceCup.roll();
|
game.getDice().roll();
|
||||||
game.diceCup.updateCredits();
|
game.getDice().updateCredits();
|
||||||
|
|
||||||
System.out.println(game.toString());
|
System.out.println(game.toString());
|
||||||
|
|
||||||
System.out.println("Total sum of Dice: " +
|
System.out.println("Total sum of Dice: " +
|
||||||
game.diceCup.getTotal());
|
game.diceCup.getTotal());
|
||||||
System.out.println("Credits after bet: " +
|
System.out.println("Credits after bet: " +
|
||||||
game.diceCup.getCredits());
|
game.diceCup.getCredits() + "\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("You do not have enough credits! \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scnr.close();
|
scnr.close();
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ public class MyDiceGameTest {
|
|||||||
// confirm large is rolled
|
// confirm large is rolled
|
||||||
GameManager game = new GameManager(6);
|
GameManager game = new GameManager(6);
|
||||||
int credits = game.getDice().getCredits();
|
int credits = game.getDice().getCredits();
|
||||||
game.getDice().testRoll(new int[]{6, 6, 5});
|
game.getDice().testRoll(new int[]{6, 4, 5});
|
||||||
game.getDice().checkLarge();
|
game.getDice().checkLarge();
|
||||||
Assert.assertEquals("Dice => (6,6,5): credits should stay the same",
|
Assert.assertEquals("Dice => (6,4,5): credits should stay the same",
|
||||||
game.getDice().getCredits(), credits);
|
game.getDice().getCredits(), credits);
|
||||||
|
|
||||||
// confirm large is not rolled
|
// confirm large is not rolled
|
||||||
@ -44,38 +44,68 @@ public class MyDiceGameTest {
|
|||||||
Assert.assertEquals("Dice => (1,2,3): credits should decrease by one",
|
Assert.assertEquals("Dice => (1,2,3): credits should decrease by one",
|
||||||
game2.getDice().getCredits(), credits - 1);
|
game2.getDice().getCredits(), credits - 1);
|
||||||
|
|
||||||
// confirm large rolled with three of kind
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************
|
||||||
|
* Test Doubles
|
||||||
|
*****************************************************/
|
||||||
|
@Test
|
||||||
|
public void testDoubles() {
|
||||||
|
// confirm doubles is rolled. 1st Combo
|
||||||
|
GameManager game = new GameManager(6);
|
||||||
|
int credits = game.getDice().getCredits();
|
||||||
|
game.getDice().testRoll(new int[]{1, 1, 2});
|
||||||
|
game.getDice().checkDoubles();
|
||||||
|
Assert.assertEquals("Dice => (1,1,2): credits should stay the same",
|
||||||
|
game.getDice().getCredits(), credits);
|
||||||
|
|
||||||
|
// confirm doubles is rolled. 2nd Combo
|
||||||
|
GameManager game2 = new GameManager(6);
|
||||||
|
int credits2 = game2.getDice().getCredits();
|
||||||
|
game2.getDice().testRoll(new int[]{2, 1, 1});
|
||||||
|
game2.getDice().checkDoubles();
|
||||||
|
Assert.assertEquals("Dice => (1,1,1): credits should stay the same",
|
||||||
|
game2.getDice().getCredits(), credits2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************
|
||||||
|
* Test Combination of Points Awarded
|
||||||
|
*****************************************************/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCombinations(){
|
||||||
|
// confirm large and double are called
|
||||||
|
GameManager game = new GameManager(6);
|
||||||
|
int credits = game.getDice().getCredits();
|
||||||
|
game.getDice().testRoll(new int[]{6, 6, 3});
|
||||||
|
game.getDice().checkDoubles();
|
||||||
|
game.getDice().checkLarge();
|
||||||
|
Assert.assertEquals("Dice => (6,6,3): credits should increase by one",
|
||||||
|
game.getDice().getCredits(), credits + 1);
|
||||||
|
|
||||||
|
// confirm large, triplets and doubles are given points
|
||||||
GameManager game3 = new GameManager(6);
|
GameManager game3 = new GameManager(6);
|
||||||
credits = game3.getDice().getCredits();
|
credits = game3.getDice().getCredits();
|
||||||
game3.getDice().testRoll(new int[]{4, 4, 4});
|
game3.getDice().testRoll(new int[]{4, 4, 4});
|
||||||
game3.getDice().checkLarge();
|
game3.getDice().checkLarge();
|
||||||
game3.getDice().checkTriplets();
|
game3.getDice().checkTriplets();
|
||||||
Assert.assertEquals("Dice => (4,4,4): credits should increased by one",
|
game3.getDice().checkDoubles();
|
||||||
game3.getDice().getCredits(), credits + 1);
|
Assert.assertEquals("Dice => (4,4,4): credits should increased by two",
|
||||||
|
game3.getDice().getCredits(), credits + 2);
|
||||||
|
|
||||||
// confirm large is not rolled with three of kind
|
// confirm triplets and doubles are called but not large
|
||||||
GameManager game4 = new GameManager(6);
|
GameManager game4 = new GameManager(6);
|
||||||
credits = game4.getDice().getCredits();
|
credits = game4.getDice().getCredits();
|
||||||
game4.getDice().testRoll(new int[]{3, 3, 3});
|
game4.getDice().testRoll(new int[]{3, 3, 3});
|
||||||
game4.getDice().checkLarge();
|
game4.getDice().checkLarge();
|
||||||
game4.getDice().checkTriplets();
|
game4.getDice().checkTriplets();
|
||||||
Assert.assertEquals("Dice => (3,3,3): credits should stay the same",
|
game4.getDice().checkDoubles();
|
||||||
game4.getDice().getCredits(), credits);
|
Assert.assertEquals("Dice => (3,3,3): credits should increase by one",
|
||||||
|
game4.getDice().getCredits(), credits+1);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************
|
|
||||||
* Test Triplets
|
|
||||||
*****************************************************/
|
|
||||||
@Test
|
|
||||||
public void testTriplets() {
|
|
||||||
// confirm triplets is rolled
|
|
||||||
GameManager game = new GameManager(6);
|
|
||||||
int credits = game.getDice().getCredits();
|
|
||||||
game.getDice().testRoll(new int[]{1, 1, 1});
|
|
||||||
game.getDice().checkTriplets();
|
|
||||||
Assert.assertEquals("Dice => (1,1,1): credits should stay the same",
|
|
||||||
game.getDice().getCredits(), credits);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
Project/notes/CIS 217 Project 1 Winter 2021(5).docx
Normal file
BIN
Project/notes/CIS 217 Project 1 Winter 2021(5).docx
Normal file
Binary file not shown.
81
Project/old-my-dice-game-test.java.old
Normal file
81
Project/old-my-dice-game-test.java.old
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
/*******************************************
|
||||||
|
* The test class for Chuck
|
||||||
|
*
|
||||||
|
* @author Resendiz
|
||||||
|
* @version February 2021
|
||||||
|
******************************************/
|
||||||
|
|
||||||
|
public class MyDiceGameTest {
|
||||||
|
|
||||||
|
/******************************************************
|
||||||
|
* Test initial values of the constructor
|
||||||
|
*****************************************************/
|
||||||
|
@Test
|
||||||
|
public void testConstructor() {
|
||||||
|
GameManager game = new GameManager(6);
|
||||||
|
int credits = game.getDice().getCredits();
|
||||||
|
|
||||||
|
// confirm there is only one copy of Title 1
|
||||||
|
Assert.assertEquals("Game should start with 10 credits",
|
||||||
|
credits, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************
|
||||||
|
* Test Large
|
||||||
|
*****************************************************/
|
||||||
|
@Test
|
||||||
|
public void testLarge() {
|
||||||
|
// confirm large is rolled
|
||||||
|
GameManager game = new GameManager(6);
|
||||||
|
int credits = game.getDice().getCredits();
|
||||||
|
game.getDice().testRoll(new int[]{6, 6, 5});
|
||||||
|
game.getDice().checkLarge();
|
||||||
|
Assert.assertEquals("Dice => (6,6,5): credits should stay the same",
|
||||||
|
game.getDice().getCredits(), credits);
|
||||||
|
|
||||||
|
// confirm large is not rolled
|
||||||
|
GameManager game2 = new GameManager(6);
|
||||||
|
credits = game2.getDice().getCredits();
|
||||||
|
game2.getDice().testRoll(new int[]{1, 2, 3});
|
||||||
|
game2.getDice().checkLarge();
|
||||||
|
Assert.assertEquals("Dice => (1,2,3): credits should decrease by one",
|
||||||
|
game2.getDice().getCredits(), credits - 1);
|
||||||
|
|
||||||
|
// confirm large rolled with three of kind
|
||||||
|
GameManager game3 = new GameManager(6);
|
||||||
|
credits = game3.getDice().getCredits();
|
||||||
|
game3.getDice().testRoll(new int[]{4, 4, 4});
|
||||||
|
game3.getDice().checkLarge();
|
||||||
|
game3.getDice().checkTriplets();
|
||||||
|
Assert.assertEquals("Dice => (4,4,4): credits should increased by one",
|
||||||
|
game3.getDice().getCredits(), credits + 1);
|
||||||
|
|
||||||
|
// confirm large is not rolled with three of kind
|
||||||
|
GameManager game4 = new GameManager(6);
|
||||||
|
credits = game4.getDice().getCredits();
|
||||||
|
game4.getDice().testRoll(new int[]{3, 3, 3});
|
||||||
|
game4.getDice().checkLarge();
|
||||||
|
game4.getDice().checkTriplets();
|
||||||
|
Assert.assertEquals("Dice => (3,3,3): credits should stay the same",
|
||||||
|
game4.getDice().getCredits(), credits);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************
|
||||||
|
* Test Triplets
|
||||||
|
*****************************************************/
|
||||||
|
@Test
|
||||||
|
public void testTriplets() {
|
||||||
|
// confirm triplets is rolled
|
||||||
|
GameManager game = new GameManager(6);
|
||||||
|
int credits = game.getDice().getCredits();
|
||||||
|
game.getDice().testRoll(new int[]{1, 1, 1});
|
||||||
|
game.getDice().checkTriplets();
|
||||||
|
Assert.assertEquals("Dice => (1,1,1): credits should stay the same",
|
||||||
|
game.getDice().getCredits(), credits);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user