-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.cpp
More file actions
executable file
·67 lines (58 loc) · 1.19 KB
/
Line.cpp
File metadata and controls
executable file
·67 lines (58 loc) · 1.19 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
#include "Line.h"
Line::Line(int maxSize) : Line(maxSize, 0, NOTILE)
{
}
Line::Line(int maxSize, int numTiles, TileType tileType) : maxSize(maxSize), numTiles(numTiles), tileType(tileType)
{
}
int Line::addTiles(int quantity, TileType tileType)
{
int overflow = 0;
if (canAddTiles(tileType))
{
this->tileType = tileType;
numTiles += quantity;
if (numTiles >= maxSize)
{
overflow = numTiles - maxSize;
numTiles = maxSize;
}
}
return overflow;
}
void Line::removeTiles()
{
numTiles = 0;
tileType = NOTILE;
}
TileType Line::getTileType()
{
return tileType;
}
int Line::getNumTiles()
{
return numTiles;
}
int Line::getMaxSize()
{
return maxSize;
}
std::string Line::toString()
{
std::string result = "";
for (int i = 0; i < maxSize - numTiles; ++i)
{
result += char(NOTILE);
}
for (int i = 0; i < numTiles; ++i)
{
result += char(tileType);
}
return result;
}
bool Line::canAddTiles(TileType tileType)
{
return tileType != FIRSTPLAYER && tileType != NOTILE
&& (this->tileType == NOTILE || this->tileType == tileType)
&& numTiles < maxSize;
}