- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEights.java
More file actions
Latest commit
146 lines (126 loc) · 4.21 KB
/
Copy pathEights.java
File metadata and controls
146 lines (126 loc) · 4.21 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
importjava.util.Scanner;
publicclassEights
{
privatePlayerone;
privatePlayertwo;
privateHanddrawPile;
privateHanddiscardPile;
privateScannerin;
publicEights(Stringp1, Stringp2)
{
//Remember the current object(this) in use now is the Eights object which
//has these attributes!^
Deck2deck = newDeck2("Deck");
deck.shuffle(); //??What's the point of even making a deck!!???
one = newPlayer(p1);
//?Why doesn't one.hand just work???? Is it because if we say one.hand then
//the type is a Player object so it returns as a Player object and deal()
//needs either Hand, Deck2, or a CardCollection object???? or is it that we
//just can't access the attributes of a Player object from here because they
//are private???? if yes to the last one is a getMethod the only way????
deck.deal(one.getHand(), 5);
two = newPlayer(p2);
deck.deal(two.getHand(), 5);
discardPile = newHand("Discard Pile");
deck.deal(discardPile, 1);
drawPile = newHand("Draw Pile");
deck.dealAll(drawPile);
in = newScanner(System.in);
}
publicstaticvoidmain(String[] args)
{
System.out.println("Howdy, let's play 8's!");
//Eights game;
Scannerinny = newScanner(System.in);
System.out.println("What's your name?");
Stringp1 = inny.nextLine();
System.out.println("Whats your friends name?");
Stringp2 = inny.nextLine();
//game = new Eights(p1, p2);
Eightsgame = newEights(p1, p2);
game.playGame();
}
publicbooleanisDone()
{
/*if(p1.hand.size() == 0)
{
System.out.println("Ya " + p1.name + " won!");
p1.score();
}*/
returnone.getHand().isEmpty() || two.getHand().isEmpty();
}
publicvoidreshuffle()
{
Cardprev = discardPile.removeCard();
discardPile.dealAll(drawPile);
discardPile.addCard(prev);
drawPile.shuffle();
}
publicCarddrawCard()
{
if(drawPile.isEmpty())
reshuffle();
returndrawPile.removeCard();
}
publicPlayernextPlayer(Playercurrent)
{
if(current == one)
returntwo;
else
returnone;
}
publicvoiddisplayState()
{
//???Why not just do one.hand.display(); and if this doesn't work why not,
//because we never technically access it we just use the attribute to invoke
//that attributes own objects/class's method
//or one.getHand().display();
//??Point is I feel like adding the display method in Player, since it's
//just a wrapper method, is pointless either by a slowing down of computation
//or just bad style since here we can't tell that it's just a wrapper method
//to use another class's method!!!??? How do we just invoke the Hand's
//display method directly(from here)!!!!????????????????????????????????????
one.display();
two.display();
discardPile.display();
System.out.println("Draw Pile:");
System.out.println(drawPile.size() + " cards");
in.nextLine();
}
publicvoidtakeTurn(Playerplayer)
{
Cardprev = discardPile.lastCard();
//???We passed argument this which is the eights object not the player, yet
//in the class Player this is the player variable??????
//ANS:Yes this is right
//?????BUT what is the purpose in doing this???????
Cardnext = player.play(this, prev);
//(51)??takes from player or one???? or neither????
//(52)Which discardPile is it being added to, player or one??? AND if it's
//added to only 1 of those options WHY because when we removed it, both
//variables had the card removed????????????????????????????????????????
discardPile.addCard(next);
System.out.println(player.getName() + " plays " + next);
System.out.println();
}
publicvoidplayGame()
{
//???WHAT IS THIS VARIABLES PURPOSE????????????? Why not just use the 2
//Player variables that we already had???????
Playerplayer = one;
while(!isDone())
{
displayState();
takeTurn(player);
player = nextPlayer(player);
}
one.displayScore();
two.displayScore();
}
//?Why cant this be here????? Cause score method is in Player so
//it can't be seen from here cause it's not static???????
/*public void displayScore()
{
System.out.println(name + " had " + score() + " points!");
}*/
}