- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
Latest commit
97 lines (87 loc) · 2.35 KB
/
Copy pathPlayer.java
File metadata and controls
97 lines (87 loc) · 2.35 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
publicclassPlayer
{
privateStringname;
privateHandhand;
publicPlayer(Stringname)
{
//Here we have to use this to distinguish between the
//instance variable and the parameter with the same name
this.name = name;
this.hand = newHand(name);
}
publicStringgetName()
{
returnname;
}
publicHandgetHand()
{
returnhand;
}
publicCardplay(Eightseights, Cardprev)
{
//"prev" is the top card of the discard pile
//BOOK:play invokes two helper methods: searchForMatch and
//drawForMatch. Since we have not written them yet, this is
//an example of "top-down development".
Cardcard = searchForMatch(prev);//='s null if you check all the cards in your hand and nothing matches which then executes the inside
if(card == null)
card = drawForMatch(eights, prev);
returncard;
}
publicCardsearchForMatch(Cardprev)
{
for(inti = 0; i < hand.size(); i++)
{
Cardcard = hand.getCard(i);
//(50)If the card is found then we remove it BUT the current object(this)
//in use is player BUT once we remove it from player the card is removed
//from the Eights one/two attribute as well HOW?????
if(cardMatches(card, prev))
returnhand.removeCard(i);
}
returnnull;
}
publicCarddrawForMatch(Eightseights, Cardprev)
{
while(true)
{ //?????HOW IS THIS ALLOWED??? eights.two
Cardcard = eights.drawCard();
System.out.println(name + " draws " + card);
if(cardMatches(card, prev))
returncard;
hand.addCard(card);
}
}
publicstaticbooleancardMatches(Cardcard1, Cardcard2)
{
returncard1.getSuit() == card2.getSuit()
|| card1.getRank() == card2.getRank()
|| card1.getRank() == 8;
}
publicintscore()
{
intsum = 0;
for(inti = 0; i < hand.size(); i++)
{
intrankPoints = hand.getCard(i).getRank() % 14;
if(rankPoints <=13 && rankPoints >= 11)
{
sum += 10;
}
//rankPoints = hand.getCard(i).getRank() % 10;
if(rankPoints < 11)
sum += rankPoints;
}
returnsum;
}
//??Isn't this just a wrapper method??? So in Eights can't we just
//call the display method in Hand from there and make it easier!???
publicvoiddisplay()
{
hand.display();
}
publicvoiddisplayScore()
{
System.out.println(name + " had " + score() + " points!");
}
}