-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoundationClass.java
86 lines (72 loc) · 1.72 KB
/
FoundationClass.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
// The "FoundationClass" class.
// A deck that contains only 1 suit ascending from Ace to King.
import java.util.*;
import java.awt.*;
public class FoundationClass extends DeckClass
{
int topVal = 0; //Indicates what value the topmost card represents
int suitContained;
FoundationClass ()
{
}
FoundationClass (int suitSelection)
{
suitContained = suitSelection;
}
FoundationClass (String sizeNew, int suitSelection)
{
super.setSize(sizeNew);
suitContained = suitSelection;
}
public boolean addCard (CardClass cardToAdd, int Pos)
{
if ((cardToAdd.getSuit () == suitContained) && (cardToAdd.getValue () == (topVal + 1))) //Checks to see if the added card is the right suit and value.
{
topVal++;
return super.addCard (cardToAdd, -1);
}
else
{
return false;
}
}
public CardClass dealCard (int Pos)
{
topVal--;
return super.dealCard (-1);
}
public void removeCard (int Pos)
{
topVal--;
super.removeCard(Pos);
}
public void draw (Graphics g)
{
super.draw(g);
//draws the respected suit indicating which ace the foundation accepts if empty
if (suitContained == 1)
{
setColour (Color.black);
SpadeClass S1 = new SpadeClass (x, y, width / 3, colour);
S1.draw (g);
}
else if (suitContained == 2)
{
setColour (Color.red);
HeartClass H1 = new HeartClass (x, y, width / 3, colour);
H1.draw (g);
}
else if (suitContained == 3)
{
setColour (Color.black);
ClubClass C1 = new ClubClass (x, y, width / 3, colour);
C1.draw (g);
}
else if (suitContained == 4)
{
setColour (Color.red);
DiamondClass D1 = new DiamondClass (x, y, width / 3, colour);
D1.draw (g);
}
}
}