-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.cpp
More file actions
executable file
·91 lines (80 loc) · 1.58 KB
/
Factory.cpp
File metadata and controls
executable file
·91 lines (80 loc) · 1.58 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
#include "Factory.h"
Factory::Factory()
{
TileType arr[FACTORY_SIZE] = {NOTILE, NOTILE, NOTILE, NOTILE};
fill(arr);
}
Factory::Factory(TileType arr[FACTORY_SIZE])
{
fill(arr);
}
void Factory::fill(TileType arr[FACTORY_SIZE])
{
for (int i = 0; i < FACTORY_SIZE; i++)
{
tiles[i] = arr[i];
}
}
std::vector<TileType> Factory::empty()
{
std::vector<TileType> leftovers;
for (int i = 0; i < FACTORY_SIZE; i++)
{
if (tiles[i] != NOTILE)
{
leftovers.push_back(tiles[i]);
tiles[i] = NOTILE;
}
}
return leftovers;
}
int Factory::draw(TileType tileType)
{
int count = 0;
for (int i = 0; i < FACTORY_SIZE; i++)
{
if (tiles[i] == tileType)
{
count++;
tiles[i] = NOTILE;
}
}
return count;
}
string Factory::toString()
{
string output = "";
for (int i = 0; i < FACTORY_SIZE; i++)
{
output += tiles[i];
output += " ";
}
return output;
}
string Factory::toStringNoSpace()
{
string output = "";
for (int i = 0; i < FACTORY_SIZE; i++)
{
output += tiles[i];
}
return output;
}
bool Factory::isEmpty()
{
bool isEmpty = false;
for (int i = 0; i < FACTORY_SIZE; ++i)
isEmpty |= tiles[i] == NOTILE;
return isEmpty;
}
bool Factory::contains(TileType tileType)
{
bool doesContain = false;
int tileIndex = 0;
while (!doesContain && tileIndex < FACTORY_SIZE)
{
doesContain = tiles[tileIndex] == tileType;
tileIndex++;
}
return doesContain;
}