-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
73 lines (58 loc) · 1.3 KB
/
Copy pathmodel.cpp
File metadata and controls
73 lines (58 loc) · 1.3 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
#include "model.h"
const int width = 3, height = 3;
Model::Model(QObject *parent) :
QObject(parent),
m_gameField(QList<Cell*>()),
m_gamer(State::X),
m_victoryLine(Line::NotLine)
{
for (int i = 0; i < width * height; ++i)
m_gameField << new Cell(this);
}
const QList<Cell *> &Model::gameField() const{
return m_gameField;
}
const QList<QObject *> Model::gameFieldProperty() const{
auto res = QList<QObject*>();
foreach (auto var, m_gameField)
res << var;
return res;
}
State::StateEnum Model::gamer() const{
return m_gamer;
}
void Model::setGamer(State::StateEnum gamer){
m_gamer = gamer;
}
bool Model::hasError(){
return false;
}
QString Model::errorText(){
return "";
}
QString Model::victoryLine() const{
return Line::m().valueToKey(m_victoryLine);
}
void Model::setVictoryLine(Line::LineEnum value){
if(m_victoryLine != value){
m_victoryLine = value;
emit victoryLineChange();
}
}
bool Model::gameIsActive() const{
return m_victoryLine == Line::NotLine;
}
Cell::Cell(QObject *parent) :
QObject(parent),
m_value(State::Empty)
{
}
State::StateEnum Cell::value() const{
return m_value;
}
void Cell::setValue(State::StateEnum v){
if(m_value != v){
m_value = v;
emit valueChange();
}
}