-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.java
65 lines (62 loc) · 1.36 KB
/
Game.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public class Game
{
private Player playerOne = new Player(1);
private Player playerTwo = new Player(2);
private int battleCount = 0;
private int warCount = 0;
private int doubleWarCount = 0;
private boolean[] warArray;
public void play()
{
while (!playerOne.hasWon() && !playerTwo.hasWon())
{
Card cardPlayerOne = playerOne.flip();
Card cardPlayerTwo = playerTwo.flip();
if (cardPlayerOne.numValue> cardPlayerTwo.numValue)
{
playerOne.collect(cardPlayerTwo, cardPlayerOne);
battleCount++;
}
else if (cardPlayerOne.numValue< cardPlayerTwo.numValue)
{
playerTwo.collect(cardPlayerOne, cardPlayerTwo);
battleCount++;
}
else if (playerOne.playerCards.size()!=0 && playerTwo.playerCards.size()!=0)
{
while (!playerOne.hasWon() && !playerTwo.hasWon())
{
warArray = playerOne.war(playerOne, playerTwo);
if (warArray[1] == false)
{
warCount++;
break;
}
else
{
doubleWarCount++;
continue;
}
}
if (warArray[0] == true)
playerOne.collect(cardPlayerOne, cardPlayerTwo);
else if (warArray[0] == false)
playerTwo.collect(cardPlayerOne, cardPlayerTwo);
}
else
break;
}
}
public int getBattleCount()
{
return battleCount;
}
public int getWarCount()
{
return warCount;
}
public int getDoubleWarCount()
{
return doubleWarCount;
}
}