资源简介
开发环境:LinuxMint 17.1
开发工具:QtCreator 3.3.1
Qt版本:5.4.1
功能:实现了人机对战,网络对战,自己和自己下棋三种模式。主要功能包括重复局面检测,长将判负,悔棋,提示音播放,死棋检测,中文着法显示,步时限制,保存棋局到文件和从文件加载棋局。总共代码有5000行左右,历时200多个小时。

代码片段和文件信息
#include “chessboard.h“
#include “commdef.h“
#include
#include
ChessBoard::ChessBoard(QWidget *parent) : QWidget(parent)
{
resize(CHESSBOARD_WIDTH CHESSBOARD_HEIGHT);
move(CHESSBOARD_STARTX CHESSBOARD_STARTY);
fliped = false;
loadPixmap(STARTUP_LAYOUT);
}
ChessBoard::~ChessBoard()
{
}
void ChessBoard::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
int xx = 0;
int yy = 0;
int index = 0;
QPainter painter(this);
painter.drawPixmap(0 0 background);
for (int row = 0; row < CHESSBOARD_ROW; ++row)
{
for (int column = 0; column < CHESSBOARD_COLUMN; ++column)
{
index = row * CHESSBOARD_COLUMN + column;
getPixmapPos(row column xx yy);
painter.drawPixmap(xx yy arrChessman[index]);
}
}
}
void ChessBoard::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
int row = 0;
int column = 0;
getPixmapIndex(event->pos().x() event->pos().y() row column);
int sq = getChessmanIndex(row column fliped);
emit doMove(sq);
}
}
void ChessBoard::loadPixmap(const char *chessman)
{
int sq = 0;
char pc = 0;
int index = 0;
background.load(“:/images/WOOD.GIF“);
for(int row = 0; row < CHESSBOARD_ROW; ++row)
{
for (int column = 0; column < CHESSBOARD_COLUMN; ++column)
{
index = row * CHESSBOARD_COLUMN + column;
sq = getChessmanIndex(row column fliped);
pc = chessman[sq];
arrChessman[index].load(getChessmanPic(pc false false));
}
}
}
void ChessBoard::showMoveRoute(char movingChessman int move bool show)
{
int srcPos = SRC(move);
int dstPos = DST(move);
int srcIndex = 0;
int dstIndex = 0;
if (srcPos > 0)
{
srcIndex = getChessboardCoord(FILE_X(srcPos) RANK_Y(srcPos) fliped);
arrChessman[srcIndex].load(getChessmanPic(dstPos > 0 ? 0 : movingChessman show false));
}
if (dstPos > 0)
{
dstIndex = getChessboardCoord(FILE_X(dstPos) RANK_Y(dstPos) fliped);
arrChessman[dstIndex].load(getChessmanPic(movingChessman show false));
}
}
void ChessBoard::updateGeneralDisplay(char chessman int pos bool dead)
{
int index = getChessboardCoord(FILE_X(pos) RANK_Y(pos) fliped);
arrChessman[index].load(getChessmanPic(chessman true dead));
}
void ChessBoard::changeFlip()
{
fliped = !fliped;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-10-11 22:37 QtChess\
目录 0 2015-10-11 22:37 QtChess\audios\
文件 5850 2015-10-11 22:37 QtChess\audios\AttackKing.wav
文件 862 2015-10-11 22:37 QtChess\audios\Choose.wav
文件 24444 2015-10-11 22:37 QtChess\audios\Draw.wav
文件 5802 2015-10-11 22:37 QtChess\audios\Eat.wav
文件 6278 2015-10-11 22:37 QtChess\audios\Forbid.wav
文件 8560 2015-10-11 22:37 QtChess\audios\Loss.wav
文件 1962 2015-10-11 22:37 QtChess\audios\Move.wav
文件 121720 2015-10-11 22:37 QtChess\audios\NewGame.wav
文件 32122 2015-10-11 22:37 QtChess\audios\Win.wav
文件 2509 2015-10-11 22:37 QtChess\chessboard.cpp
文件 747 2015-10-11 22:37 QtChess\chessboard.h
文件 22229 2015-10-11 22:37 QtChess\chesshandler.cpp
文件 3029 2015-10-11 22:37 QtChess\chesshandler.h
文件 1453 2015-10-11 22:37 QtChess\clientnetwork.cpp
文件 624 2015-10-11 22:37 QtChess\clientnetwork.h
文件 27057 2015-10-11 22:37 QtChess\commdef.h
文件 185 2015-10-11 22:37 QtChess\Config.ini
文件 2467 2015-10-11 22:37 QtChess\gamesettings.cpp
文件 908 2015-10-11 22:37 QtChess\gamesettings.h
目录 0 2015-10-11 22:37 QtChess\images\
文件 2425 2015-10-11 22:37 QtChess\images\chess.png
文件 2383 2015-10-11 22:37 QtChess\images\fail.png
文件 2232 2015-10-11 22:37 QtChess\images\fallback.png
文件 486 2015-10-11 22:37 QtChess\images\fileexit.png
文件 1662 2015-10-11 22:37 QtChess\images\fileopen.png
文件 1205 2015-10-11 22:37 QtChess\images\filesave.png
文件 944 2015-10-11 22:37 QtChess\images\flip.png
文件 1096 2015-10-11 22:37 QtChess\images\helpabout.png
文件 1231 2015-10-11 22:37 QtChess\images\newgame.png
............此处省略60个文件信息
- 上一篇:MPC 自动驾驶 轨迹跟踪
- 下一篇:Qt开发的文本编辑器
相关资源
- 酒店管理系统基于Qt Creator5)
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- vtk QT做的三维地质可视化系统2of2
- 用VC 编写的仿QQ聊天室程序源代码
- Qt局域网聊天软件
- 外点法程序
- 外罚函数程序
- Qt Creator opengl实现四元数鼠标控制轨迹
- QT局域网聊天系统(基于QT5.修改过)
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - QT 实现文件下载
- qt图像处理
- 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- VC 游戏编程—附源代码
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
评论
共有 条评论