Giter VIP home page Giter VIP logo

chess's Introduction

Qt-Chess

Qt 大作业军旗对战

开发环境

Windows 10 家庭中文版

Visual Studio 2019 + Qt 6.1.2 (MSVC 2019 64-bit)

设计说明

网络架构

通信方式采用 TCP 通信,面向连接,能够实现游戏过程中的即时通信。

服务采用 C/S 结构,游戏双方分别为客户端和服务器端。

服务器端工作流程

服务器端创建 QTcpServer 对象作为服务器,调用 QTcpServer::listen 监听(端口 514 的)连接请求。当有客户端接入时,创建一个与客户端连接的套接字 QTcpSocket,同时服务器停止监听。

连接建立后即可开始游戏。游戏开始、进行及结束过程中通过 QTcpSocket::writeQTcpSocket::read 收发报文进行通信,从而保证双方游戏状态同步。

客户端工作流程

客户端创建 QTcpSocket 对象,根据用户输入的 IP 地址,调用 QTcpSocket::connectToHost 尝试连接到服务器端。连接成功即可开始游戏,否则提示连接失败并断开连接。

游戏开始、进行及结束过程中的通信与服务器端相同。

信号与槽

本次作业中多处利用了 Qt 特有的信号/槽(Signal/Slot)机制,便于进行事件处理以及界面组件的交互。例如在游戏界面的点击、超时、游戏结束信号,分别与套接字的对应槽连接,从而能够调用 QTcpSocket::write 发送报文,实现游戏同步。

GUI

游戏窗口继承自 QMainWindow 类,拥有菜单栏,可实现连接、断开连接、开始游戏、游戏认输的功能。

通过(鼠标左键)点击游戏界面的对应棋子,可实现翻棋、选择、取消选择、走子、吃子的功能。棋子被选中后变为灰色,达到提示玩家的效果。

棋盘采用 3D 透视效果,对战双方的视角相反,游戏界面更真实。

游戏过程中,双方界面都显示进度条,标示当前下棋方、玩家阵营(颜色)及剩余时间。

游戏结束时弹窗告知双方胜负结果。

chess's People

Contributors

piuuuuuuui avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.