-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStone.cpp
More file actions
102 lines (91 loc) · 1.75 KB
/
Copy pathStone.cpp
File metadata and controls
102 lines (91 loc) · 1.75 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
92
93
94
95
96
97
98
99
100
101
102
#include "Stone.h"
#include <QDebug>
Stone::Stone()
{
}
Stone::~Stone()
{
}
QString Stone::name()
{
switch(this->_type)
{
case CHE:
return QString("车");
case MA:
return QString("马");
;
case PAO:
return QString("炮");
;
case BING:
if(_red)
return QString("兵");
else
return QString("卒");
;
case JIANG:
if(_red)
return QString("帅");
else
return QString("将");
;
case SHI:
if(_red)
return QString("仕");
else
return QString("士");
;
case XIANG:
if(_red)
return QString("相");
else
return QString("象");
;
}
return QString("错误");
}
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;
qDebug()<<"type::"<<this->_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;
}