rp-scrabble
Simple, terminal-based Scrabble game
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 
62 {
63  return letter;
64 }
65 
74 {
75  return points;
76 }
77 
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 
110 {
111  return string(1, letter);
112 }
113 
122 {
123  return tRack;
124 }
125 
134 {
135  return tBag;
136 }
137 
146 {
147  return tSquare;
148 }
149 
158 {
159  tBag = b;
160  setLoc(0);
161 }
162 
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 
208 {
209  tSquare = s;
210 }
enum_location loc
Definition: bag.cc:13
Definition: bag.h:15
Definition: rack.h:17
Definition: square.h:30
Definition: tile.h:22
int getPoints()
Definition: tile.cc:73
enum_location presentLoc
Definition: tile.h:29
void setSquare(Square *s)
Definition: tile.cc:207
Bag * getBag()
Definition: tile.cc:133
void show()
Definition: tile.cc:49
Rack * getRack()
Definition: tile.cc:121
int points
Definition: tile.h:26
Tile(char l, int p, enum_location p_loc)
Definition: tile.cc:21
Square * getSquare()
Definition: tile.cc:145
void setRack(Rack *r)
Definition: tile.cc:170
std::string getLetterStr()
Definition: tile.cc:109
char letter
Definition: tile.h:25
void setBag(Bag *b)
Definition: tile.cc:157
int getLoc()
Definition: tile.cc:85
void setLoc(int loc)
Definition: tile.cc:183
char getLetter()
Definition: tile.cc:61
enum_location
Definition: tile.h:15
@ BAG
Definition: tile.h:15
@ BOARD
Definition: tile.h:15
@ RACK
Definition: tile.h:15