forked from XMuli/ChineseChess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessPieces.cpp
executable file
·106 lines (97 loc) · 2.71 KB
/
ChessPieces.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
98
99
100
101
102
103
104
105
106
/*
* Copyright (C) 2019~2020 偕臧 All rights reserved.
*
* Author: xmuli(偕臧) [email protected]
*
* github: https://github.com/xmuli
* blogs: https://xmuli.tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://touwoyimuli.github.io/>.
*/
#include "ChessPieces.h"
//1、定义结构体tPOS
struct POS
{
int t_nRow;
int t_nCol;
ChessPieces::m_emTYPE t_emType;
};
//定义基础的16棋子[预定作为上方使用,黑棋使用]
POS tPos[16]= {
{0, 0, ChessPieces::CHE},
{0, 1, ChessPieces::MA},
{0, 2, ChessPieces::XIANG},
{0, 3, ChessPieces::SHI},
{0, 4, ChessPieces::JIANG},
{0, 5, ChessPieces::SHI},
{0, 6, ChessPieces::XIANG},
{0, 7, ChessPieces::MA},
{0, 8, ChessPieces::CHE},
{2, 1, ChessPieces::PAO},
{2, 7, ChessPieces::PAO},
{3, 0, ChessPieces::BING},
{3, 2, ChessPieces::BING},
{3, 4, ChessPieces::BING},
{3, 6, ChessPieces::BING},
{3, 8, ChessPieces::BING}
};
ChessPieces::ChessPieces()
{
}
ChessPieces::~ChessPieces()
{
}
//初始化 对每一个棋子进行检验判断而后赋相应的值
void ChessPieces::init(int id)
{
if(id <16)
{
m_nRow = tPos[id].t_nRow;
m_nCol = tPos[id].t_nCol;
m_emType = tPos[id].t_emType;
m_bRed = false;
}
else
{
m_nRow = 9-tPos[id-16].t_nRow;
m_nCol = 8-tPos[id-16].t_nCol;
m_emType = tPos[id-16].t_emType;
m_bRed = true;
}
m_bDead = false;
}
QString ChessPieces::getnName()
{
//enum m_emTYPE{JIANG, SHI, XIANG, MA, CHE, PAO, BING};
switch(m_emType)
{
case CHE:
return "车";
case MA:
return "马";
case PAO:
return "炮";
case BING:
return "兵";
case JIANG:
return "将";
case SHI:
return "士";
case XIANG:
return "相";
default:
return "显示出错";
}
return "ERROR";
}