-
Notifications
You must be signed in to change notification settings - Fork 0
/
Eights.java
146 lines (126 loc) · 4.21 KB
/
Eights.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
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
import java.util.Scanner;
public class Eights
{
private Player one;
private Player two;
private Hand drawPile;
private Hand discardPile;
private Scanner in;
public Eights(String p1, String p2)
{
//Remember the current object(this) in use now is the Eights object which
//has these attributes!^
Deck2 deck = new Deck2("Deck");
deck.shuffle(); //??What's the point of even making a deck!!???
one = new Player(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 = new Player(p2);
deck.deal(two.getHand(), 5);
discardPile = new Hand("Discard Pile");
deck.deal(discardPile, 1);
drawPile = new Hand("Draw Pile");
deck.dealAll(drawPile);
in = new Scanner(System.in);
}
public static void main(String[] args)
{
System.out.println("Howdy, let's play 8's!");
//Eights game;
Scanner inny = new Scanner(System.in);
System.out.println("What's your name?");
String p1 = inny.nextLine();
System.out.println("Whats your friends name?");
String p2 = inny.nextLine();
//game = new Eights(p1, p2);
Eights game = new Eights(p1, p2);
game.playGame();
}
public boolean isDone()
{
/*if(p1.hand.size() == 0)
{
System.out.println("Ya " + p1.name + " won!");
p1.score();
}*/
return one.getHand().isEmpty() || two.getHand().isEmpty();
}
public void reshuffle()
{
Card prev = discardPile.removeCard();
discardPile.dealAll(drawPile);
discardPile.addCard(prev);
drawPile.shuffle();
}
public Card drawCard()
{
if(drawPile.isEmpty())
reshuffle();
return drawPile.removeCard();
}
public Player nextPlayer(Player current)
{
if(current == one)
return two;
else
return one;
}
public void displayState()
{
//???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();
}
public void takeTurn(Player player)
{
Card prev = 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???????
Card next = 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();
}
public void playGame()
{
//???WHAT IS THIS VARIABLES PURPOSE????????????? Why not just use the 2
//Player variables that we already had???????
Player player = 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!");
}*/
}