Skip to content

Commit 88e3a8e

Browse files
authored
为下一次更新做准备
修复了会导致软件崩溃的五子棋bug,并添加了制作迷宫的类的实现。
1 parent 865f063 commit 88e3a8e

File tree

9 files changed

+1270
-928
lines changed

9 files changed

+1270
-928
lines changed

cgobangchessboard.cpp

Lines changed: 900 additions & 906 deletions
Large diffs are not rendered by default.

cgobangchessboard.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define POWERVALUE1_15 1.15
3333
#define POWERVALUE1_20 1.20
3434

35+
#define INITIALADDSCORE 1.0
36+
3537
class CGobangChessboard : public QLabel
3638
{
3739
Q_OBJECT
@@ -49,6 +51,7 @@ class CGobangChessboard : public QLabel
4951
public:
5052
explicit CGobangChessboard(QWidget *parent = nullptr);
5153

54+
void addScoreInitially(double score);
5255
void restart();
5356

5457
protected:
@@ -66,18 +69,17 @@ class CGobangChessboard : public QLabel
6669
QVector<QImage*> m_vectorPlayImagesHistory;
6770

6871
CGobangChessman **m_virtualChessboard = nullptr;
69-
CGobangChessman::CChessmanType m_playerChessmanType = CGobangChessman::CChessmanType::Type_Black;
72+
CGobangChessman::CChessmanType m_playerChessmanType = CGobangChessman::CChessmanType::Chessman_Black;
7073

7174
private slots:
7275
void ai();
73-
void updateScore(int indexX, int indexY, CGobangChessman::CChessmanType type);
7476
void checkWin(const int indexX, const int indexY, const CGobangChessman::CChessmanType type);
7577
void mouseMoveEvent(QMouseEvent *event);
7678
void mouseReleaseEvent(QMouseEvent *event);
7779
void paintChessboard();
78-
void paintPredictor();
79-
8080
bool paintChessman(int indexX, int indexY, CGobangChessman::CChessmanType chessmanType);
81+
void paintPredictor();
82+
void updateScore(int indexX, int indexY, CGobangChessman::CChessmanType type);
8183

8284
};
8385

cgobangchessman.cpp

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
CGobangChessman::CGobangChessman()
99
{
10-
m_isEmpty = true;
11-
m_score = INITIALSCORE;
12-
m_type = Type_None;
10+
this->m_isEmpty = true;
11+
this->m_backslash = INITIALSCORE;
12+
this->m_slash = INITIALSCORE;
13+
this->m_horizontal = INITIALSCORE;
14+
this->m_vertical = INITIALSCORE;
15+
this->m_type = Chessman_None;
1316
}
1417

1518
CGobangChessman::~CGobangChessman()
@@ -19,19 +22,48 @@ CGobangChessman::~CGobangChessman()
1922

2023
void CGobangChessman::addScore(int score)
2124
{
22-
this->m_score += score;
25+
this->m_backslash += score;
26+
this->m_slash += score;
27+
this->m_horizontal += score;
28+
this->m_vertical += score;
2329
}
2430

2531
bool CGobangChessman::isEmpty()
2632
{
2733
return this->m_isEmpty;
2834
}
2935

30-
bool CGobangChessman::powerScore(double power)
36+
bool CGobangChessman::powerScore(CDirectionType directionType, double power)
3137
{
3238
if(this->m_isEmpty == true && power > 0)
3339
{
34-
this->m_score *= power;
40+
switch(directionType)
41+
{
42+
default:
43+
{
44+
return false;
45+
}
46+
case Direction_Backslash:
47+
{
48+
this->m_backslash *= power;
49+
break;
50+
}
51+
case Direction_Slash:
52+
{
53+
this->m_slash *= power;
54+
break;
55+
}
56+
case Direction_Horizontal:
57+
{
58+
this->m_horizontal *= power;
59+
break;
60+
}
61+
case Direction_Vertical:
62+
{
63+
this->m_vertical *= power;
64+
break;
65+
}
66+
}
3567
return true;
3668
}
3769
return false;
@@ -40,17 +72,25 @@ bool CGobangChessman::powerScore(double power)
4072
void CGobangChessman::restart()
4173
{
4274
this->m_isEmpty = true;
43-
this->m_score = INITIALSCORE;
44-
this->m_type = Type_None;
75+
this->m_backslash = INITIALSCORE;
76+
this->m_slash = INITIALSCORE;
77+
this->m_horizontal = INITIALSCORE;
78+
this->m_vertical = INITIALSCORE;
79+
this->m_type = Chessman_None;
4580
}
4681

4782
double CGobangChessman::score()
4883
{
49-
if(m_type == Type_None)
84+
// if(m_type == Chessman_None)
85+
// {
86+
// return this->m_score;
87+
// }
88+
// return 0;
89+
if(m_type == Chessman_None)
5090
{
51-
return this->m_score;
91+
return (this->m_backslash + this->m_slash + this->m_horizontal + this->m_vertical);
5292
}
53-
return 0;
93+
return 0.0;
5494
}
5595

5696
bool CGobangChessman::setChessman(CChessmanType type)

cgobangchessman.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ class CGobangChessman : public QObject
1919
public:
2020
enum CChessmanType
2121
{
22-
Type_Black,
23-
Type_None,
24-
Type_White,
22+
Chessman_Black,
23+
Chessman_None,
24+
Chessman_White,
25+
};
26+
enum CDirectionType
27+
{
28+
Direction_Backslash,
29+
Direction_Slash,
30+
Direction_Horizontal,
31+
Direction_Vertical,
2532
};
2633

2734
explicit CGobangChessman();
@@ -30,6 +37,7 @@ class CGobangChessman : public QObject
3037
void addScore(int score);
3138
bool isEmpty();
3239
bool powerScore(double power);
40+
bool powerScore(CDirectionType directionType, double power);
3341
void restart();
3442
double score();
3543
bool setChessman(CChessmanType type);
@@ -40,7 +48,10 @@ class CGobangChessman : public QObject
4048

4149
private:
4250
bool m_isEmpty; //是否落子
43-
double m_score; //棋子初始化分数
51+
double m_backslash; //反斜杠方向的分数
52+
double m_slash; //斜杠方向的分数
53+
double m_horizontal; //斜杠方向的分数
54+
double m_vertical; //斜杠方向的分数
4455

4556
CChessmanType m_type; //棋子类型
4657

0 commit comments

Comments
 (0)