-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoundationClass.java
110 lines (99 loc) · 2.49 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Author: Matthew Leung
// ICS4U1 Final Project
// Penguin Solitaire
import java.awt.*; // Java's Abstract Windowing Toolkit package - includes class Color
import java.util.*; // Vector class is in the 'util' package
public class FoundationClass extends DeckClass
{
public FoundationClass ()
{
}
public boolean canAdd (PileClass p) //checks if a pile can be added to the foundation deck
{
if (super.canAdd (p) == true)
{
final CardClass newCard = p.getCard (0);
if (getDeckSize () > 0)
{
final int s = getCard (0).getSuit ();
if (newCard.getSuit () == s)
{
if (getCard (0).getValueInt () != 14) //if the top card on the foundation deck is not an Ace
{
if (newCard.getValueInt () == getCard (0).getValueInt () + 1)
{
return true;
}
}
else //if the top card on the foundation deck is an Ace
{
if (newCard.getValueInt () == 2) //card that is added must be a 2
{
return true;
}
}
}
}
else //if foundation deck is empty, a card with the same rank as the beak must be put in
{
if (newCard.getValueInt () == Globals.beak)
{
return true;
}
}
}
return false;
}
public boolean complete () //checks if all the cards have been moved into this foundation deck (whether or not this foundation has been completed)
{
if (getDeckSize () == 13)
{
return true;
}
else
{
return false;
}
}
///////////////////////////////////////////////////////////////////////////////
private String getValueByInt (int iValue) //used by draw (changes a numeric rank to string, ex. 14 becomes "A")
{
String value = "";
if (iValue >= 2 && iValue <= 10)
{
value = Integer.toString (iValue);
}
else if (iValue == 11)
{
value = "J";
}
else if (iValue == 12)
{
value = "Q";
}
else if (iValue == 13)
{
value = "K";
}
else if (iValue == 14)
{
value = "A";
}
else if (iValue < 2 || iValue > 14)
{
value = "Error"; //error message
}
return value;
}
public void draw (Graphics g)
{
super.draw (g);
if (getDeckSize () == 0)
{
Font f1 = new Font ("SanSerif", Font.PLAIN, getHeight () / 5);
g.setColor (Color.white);
g.setFont (f1);
g.drawString (getValueByInt (Globals.beak), getCenterX () - getWidth () / 2 + getWidth () / 25, getCenterY () - getHeight () / 2 + getHeight () / 5);
}
}
}