Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite/dicetotwo #5

Merged
merged 2 commits into from Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import java.awt.*;

Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;
import Model.Player;

abstract public class ChanceCard {
Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import Model.Player;

Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import Model.Player;

Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import Model.Player;

Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import Model.Player;

Expand Down
@@ -1,4 +1,4 @@
package Model.Kort;
package Model.ChanceCards;

import Model.Player;

Expand Down
24 changes: 20 additions & 4 deletions src/main/java/Model/Dice.java
Expand Up @@ -15,20 +15,36 @@
public class Dice {
private int result;
private int sides;
private int amount;


// #----------Constructor----------#
protected Dice() {
this.sides = 6;
this.sides = Global.DICE_SIDES;
this.amount = Global.DICE_AMOUNT;
}

// #--------------Get--------------#
public int getResult(){ // Returner en værdi af terningen.
int sum = 0;
public int setAndGetResult(){ // Returner en værdi af terningen.
/* int sum = 0;
float _random1 = (float) Math.random(); // 0-1 float
int _random2 = (int) (_random1 * sides); // 0-5 integer
result = _random2 + 1; // 1-6 integer

return result;
return result;*/

//int[] diceThrow = new int[amount + 1];
int sum = 0;
for (int i = 0 ; i < amount ; i++){
float _random1 = (float) Math.random(); // 0-1 float
int _random2 = (int) (_random1 * sides); // 0-5 integer
int random = _random2 + 1; // 1-6 integer
//diceThrow[i] = random;
sum += random;
}

this.result = sum;
//diceThrow[diceThrow.length - 1] = sum;
return sum;
}
}
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Chance;
import gui_fields.GUI_Field;
Expand Down
@@ -1,5 +1,6 @@
package Model;
package Model.Fields;

import Model.Player;
import gui_fields.GUI_Field;

/**
Expand Down
@@ -1,6 +1,4 @@
package Model.Felter;

import Model.Field;
package Model.Fields;

import java.awt.*;

Expand Down
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Field;
import gui_fields.GUI_Refuge;
Expand Down
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Field;
import gui_fields.GUI_Jail;
Expand Down
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Field;
import gui_fields.GUI_Street;
Expand Down
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Field;
import gui_fields.GUI_Start;
Expand Down
@@ -1,6 +1,5 @@
package Model.Felter;
package Model.Fields;

import Model.Field;
import Model.Player;
import gui_fields.GUI_Field;
import gui_fields.GUI_Jail;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/Model/Game.java
@@ -1,9 +1,10 @@
package Model;

import Model.Felter.PropertyField;
import Model.Kort.GetPaidCard;
import Model.Kort.ChanceCard;
import Model.Kort.FreePropertyCard;
import Model.Fields.Field;
import Model.Fields.PropertyField;
import Model.ChanceCards.GetPaidCard;
import Model.ChanceCards.ChanceCard;
import Model.ChanceCards.FreePropertyCard;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -70,7 +71,7 @@ public Player playTurn(){
if (!ended) {
int nowIndex = java.util.Arrays.asList(players).indexOf(activePlayer);
int newIndex = (nowIndex + 1) % players.length;
int diceThrow = dice.getResult();
int diceThrow = dice.setAndGetResult();
int[] tempTurn = {diceThrow, nowIndex};

Player _activePlayer = activePlayer;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/Model/GameBoard.java
@@ -1,7 +1,7 @@
package Model;
import Model.Felter.*;
import Model.Kort.ChanceCard;
import Model.Kort.CardFactory;
import Model.Fields.*;
import Model.ChanceCards.ChanceCard;
import Model.ChanceCards.CardFactory;
import gui_fields.*;

import java.awt.*;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/Model/Global.java
Expand Up @@ -6,6 +6,9 @@ public class Global {
static final int ROUND_MONEY = 4000;
static final int JAIL_PRICE = 1000;

public static final int DICE_SIDES = 6;
public static final int DICE_AMOUNT = 2;

public static final int MIN_SPILLERE = 3;
public static final int MAX_SPILLERE = 6;
}
2 changes: 1 addition & 1 deletion src/main/java/Model/Player.java
@@ -1,6 +1,6 @@
package Model;

import Model.Kort.ChanceCard;
import Model.ChanceCards.ChanceCard;

/**
* ------------------------------------------------------------/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/Model/FieldTest.java
@@ -1,6 +1,6 @@
package Model;

import Model.Felter.PropertyField;
import Model.Fields.PropertyField;
import org.junit.jupiter.api.Test;

import java.awt.*;
Expand Down
31 changes: 28 additions & 3 deletions src/test/java/Model/diceTest.java
Expand Up @@ -3,6 +3,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Random;

import static org.junit.jupiter.api.Assertions.assertTrue;

class diceTest {
Expand All @@ -15,8 +17,31 @@ void setUp() {

@Test
void getResultatTest() {
int testRes = testDice1.getResult();
// Tester at terningen kun giver værdier fra 1 til 6
assertTrue(testRes > 0 && testRes < 7);
Random rng = new Random();
int[] dist = new int[11];
int[] slag = new int[11];

// Vi slår 50000 gange
for (int i = 1; i <= 50000; i++) {
int tempSlag = testDice1.setAndGetResult();
slag[tempSlag - 2]++;

// Samtidig med de to terningekast, opretter
// bi et normalfordelt tilfældigt tal i tempGaus arrayer med samme størrelse
double gaus = (rng.nextGaussian() * 3) + 7;
if (gaus < 12 && gaus > 1) {
int tempGaus = (int) gaus;
dist[tempGaus - 1]++;
}
}

// Ud fra vores normalfordeling tjekkes hvert resultat
for (int i = 0; i < slag.length; i++) {
int goal = dist[i];
double pr = (double) slag[i]/50000*100;
int rounded = (int) pr;
System.out.println((i+1) + " : "+ rounded + "%");
assertTrue(slag[i] >= goal-2000 && slag[i] <= goal+2000);
}
}
}
2 changes: 1 addition & 1 deletion src/test/java/stub/DiceStub.java
Expand Up @@ -13,7 +13,7 @@ public DiceStub(int testRes) {
}

@Override
public int getResult() {
public int setAndGetResult() {
return testRes;
}
}