-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGame.java
More file actions
121 lines (84 loc) · 2.52 KB
/
Copy pathGame.java
File metadata and controls
121 lines (84 loc) · 2.52 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* author alex torres
* this is the games class that will run the game. this class will create the deck, player, and hand. this class
* will also will run each step of the game
*/
public class Game {
//deck of cards
private Deck deck;
//hands for players
private Hand playerHand;
private Hand computerHand;
//player and computer
private Player p1;
ComputerPlayer c1;
//stores index of combo box from gui
private int playerChoosenIndex;
//getter and setter for playerChoosenIndex
public int getPlayerChoosenIndex() {
return playerChoosenIndex;
}
public void setPlayerChoosenIndex(int playerChoosenIndex) {
this.playerChoosenIndex = playerChoosenIndex;
}
//this method will set up a game
public void gameSetup() {
//create deck
deck = CreateDeck.fullDeck();
//shuffle deck
deck.shuffleDeck();
//create hands
//hand for player. half the deck is delt
playerHand = new Hand( deck.dealFirstHalf());
//hand for computer player. second half is delt
computerHand = new Hand( deck.dealSecondhalf());
//add hand to players
//player
p1 = new Player( playerHand);
//computer
c1 = new ComputerPlayer( computerHand);
}
//this method is the player turn. this method will remove a card from the computer hand based on an index
public void playerTurn() {
//removing card from index given from combo box action listener
Card tempCard = c1.removeCard(playerChoosenIndex);
//put card into player deck
p1.getHand().addCard(tempCard);
//check for pairs
p1.removePairs();
//toString for test run
System.out.println( p1.toString() );
}
//this method is the computer turn and will simulate the computer playing
public void computerTurn() {
//random generated int
int generatedInt = c1.GenerateRandomInt();
//remove card from player deck
Card tempCard = p1.removeCard(generatedInt);
//add card to computer hand
c1.addCard(tempCard);
//check for pairs
c1.removePairs();
}
//this method checks if the game is over
public boolean isGameDone () {
if (p1.getHand().isHandEmpty()) {
System.out.println("congradulations, you won");
return true;
}
if (c1.getHand().isHandEmpty()) {
System.out.println("You lost");
return true;
}
return false;
}
//method that will check for pairs at the beginning of the game
public void checkingForPairs () {
p1.removePairs();
c1.removePairs();
}
//method that returns the size of the hand in c1
public int getC1Size() {
return c1.getHandSize();
}
}