/
Stone.cpp
83 lines (72 loc) · 1.37 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
83
// Stone.cpp
#include "Stone.h"
#include <QDebug>
Stone::Stone()
{
}
Stone::~Stone()
{
}
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},
};
//_id = id;
_dead = false;
_red = id < 16;
if (id < 16) { // 上方的棋子
this->_row = pos[id].row;
this->_col = pos[id].col;
this->_type = pos[id].type;
}
else { // 下方的棋子
this->_row = 9 - pos[id - 16].row;
this->_col = 8 - pos[id - 16].col;
this->_type = pos[id - 16].type;
}
}
QString Stone::name()
{
switch (this->_type)
{
case CHE:
return "车";
case MA:
return "马";
case PAO:
return "炮";
case BING:
return "兵";
case JIANG:
return "将";
case SHI:
return "士";
case XIANG:
return "相";
}
return "错误";
}
void Stone::rotate()
{
this->_col = 8 - this->_col;
this->_row = 9 - this->_row;
}