-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCard.java
153 lines (116 loc) · 3.76 KB
/
Card.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
147
148
149
150
151
152
153
/**
* This class represent a Card in UNO game.
*
*
* @author Mohammad Mahdi Malmasi
* @version 0.1.7
*/
public class Card
{
/* Feilds */
// the score of the card
private int cardScore;
// the color of the card
private Color cardColor;
// the code of the card. (UNO game has 108 cards)
private int cardCode;
/* Constructor */
/**
* Creat a new card with given details
*
* @param cardScore : the score of the card
* @param cardColor : the color of the card
* @param cardCode : the code of the card
*/
public Card(int cardScore, Color cardColor, int cardCode)
{
this.cardScore = cardScore;
this.cardColor = cardColor;
this.cardCode = cardCode;
}
/* Methods */
// * getter methods *
/**
* @return the score of the card
*/
public int getCardScore()
{
return cardScore;
}
/**
* @return the color of the card
*/
public Color getCardColor()
{
return cardColor;
}
/**
* @return the code of the card
*/
public int getCardCode()
{
return cardCode;
}
/**
* This method check the equality between this card and the geven object
* This method check the code number of the cards
*
* @param obj : the given object to check the equality
* @return {@code true} if and only if the given card has a same code number with this card
*/
@Override
public boolean equals(Object obj)
{
// check the pointers
if (obj == this)
return true;
// check the class
if (!(obj instanceof Card))
return false;
Card card = (Card) obj;
return cardCode == card.cardCode;
}
/**
* This method return the {@code String} of the behind the gmae cards
*
* @param lineNumber : the number of the card line
* @return a {@code String} of the given card line
*
* @see cardsOutput.txt, (in project repository)
*/
public String toString(int lineNumber)
{
switch (lineNumber)
{
// the top and bottom of the card
case 1:
case 7:
return Color.getColorCodeString(Color.WHITE) + "•~~~~~~~•" +
Color.getColorCodeString(Color.RESET);
case 2:
return Color.getColorCodeString(Color.WHITE) + "|◉ " +
Color.getColorCodeString(Color.GREEN) + "♢ " +
Color.getColorCodeString(Color.WHITE) + "◎|" +
Color.getColorCodeString(Color.RESET);
case 3:
case 5:
return Color.getColorCodeString(Color.WHITE) + "| " +
Color.getColorCodeString(Color.GREEN) + "♢♢♢ " +
Color.getColorCodeString(Color.WHITE) + "|" +
Color.getColorCodeString(Color.RESET);
case 4:
return Color.getColorCodeString(Color.WHITE) + "| " +
Color.getColorCodeString(Color.RED) + "U " +
Color.getColorCodeString(Color.YELLOW) + "N " +
Color.getColorCodeString(Color.BLUE) + "O " +
Color.getColorCodeString(Color.WHITE) + "|" +
Color.getColorCodeString(Color.RESET);
case 6:
return Color.getColorCodeString(Color.WHITE) + "|◎ " +
Color.getColorCodeString(Color.GREEN) + "♢ " +
Color.getColorCodeString(Color.WHITE) + "◉|" +
Color.getColorCodeString(Color.RESET);
}
return null;
}
}