添加动画功能
This commit is contained in:
parent
4f67764a69
commit
e7c41e3f58
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.6.1, 2018-09-02T15:21:34. -->
|
||||
<!-- Written by QtCreator 4.6.1, 2018-11-06T00:04:14. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
|
|
@ -210,19 +210,35 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="src\boarditem.h" />
|
||||
<ClInclude Include="src\boarditem.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(QTDIR)\include;.\debug;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtNetwork</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB</Define>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName)\.;.\GeneratedFiles;.;$(QTDIR)\include;.\release;\include;$(QTDIR)\mkspecs\win32-msvc;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtMultimedia;$(QTDIR)\include\QtNetwork</IncludePath>
|
||||
<Define Condition="'$(Configuration)|$(Platform)'=='Release|x64'">_WINDOWS;UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_WIDGETS_LIB;QT_CORE_LIB;QT_GUI_LIB;QT_MULTIMEDIA_LIB;QT_NETWORK_LIB</Define>
|
||||
</ClInclude>
|
||||
<QtMoc Include="src\gamecontroller.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;debug;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;release;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\gamescene.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;debug;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;release;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\gameview.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;debug;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;release;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
<ClInclude Include="src\graphicsconst.h" />
|
||||
<ClInclude Include="src\ninechess.h" />
|
||||
<QtMoc Include="src\ninechesswindow.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;debug;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;release;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
<QtMoc Include="src\pieceitem.h" />
|
||||
<QtMoc Include="src\sizehintlistview.h">
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;debug;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include;release;\include;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\mkspecs\win32-msvc;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtWidgets;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtCore;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtGui;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtANGLE;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtMultimedia;D:\Qt\Qt5.11.0\5.11.0\msvc2017_64\include\QtNetwork;%(AdditionalIncludeDirectories)</IncludePath>
|
||||
</QtMoc>
|
||||
<ClInclude Include="src\pieceitem.h" />
|
||||
<QtMoc Include="src\sizehintlistview.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
|
|
@ -83,9 +83,6 @@
|
|||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\boarditem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<QtMoc Include="src\gamecontroller.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
|
@ -104,12 +101,12 @@
|
|||
<QtMoc Include="src\ninechesswindow.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<ClInclude Include="src\pieceitem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Generated Files</Filter>
|
||||
</ClInclude>
|
||||
<QtMoc Include="src\pieceitem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="debug\moc_predefs.h.cbt">
|
||||
|
@ -257,4 +254,9 @@
|
|||
<ItemGroup>
|
||||
<Image Include="NineChess.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\boarditem.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -497,9 +497,6 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionEdit_E">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "graphicsconst.h"
|
||||
#include <QPainter>
|
||||
|
||||
BoardItem::BoardItem(QGraphicsItem *parent ) : QGraphicsItem(parent),
|
||||
BoardItem::BoardItem(QGraphicsItem *parent ) : QGraphicsItem(),
|
||||
size(BOARD_SIZE),
|
||||
sizeShadow(5.0),
|
||||
hasObliqueLine(false)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifndef BOARDITEM_H
|
||||
#define BOARDITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class BoardItem : public QGraphicsItem
|
||||
|
@ -12,7 +11,8 @@ public:
|
|||
QPainterPath shape() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget * widget = 0);
|
||||
// 用UserType+1表示棋子,用qgraphicsitem_cast()判断是否为BoardItem类的对象
|
||||
|
||||
// 用UserType+1表示棋子,用qgraphicsitem_cast()判断是否为BoardItem类的对象
|
||||
// 还有一个方式是把类名放在Data的0key位置setData(0, "BoardItem"),然后用data(0)来判断
|
||||
enum { Type = UserType + 1 };
|
||||
int type() const { return Type; }
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QAbstractButton>
|
||||
#include <QMap>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include "gamecontroller.h"
|
||||
#include "graphicsconst.h"
|
||||
#include "boarditem.h"
|
||||
|
@ -19,13 +20,14 @@
|
|||
GameController::GameController(GameScene &scene, QObject *parent) : QObject(parent),
|
||||
// 是否浏览过历史纪录
|
||||
scene(scene),
|
||||
piece(NULL),
|
||||
currentPiece(NULL),
|
||||
currentRow(-1),
|
||||
isEditing(false),
|
||||
isInverted(false),
|
||||
isEngine1(false),
|
||||
isEngine2(false),
|
||||
hasAnimation(true),
|
||||
durationTime(250),
|
||||
hasSound(true),
|
||||
timeID(0),
|
||||
ruleNo(-1),
|
||||
|
@ -46,7 +48,7 @@ GameController::~GameController()
|
|||
// 清除棋子
|
||||
qDeleteAll(pieceList);
|
||||
pieceList.clear();
|
||||
piece = NULL;
|
||||
currentPiece = NULL;
|
||||
}
|
||||
|
||||
const QMap<int, QStringList> GameController::getActions()
|
||||
|
@ -90,7 +92,7 @@ void GameController::gameReset()
|
|||
// 清除棋子
|
||||
qDeleteAll(pieceList);
|
||||
pieceList.clear();
|
||||
piece = NULL;
|
||||
currentPiece = NULL;
|
||||
// 重新绘制棋盘
|
||||
scene.setDiagonal(chess.getRule()->hasObliqueLine);
|
||||
|
||||
|
@ -217,6 +219,11 @@ void GameController::setEngine2(bool arg)
|
|||
void GameController::setAnimation(bool arg)
|
||||
{
|
||||
hasAnimation = arg;
|
||||
// 默认动画时间250ms
|
||||
if (hasAnimation)
|
||||
durationTime = 250;
|
||||
else
|
||||
durationTime = 0;
|
||||
}
|
||||
|
||||
void GameController::setSound(bool arg)
|
||||
|
@ -478,7 +485,7 @@ bool GameController::placePiece(QPointF pos)
|
|||
// 移动旧子
|
||||
bool GameController::movePiece(QPointF pos)
|
||||
{
|
||||
if (!piece) {
|
||||
if (!currentPiece) {
|
||||
return false;
|
||||
}
|
||||
int c, p;
|
||||
|
@ -547,27 +554,60 @@ bool GameController::updateScence(NineChess &chess)
|
|||
{
|
||||
const char *board = chess.getBoard();
|
||||
QPointF pos;
|
||||
// chess类中的棋子代码
|
||||
int key;
|
||||
// 棋子总数
|
||||
int n = chess.getRule()->numOfChess * 2;
|
||||
|
||||
// 棋子就位
|
||||
for (int i = 0; i < n; i++)
|
||||
// 动画组
|
||||
QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup;
|
||||
|
||||
// 棋子就位
|
||||
PieceItem *piece = NULL;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
piece = pieceList.at(i);
|
||||
// 将pieceList的下标转换为chess的棋子代号
|
||||
key = (i >= n/2) ? (i + 0x21 -n/2) : (i + 0x11);
|
||||
int j;
|
||||
// 放置棋盘上的棋子
|
||||
for (j = NineChess::SEAT; j < (NineChess::SEAT)*(NineChess::RING + 1); j++)
|
||||
{
|
||||
if (board[j] == key)
|
||||
{
|
||||
pos = scene.cp2pos(j / NineChess::SEAT, j % NineChess::SEAT + 1);
|
||||
pieceList.at(i)->setPos(pos);
|
||||
if (piece->pos() != pos) {
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
|
||||
animation->setDuration(durationTime);
|
||||
animation->setStartValue(piece->pos());
|
||||
animation->setEndValue(pos);
|
||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animationGroup->addAnimation(animation);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 放置棋盘外的棋子
|
||||
if (j == (NineChess::SEAT)*(NineChess::RING + 1))
|
||||
{
|
||||
pieceList.at(i)->setPos((i % 2) ? scene.pos_p2 : scene.pos_p1);
|
||||
}
|
||||
// 判断是被吃掉的子,还是未安放的子
|
||||
if (key & 0x10) {
|
||||
pos = (key - 0x11 < n / 2 - chess.getPlayer1_InHand()) ? scene.pos_p2_g : scene.pos_p1;
|
||||
}
|
||||
else
|
||||
pos = (key - 0x21 < n / 2 - chess.getPlayer2_InHand()) ? scene.pos_p1_g : scene.pos_p2;
|
||||
|
||||
if (piece->pos() != pos) {
|
||||
QPropertyAnimation *animation = new QPropertyAnimation(piece, "pos");
|
||||
animation->setDuration(durationTime);
|
||||
animation->setStartValue(piece->pos());
|
||||
animation->setEndValue(pos);
|
||||
animation->setEasingCurve(QEasingCurve::InOutQuad);
|
||||
animationGroup->addAnimation(animation);
|
||||
}
|
||||
}
|
||||
piece->setSelected(false);
|
||||
}
|
||||
|
||||
// 添加开局禁子点
|
||||
|
@ -608,11 +648,12 @@ bool GameController::updateScence(NineChess &chess)
|
|||
// 选中当前棋子
|
||||
int ipos = chess.getCurrentPos();
|
||||
if (ipos) {
|
||||
pos = scene.cp2pos(ipos / NineChess::SEAT, ipos % NineChess::SEAT + 1);
|
||||
piece = qgraphicsitem_cast<PieceItem *> (scene.itemAt(pos, QTransform()));
|
||||
if (piece)
|
||||
piece->setSelected(true);
|
||||
key = board[chess.getCurrentPos()];
|
||||
currentPiece = pieceList.at(key & 0x10 ? key - 0x11 : key - 0x21 + n/2);
|
||||
currentPiece->setSelected(true);
|
||||
}
|
||||
|
||||
animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ public:
|
|||
int getRuleNo() { return ruleNo; }
|
||||
int getTimeLimit() { return timeLimit; }
|
||||
int getStepsLimit() { return stepsLimit; }
|
||||
bool isAnimation() { return hasAnimation; }
|
||||
void setDurationTime(int i) { durationTime = i; }
|
||||
int getDurationTime() { return durationTime; }
|
||||
// 棋谱字符串列表模型
|
||||
QStringListModel manualListModel;
|
||||
|
||||
|
@ -99,11 +102,11 @@ private:
|
|||
// 所有棋子
|
||||
QList<PieceItem *> pieceList;
|
||||
// 当前棋子
|
||||
PieceItem *piece;
|
||||
PieceItem *currentPiece;
|
||||
// 当前浏览的棋谱行
|
||||
int currentRow;
|
||||
// 玩家1手棋数、玩家2手棋数、待去棋数
|
||||
int player1_InHand, player2_InHand, num_NeedRemove;
|
||||
// 玩家1手棋数、玩家2手棋数、待去棋数,没有用到,注释掉
|
||||
//int player1_InHand, player2_InHand, num_NeedRemove;
|
||||
// 是否处于“编辑棋局”状态
|
||||
bool isEditing;
|
||||
// 是否黑白反转
|
||||
|
@ -114,7 +117,9 @@ private:
|
|||
bool isEngine2;
|
||||
// 是否有落子动画
|
||||
bool hasAnimation;
|
||||
// 是否有落子音效
|
||||
// 动画持续时间
|
||||
int durationTime;
|
||||
// 是否有落子音效
|
||||
bool hasSound;
|
||||
// 定时器ID
|
||||
int timeID;
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
GameScene::GameScene(QObject *parent) : QGraphicsScene(parent),
|
||||
board(NULL),
|
||||
pos_p1(LINE_INTERVAL * 6, LINE_INTERVAL * 3),
|
||||
pos_p1_g(LINE_INTERVAL* (-6), LINE_INTERVAL * 3),
|
||||
pos_p2(LINE_INTERVAL * (-6), LINE_INTERVAL * (-3)),
|
||||
pos_p2_g(LINE_INTERVAL * 6, LINE_INTERVAL * (-3))
|
||||
pos_p1(LINE_INTERVAL * 4, LINE_INTERVAL * 6),
|
||||
pos_p1_g(LINE_INTERVAL* (-4), LINE_INTERVAL * 6),
|
||||
pos_p2(LINE_INTERVAL * (-4), LINE_INTERVAL * (-6)),
|
||||
pos_p2_g(LINE_INTERVAL * 4, LINE_INTERVAL * (-6))
|
||||
{
|
||||
// 添加棋盘
|
||||
board = new BoardItem;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QLabel>
|
||||
#include <QHelpEvent>
|
||||
#include <QToolTip>
|
||||
#include <QElapsedTimer>
|
||||
#include <QDebug>
|
||||
#include "ninechesswindow.h"
|
||||
#include "gamecontroller.h"
|
||||
|
@ -74,8 +75,8 @@ NineChessWindow::NineChessWindow(QWidget *parent)
|
|||
// 初始化游戏规则菜单
|
||||
ui.menu_R->installEventFilter(this);
|
||||
|
||||
// 安装一次性定时器,执行初始化
|
||||
QTimer::singleShot(0, this, SLOT(initialize()));
|
||||
// 游戏初始化
|
||||
initialize();
|
||||
}
|
||||
|
||||
NineChessWindow::~NineChessWindow()
|
||||
|
@ -110,14 +111,10 @@ bool NineChessWindow::eventFilter(QObject *watched, QEvent *event)
|
|||
|
||||
void NineChessWindow::initialize()
|
||||
{
|
||||
// 如果游戏已经初始化,则退出
|
||||
if (game != NULL)
|
||||
return;
|
||||
// 开辟一个新的游戏控制器
|
||||
game = new GameController(*scene, this);
|
||||
|
||||
// 开辟一个新的游戏控制器
|
||||
game = new GameController(*scene, this);
|
||||
|
||||
// 添加新菜单栏动作
|
||||
// 添加新菜单栏动作
|
||||
QMap <int, QStringList> actions = game->getActions();
|
||||
QMap <int, QStringList>::const_iterator i;
|
||||
for (i = actions.constBegin(); i != actions.constEnd(); i++) {
|
||||
|
@ -275,7 +272,27 @@ void NineChessWindow::on_actionOpen_O_triggered()
|
|||
{
|
||||
cmd = textStream.readLine();
|
||||
game->command(cmd);
|
||||
}
|
||||
// 自动运行前禁用所有控件
|
||||
ui.menuBar->setEnabled(false);
|
||||
ui.mainToolBar->setEnabled(false);
|
||||
ui.dockWidget->setEnabled(false);
|
||||
ui.gameView->setEnabled(false);
|
||||
// 处理自动播放时的动画
|
||||
if (game->isAnimation()) {
|
||||
QElapsedTimer et;
|
||||
et.start();
|
||||
int waitTime = game->getDurationTime() + 50;
|
||||
while (et.elapsed() < waitTime)
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
// 自动运行结束后启用所有控件
|
||||
ui.menuBar->setEnabled(true);
|
||||
ui.mainToolBar->setEnabled(true);
|
||||
ui.dockWidget->setEnabled(true);
|
||||
ui.gameView->setEnabled(true);
|
||||
// 取消自动运行按钮的选中状态
|
||||
ui.actionAutoRun_A->setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -428,6 +445,12 @@ void NineChessWindow::on_actionAutoRun_A_toggled(bool arg1)
|
|||
if (rows <= 1)
|
||||
return;
|
||||
|
||||
// 自动运行前禁用所有控件
|
||||
ui.menuBar->setEnabled(false);
|
||||
ui.mainToolBar->setEnabled(false);
|
||||
ui.dockWidget->setEnabled(false);
|
||||
ui.gameView->setEnabled(false);
|
||||
|
||||
// 反复执行“下一招”
|
||||
while (currentRow < rows - 1)
|
||||
{
|
||||
|
@ -460,9 +483,26 @@ void NineChessWindow::on_actionAutoRun_A_toggled(bool arg1)
|
|||
ui.actionEnd_E->setEnabled(true);
|
||||
ui.actionAutoRun_A->setEnabled(true);
|
||||
}
|
||||
|
||||
// 更新局面
|
||||
game->phaseChange(currentRow);
|
||||
// 处理自动播放时的动画
|
||||
if (game->isAnimation()) {
|
||||
QElapsedTimer et;
|
||||
et.start();
|
||||
int waitTime = game->getDurationTime() + 50;
|
||||
while (et.elapsed() < waitTime)
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
||||
// 自动运行结束后启用所有控件
|
||||
ui.menuBar->setEnabled(true);
|
||||
ui.mainToolBar->setEnabled(true);
|
||||
ui.dockWidget->setEnabled(true);
|
||||
ui.gameView->setEnabled(true);
|
||||
// 取消自动运行按钮的选中状态
|
||||
ui.actionAutoRun_A->setChecked(false);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#ifndef CHESSITEM_H
|
||||
#define CHESSITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class PieceItem : public QGraphicsItem
|
||||
class PieceItem : public QObject, public QGraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
// 位置属性
|
||||
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
||||
|
||||
public:
|
||||
explicit PieceItem(QGraphicsItem *parent = 0);
|
||||
~PieceItem();
|
||||
|
|
55
范例棋谱.txt
55
范例棋谱.txt
|
@ -1,9 +1,50 @@
|
|||
r3 s000 t00
|
||||
(3,1) 00:00.000
|
||||
(2,1) 00:01.195
|
||||
(1,1) 00:01.754
|
||||
(2,3) 00:08.021
|
||||
(3,3) 00:02.332
|
||||
(3,4) 00:32.907
|
||||
(3,5) 00:03.513
|
||||
(1,5) 00:42.977
|
||||
(2,1) 00:01.390
|
||||
(2,3) 00:01.701
|
||||
(2,4) 00:03.027
|
||||
(3,2) 00:04.404
|
||||
(2,2) 00:04.111
|
||||
(3,8) 00:06.017
|
||||
-(2,1) 00:08.355
|
||||
(2,8) 00:09.284
|
||||
(1,1) 00:10.028
|
||||
(2,1) 00:10.625
|
||||
-(1,1) 00:11.837
|
||||
(1,4) 00:14.877
|
||||
(1,3) 00:18.100
|
||||
(3,3) 00:17.331
|
||||
(3,4) 00:19.044
|
||||
(3,5) 00:19.068
|
||||
(2,5) 00:21.019
|
||||
(1,5) 00:20.360
|
||||
(2,7) 00:24.118
|
||||
(1,5)->(1,6) 00:22.927
|
||||
(2,5)->(2,6) 00:25.459
|
||||
-(3,5) 00:28.499
|
||||
(1,6)->(1,5) 00:25.352
|
||||
(2,6)->(2,5) 00:30.155
|
||||
(1,5)->(1,6) 00:26.503
|
||||
(2,7)->(2,6) 00:31.620
|
||||
-(1,6) 00:32.290
|
||||
(1,4)->(1,5) 00:28.604
|
||||
(2,8)->(2,7) 00:34.556
|
||||
(3,8)->(3,7) 00:30.648
|
||||
(2,1)->(2,8) 00:36.458
|
||||
-(3,1) 00:39.850
|
||||
(3,2)->(3,1) 00:34.675
|
||||
(2,5)->(3,5) 00:46.946
|
||||
(1,5)->(1,4) 00:36.227
|
||||
(2,6)->(2,5) 00:48.337
|
||||
(3,7)->(3,8) 00:38.581
|
||||
(2,7)->(2,6) 00:50.010
|
||||
-(3,3) 00:51.016
|
||||
(2,3)->(3,3) 00:43.433
|
||||
(1,3)->(2,3) 00:52.296
|
||||
-(3,3) 00:52.822
|
||||
(1,4)->(1,3) 00:45.444
|
||||
(2,5)->(1,5) 00:56.716
|
||||
(1,3)->(1,2) 00:46.681
|
||||
(2,4)->(2,5) 00:59.099
|
||||
-(1,2) 01:60.821
|
||||
Player2 win!
|
||||
|
|
Loading…
Reference in New Issue