Sfoglia il codice sorgente

pre merge with sim

Jonathan Hinds 6 anni fa
parent
commit
a032213eb6

+ 4
- 1
src/main/java/io/zipcoder/casino/Casino.java Vedi File

@@ -75,11 +75,11 @@ public class Casino {
75 75
 
76 76
                 case 1:
77 77
                     Game yahtzee = new Yahtzee(player);
78
+                    game = yahtzee;
78 79
                     ((Yahtzee) yahtzee).startGame();
79 80
                     int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
80 81
                     ((Yahtzee) yahtzee).setBid(betAmount);
81 82
                     ((Yahtzee) yahtzee).bet(betAmount);
82
-                    game = yahtzee;
83 83
                     yahtzee.startRound();
84 84
                     Printer.printMessage("You scored " + ((Yahtzee) yahtzee).getDicePlayer().getScoreSheet().getTotalScore() + " points.");
85 85
                     ((Yahtzee) yahtzee).payout();
@@ -132,4 +132,7 @@ public class Casino {
132 132
     public Game getGame() {
133 133
         return game;
134 134
     }
135
+    public boolean isRunning() {
136
+        return running;
137
+    }
135 138
 }

+ 3
- 0
src/main/java/io/zipcoder/casino/War.java Vedi File

@@ -131,6 +131,9 @@ public class War extends CardGame implements Gamble, Game {
131 131
                 Printer.printMessage(winner.getPlayer().getName() + " has been rewarded " + tableCards.size() + " cards.");
132 132
                 winner.addDiscard(tableCards);
133 133
                 tableCards = new ArrayList<Card>();
134
+            }else if(input.equals("quit")){
135
+                Printer.printMessage("Thanks for playing chump!");
136
+                console.getScanner().close();
134 137
             } else {
135 138
                 Printer.printMessage("Sorry, I don't understand that command.");
136 139
             }

+ 0
- 11
src/main/java/io/zipcoder/casino/test.java Vedi File

@@ -1,11 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class test {
4
-    public static void main(String[] args){
5
-        Player player = new Player("NickTest", 100);
6
-        Game stud = new Stud(10);
7
-        ((Stud) stud).addPlayers(player);
8
-        ((Stud) stud).addNpc();
9
-        stud.startGame();
10
-    }
11
-}

+ 50
- 0
src/test/java/io/zipcoder/casino/CasinoTest.java Vedi File

@@ -4,7 +4,57 @@ package io.zipcoder.casino;
4 4
 import org.junit.Assert;
5 5
 import org.junit.Test;
6 6
 
7
+import java.io.ByteArrayInputStream;
8
+import java.util.NoSuchElementException;
9
+import java.util.Scanner;
10
+
7 11
 public class CasinoTest {
8 12
 
13
+    @Test
14
+    public void testYahtzee(){
15
+        String test = "1";
16
+
17
+        Casino casino = new Casino();
18
+        Console console = new Console();
19
+
20
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(test.getBytes())));
21
+        try {
22
+            casino.chooseGame();
23
+        }catch(NoSuchElementException e){
24
+
25
+        }
26
+
27
+        Assert.assertTrue(casino.getGame() instanceof Yahtzee);
28
+    }
29
+
30
+    @Test
31
+    public void testGetStudPlayer(){
32
+
33
+        int num = 0;
34
+        String test = "2";
35
+        Casino casino = new Casino();
36
+        Stud stud = new Stud(10);
37
+
38
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(test.getBytes())));
39
+        try {
40
+            num = casino.getStudPlayers();
41
+        }catch(NoSuchElementException e){
42
+
43
+        }
44
+        System.out.println(num);
45
+        Assert.assertTrue(num == 2);
46
+    }
47
+
48
+    @Test
49
+    public void testWar(){
50
+        Casino casino = new Casino();
51
+        String input = "jon \n 100 \n 2 \n flip";
52
+
53
+        casino.getConsole().setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
54
+        try {
55
+            casino.getConsole().createAccount();
56
+        }catch(NoSuchElementException e){
9 57
 
58
+        }
59
+    }
10 60
 }

+ 3
- 0
src/test/java/io/zipcoder/casino/StudTest.java Vedi File

@@ -4,7 +4,10 @@ import org.junit.Assert;
4 4
 import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 
7
+import java.io.ByteArrayInputStream;
7 8
 import java.util.ArrayList;
9
+import java.util.NoSuchElementException;
10
+import java.util.Scanner;
8 11
 
9 12
 public class StudTest {
10 13