rp-scrabble
Simple, terminal-based Scrabble game
src
tile.cc
Go to the documentation of this file.
1
4
#include <iostream>
5
#include "
tile.h
"
6
#include "
bag.h
"
7
#include "
square.h
"
8
#include "
rack.h
"
9
10
using namespace
std;
11
21
Tile::Tile
(
char
l,
int
p,
enum_location
p_loc)
22
{
23
letter = l;
24
points = p;
25
presentLoc = p_loc;
26
tBag =
nullptr
;
27
tRack =
nullptr
;
28
tSquare =
nullptr
;
29
}
30
38
Tile::Tile
(
Tile
& source)
39
{
40
letter = source.
letter
;
41
points = source.
points
;
42
presentLoc = source.
presentLoc
;
43
}
44
49
void
Tile::show
()
50
{
51
cout << letter <<
"-"
<< points <<
" "
;
52
}
53
61
char
Tile::getLetter
()
62
{
63
return
letter;
64
}
65
73
int
Tile::getPoints
()
74
{
75
return
points;
76
}
77
85
int
Tile::getLoc
()
86
{
87
switch
(presentLoc) {
88
case
BAG
:
89
return
0;
90
break
;
91
case
RACK
:
92
return
1;
93
break
;
94
case
BOARD
:
95
return
2;
96
break
;
97
default
:
98
return
-1;
99
}
100
}
101
109
string
Tile::getLetterStr
()
110
{
111
return
string(1, letter);
112
}
113
121
Rack
*
Tile::getRack
()
122
{
123
return
tRack;
124
}
125
133
Bag
*
Tile::getBag
()
134
{
135
return
tBag;
136
}
137
145
Square
*
Tile::getSquare
()
146
{
147
return
tSquare;
148
}
149
157
void
Tile::setBag
(
Bag
* b)
158
{
159
tBag = b;
160
setLoc(0);
161
}
162
170
void
Tile::setRack
(
Rack
* r)
171
{
172
tRack = r;
173
setLoc(1);
174
}
175
183
void
Tile::setLoc
(
int
loc
)
184
{
185
switch
(
loc
) {
186
case
0:
187
presentLoc =
BAG
;
188
break
;
189
case
1:
190
presentLoc =
RACK
;
191
break
;
192
case
2:
193
presentLoc =
BOARD
;
194
break
;
195
default
:
196
throw
(
string
(
"Invalid value of type enum_location\n"
));
197
}
198
}
199
207
void
Tile::setSquare
(
Square
* s)
208
{
209
tSquare = s;
210
}
loc
enum_location loc
Definition:
bag.cc:13
bag.h
Bag
Definition:
bag.h:15
Rack
Definition:
rack.h:17
Square
Definition:
square.h:30
Tile
Definition:
tile.h:22
Tile::getPoints
int getPoints()
Definition:
tile.cc:73
Tile::presentLoc
enum_location presentLoc
Definition:
tile.h:29
Tile::setSquare
void setSquare(Square *s)
Definition:
tile.cc:207
Tile::getBag
Bag * getBag()
Definition:
tile.cc:133
Tile::show
void show()
Definition:
tile.cc:49
Tile::getRack
Rack * getRack()
Definition:
tile.cc:121
Tile::points
int points
Definition:
tile.h:26
Tile::Tile
Tile(char l, int p, enum_location p_loc)
Definition:
tile.cc:21
Tile::getSquare
Square * getSquare()
Definition:
tile.cc:145
Tile::setRack
void setRack(Rack *r)
Definition:
tile.cc:170
Tile::getLetterStr
std::string getLetterStr()
Definition:
tile.cc:109
Tile::letter
char letter
Definition:
tile.h:25
Tile::setBag
void setBag(Bag *b)
Definition:
tile.cc:157
Tile::getLoc
int getLoc()
Definition:
tile.cc:85
Tile::setLoc
void setLoc(int loc)
Definition:
tile.cc:183
Tile::getLetter
char getLetter()
Definition:
tile.cc:61
rack.h
square.h
tile.h
enum_location
enum_location
Definition:
tile.h:15
BAG
@ BAG
Definition:
tile.h:15
BOARD
@ BOARD
Definition:
tile.h:15
RACK
@ RACK
Definition:
tile.h:15
Generated by
1.9.1