-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrabblefunc.cpp
97 lines (81 loc) · 1.8 KB
/
scrabblefunc.cpp
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
#include "scrabblefunc.h"
ScrabbleFunc::ScrabbleFunc(int count) : countOfGamers(count), gamer(0), field(), newField(field),
scores(new int[countOfGamers]), newWord("")
{
for (int i = 0; i < countOfGamers; i++)
scores[i] = 0;
}
ScrabbleFunc::~ScrabbleFunc()
{
delete scores;
}
void ScrabbleFunc::setCell(int x, int y, char c)
{
newField.setCell(x, y, c);
}
char ScrabbleFunc::getCell(int x, int y)
{
return newField.getCell(x, y);
}
void ScrabbleFunc::updateField()
{
field = newField;
}
void ScrabbleFunc::cancelFieldChange()
{
newField = field;
}
void ScrabbleFunc::updateScore(int score)
{
scores[gamer] += score;
}
int ScrabbleFunc::getScore(int numberOfGamer)
{
if (numberOfGamer >= 0 && numberOfGamer < countOfGamers)
return scores[numberOfGamer];
return 0;
}
int ScrabbleFunc::getCount()
{
return countOfGamers;
}
int ScrabbleFunc::getGamer()
{
return gamer;
}
bool ScrabbleFunc::endOfGame()
{
for (int i = 0; i < Size; i++)
for (int j = 0; j < Size; j++)
if (getOldCell(i, j) == '\0')
return false;
return true;
}
Field *ScrabbleFunc::getField()
{
return &field;
}
char ScrabbleFunc::getOldCell(int x, int y)
{
return field.getCell(x, y);
}
void ScrabbleFunc::changeGamer()
{
gamer++;
gamer %= countOfGamers;
}
bool ScrabbleFunc::isIsolated(int x, int y)
{
int moveX[4] = {1, -1, 0, 0};
int moveY[4] = {0, 0, 1, -1};
for (int i = 0; i < 4; i++)
if (x + moveX[i] >= 0 && x + moveX[i] < Size
&& y + moveY[i] >= 0 && y + moveY[i] < Size
&& field.getCell(x + moveX[i], y + moveY[i]) != '!' && field.getCell(x + moveX[i], y + moveY[i]) != '\0')
return false;
return true;
}
bool ScrabbleFunc::areNeigbors(int x1, int y1, int x2, int y2)
{
return (abs(x1 - x2) + abs(y1 - y2) == 1);
}