-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathStone.cpp
82 lines (72 loc) · 1.44 KB
/
Stone.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
#include "Stone.h"
#include <QDebug>
Stone::Stone()
{
}
Stone::~Stone()
{
}
QString Stone::name()
{
switch(this->_type)
{
case CHE:
return QStringLiteral("车");
case MA:
return QStringLiteral("马");
case PAO:
return QStringLiteral("炮");
case BING:
return QStringLiteral("兵");
case JIANG:
return QStringLiteral("将");
case SHI:
return QStringLiteral("士");
case XIANG:
return QStringLiteral("相");
}
return QStringLiteral("错误");
}
void Stone::init(int id)
{
struct {
int row, col;
Stone::TYPE type;
} pos[16] = {
{0, 0, Stone::CHE},
{0, 1, Stone::MA},
{0, 2, Stone::XIANG},
{0, 3, Stone::SHI},
{0, 4, Stone::JIANG},
{0, 5, Stone::SHI},
{0, 6, Stone::XIANG},
{0, 7, Stone::MA},
{0, 8, Stone::CHE},
{2, 1, Stone::PAO},
{2, 7, Stone::PAO},
{3, 0, Stone::BING},
{3, 2, Stone::BING},
{3, 4, Stone::BING},
{3, 6, Stone::BING},
{3, 8, Stone::BING},
};
if(id < 16)
{
this->_col = pos[id].col;
this->_row = pos[id].row;
this->_type = pos[id].type;
}
else
{
this->_col = 8-pos[id-16].col;
this->_row = 9-pos[id-16].row;
this->_type = pos[id-16].type;
}
this->_dead = false;
this->_red = id<16;
}
void Stone::rotate()
{
this->_col = 8-this->_col;
this->_row = 9-this->_row;
}