- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTile.java
More file actions
Latest commit
executable file
·103 lines (93 loc) · 2.63 KB
/
Copy pathTile.java
File metadata and controls
executable file
·103 lines (93 loc) · 2.63 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
98
99
100
101
102
importjava.util.Random;
importjava.util.ArrayList;
/**
* A tile in the game of Concentration, i
* Tiles are arranged on an n x m board, represented in a 2-dim array
*
* In this version, a tile contains a card, similar to a playing card. Cards
* have string values for their "face up" and "face down" state. Each tile
* is shown face up or face down on the board.
*
* A tile can also have a "cardMatched", indicateing the card has been matched
* with another card and has been removed from the board. We use this value
* instead of a blank value or a missing tile because it helps to represent
* the m x n game board when tiles would otherwise be blank or missing.
*
*/
publicclassTile
{
privatebooleanfaceUp;
privatebooleanmatched;
privateStringcardFace;
privateStringcardBack = "_____";
privateStringcardMatched = " * ";
/**
* Construct a tile with a string value. The default state
* of a tile is unmatched and face down on the board.
*
* @param word the word that represents the card face
*/
publicTile(Stringword)
{
cardFace = word;
}
/**
* Return the value of the tile in its face up state
*
* @return faceUp
*/
publicStringgetFace() {
returncardFace;
}
/**
* Return the value of the tile in its face down state
*
* @return the face (as a String value)
*/
publicStringgetBack() {
returncardBack;
}
/**
* Set the card to either a face up or face down state
*
* @param b set to true to show the card face up, set to false to show face down
*/
publicvoidfaceUp(booleanb)
{
faceUp = b;
}
/**
* Determine if the card is currently face up
*
* @return true if the card is currently in the faceUp state, false otherwise
*/
publicbooleanisFaceUp() {
returnfaceUp;
}
/**
* A matching pair of cards has been found, set matched to true
* and change the way the card is shown
*/
publicvoidfoundMatch() {
matched = true;
cardFace = cardMatched;
cardBack = cardMatched;
}
/**
* Determine if this tile has been matched
*
* @return true of the card was previously matched, false otherwise
*/
publicbooleanmatched() {
returnmatched;
}
@Override
publicbooleanequals(Objectobj) {
if (objinstanceofTile) {
TileotherTile = (Tile)obj;
returncardFace.equals(otherTile.getFace());
} else {
returnfalse;
}
}
}