瀏覽代碼

Merge branch 'dev' of https://git.zipcode.rocks/woat/ZCW-OOP-Casino into console/ahmad

Ahmad Rusdi 6 年之前
父節點
當前提交
70666a53a7

二進制
.DS_Store 查看文件


+ 1
- 0
.gitignore 查看文件

@@ -1,6 +1,7 @@
1 1
 .metadata
2 2
 bin/
3 3
 tmp/
4
+.DS_Store
4 5
 *.tmp
5 6
 *.bak
6 7
 *.swp

+ 0
- 0
NEW_FEATURE 查看文件


+ 0
- 0
newfile 查看文件


二進制
src/.DS_Store 查看文件


二進制
src/main/.DS_Store 查看文件


二進制
src/main/java/.DS_Store 查看文件


二進制
src/main/java/io/.DS_Store 查看文件


二進制
src/main/java/io/zipcoder/.DS_Store 查看文件


+ 38
- 0
src/main/java/io/zipcoder/casino/Dice.java 查看文件

@@ -0,0 +1,38 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.Random;
4
+
5
+    public class Dice
6
+    {
7
+        private int dice;
8
+        private Random randomGenerator;
9
+
10
+        public Dice(int numberOfDice)
11
+        {
12
+            dice = numberOfDice;
13
+        }
14
+
15
+        public int getSum()
16
+        {
17
+            int sumOfTosses = 0;
18
+            for (int i=0; i<dice; i++)
19
+            {
20
+                randomGenerator = new Random();
21
+                int resultOfToss = randomGenerator.nextInt(6)+1;
22
+                sumOfTosses += resultOfToss;
23
+            }
24
+            return sumOfTosses;
25
+        }
26
+
27
+        public int[] getEach()
28
+        {
29
+            int[] tosses = new int[dice];
30
+            for (int i=0; i<dice; i++)
31
+            {
32
+                randomGenerator = new Random();
33
+                tosses[i] = randomGenerator.nextInt(6)+1;
34
+            }
35
+            return tosses;
36
+        }
37
+    }
38
+

+ 15
- 0
src/main/java/io/zipcoder/casino/Gamble.java 查看文件

@@ -0,0 +1,15 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Gamble {
4
+
5
+
6
+
7
+     int currentBet;
8
+
9
+     void bet(int);
10
+     void winBet(Player);
11
+     void loseBet(Player);
12
+
13
+
14
+
15
+}

+ 14
- 0
src/main/java/io/zipcoder/casino/Game.java 查看文件

@@ -0,0 +1,14 @@
1
+package io.zipcoder.casino;
2
+
3
+public interface Game {
4
+   // variable of Player type
5
+    Player player;
6
+
7
+    void startGame();
8
+
9
+    void endGame();
10
+
11
+    void declareWinner();
12
+
13
+
14
+}

+ 11
- 0
src/main/java/io/zipcoder/casino/Main.java 查看文件

@@ -0,0 +1,11 @@
1
+package io.zipcoder.casino;
2
+
3
+public class Main {
4
+    public static void main(String[] args){
5
+        Casino casino =  new Casino();
6
+        casino.start();
7
+
8
+    }
9
+
10
+
11
+}

+ 40
- 0
src/test/java/io/zipcoder/casino/DiceTest.java 查看文件

@@ -0,0 +1,40 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class DiceTest {
8
+
9
+    @Test
10
+    public void getSum1(){
11
+        Dice dice = new Dice(2);
12
+        int expected = 6;
13
+        int actual = dice.getSum();
14
+        Assert.assertEquals(expected, actual, 6);
15
+    }
16
+
17
+    @Test
18
+    public void getSum2(){
19
+        Dice dice = new Dice(5);
20
+        int expected = 13;
21
+        int actual = dice.getSum();
22
+        Assert.assertEquals(expected, actual, 12);
23
+    }
24
+
25
+    @Test
26
+    public void getEach1(){
27
+        Dice dice = new Dice(2);
28
+        int expected = 3;
29
+        int actual = dice.getEach()[1];
30
+        Assert.assertEquals(expected, actual, 3);
31
+    }
32
+
33
+    @Test
34
+    public void getEach2(){
35
+        Dice dice = new Dice(6);
36
+        int expected = 3;
37
+        int actual = dice.getEach()[3];
38
+        Assert.assertEquals(expected, actual, 3);
39
+    }
40
+}