资源简介
自己用qt写的小游戏,压缩包中包含了可执行程序和源代码。源代码是用qt creator写的,打开.pro文件可以直接编译。欢迎大家下载并提出意见和建议

代码片段和文件信息
#include “communicator.h“
#include
#include
#include
#include
#include
#include
#include
#include “tabwidget.h“
#include “mainwindow.h“
extern TabWidget *widget;
extern MainWindow *w;
Communicator::Communicator()
{
server = 0;
tcpSocket = 0;
ipAddress = ““;
serverPort = 0;
}
Communicator::~Communicator()
{
if(server)
{
server->disconnect();
delete server;
}
if(tcpSocket)
{
tcpSocket->disconnect();
delete tcpSocket;
}
}
void Communicator::initServer()
{
if(!server)
server = new QTcpServer(this);
QString msg;
bool flag = false;
if(!server->isListening())
flag = server->listen();
if(!flag)
{
msg = QString(“start listen failed“);
emit serverInitMessageToDisplay(msg);
}
else
{
QList addressList = QNetworkInterface::allAddresses();
int i;
for(i = 0; i < addressList.size(); i++)
{
if(addressList.at(i) != QHostAddress::LocalHost && addressList.at(i).toIPv4Address())
{
ipAddress = addressList.at(i).toString();
break;
}
}
if(ipAddress.isEmpty())
{
msg = QString(“no local ip available“);
emit serverInitMessageToDisplay(msg);
}
else
{
serverPort = server->serverPort();
QTextStream ts(&msg);
ts << “ip: “ << ipAddress << “ port:“ << serverPort;
emit serverInitMessageToDisplay(msg);
connect(server SIGNAL(newConnection()) this SLOT(acceptConnection()));
}
}
}
void Communicator::initClient()
{
if(!tcpSocket)
tcpSocket = new QTcpSocket(this);
}
void Communicator::setServerIp(QString ip)
{
ipAddress = ip;
}
void Communicator::setServerPort(int port)
{
serverPort = port;
}
void Communicator::connectToServer()
{
tcpSocket->abort();
tcpSocket->connectToHost(ipAddress serverPort);
connect(tcpSocket SIGNAL(connected()) this SIGNAL(connectionEstablished()));
connect(tcpSocket SIGNAL(error(QAbstractSocket::SocketError)) this SLOT(displayerror(QAbstractSocket::SocketError)));
connect(tcpSocket SIGNAL(readyRead()) this SLOT(readMessage()));
connect(tcpSocket SIGNAL(disconnected()) tcpSocket SLOT(deleteLater()));
connect(tcpSocket SIGNAL(disconnected()) w SLOT(opponentClosed()));
}
QString Communicator::getLocalIp()
{
return ipAddress;
}
void Communicator::acceptConnection()
{
tcpSocket = server->nextPendingConnection();
connect(tcpSocket SIGNAL(disconnected()) tcpSocket SLOT(deleteLater()));
connect(tcpSocket SIGNAL(disconnected()) w SLOT(opponentClosed()));
connect(tcpSocket SIGNAL
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17553 2012-01-10 15:19 sixPieces\program\images\black.png
文件 17768 2012-01-12 18:33 sixPieces\program\images\blackhi.png
文件 1790253 2012-01-10 16:15 sixPieces\program\images\board.png
文件 59384 2012-01-12 18:41 sixPieces\program\images\white.png
文件 56120 2012-01-12 18:58 sixPieces\program\images\whitehi.png
文件 43008 2012-01-05 15:01 sixPieces\program\libgcc_s_dw2-1.dll
文件 11362 2012-01-05 15:01 sixPieces\program\mingwm10.dll
文件 2552320 2012-01-05 15:02 sixPieces\program\QtCore4.dll
文件 9869824 2012-01-05 15:02 sixPieces\program\QtGui4.dll
文件 1215488 2012-01-05 15:02 sixPieces\program\QtNetwork4.dll
文件 544256 2012-02-12 14:29 sixPieces\program\sixPieces.exe
文件 1758 2007-10-09 18:52 sixPieces\program\sounds\my.wav
文件 11070 2007-10-09 18:52 sixPieces\program\sounds\oppo.wav
文件 25174 2012-02-13 15:01 sixPieces\program\游戏说明.doc
文件 5523 2012-02-12 10:45 sixPieces\src\communicator.cpp
文件 1582 2012-02-12 10:29 sixPieces\src\communicator.h
文件 17553 2012-01-10 15:19 sixPieces\src\images\black.png
文件 17768 2012-01-12 18:33 sixPieces\src\images\blackhi.png
文件 1790253 2012-01-10 16:15 sixPieces\src\images\board.png
文件 59384 2012-01-12 18:41 sixPieces\src\images\white.png
文件 56120 2012-01-12 18:58 sixPieces\src\images\whitehi.png
文件 10986 2012-02-12 14:29 sixPieces\src\logicboard.cpp
文件 887 2012-02-11 00:53 sixPieces\src\logicboard.h
文件 564 2012-02-10 22:26 sixPieces\src\main.cpp
文件 19352 2012-02-12 14:29 sixPieces\src\mainwindow.cpp
文件 1749 2012-02-12 13:25 sixPieces\src\mainwindow.h
文件 1350 2012-01-17 17:31 sixPieces\src\mainwindow.ui
文件 6901 2012-02-13 15:44 sixPieces\src\Makefile
文件 8474 2012-02-13 15:44 sixPieces\src\Makefile.Debug
文件 8622 2012-02-13 15:44 sixPieces\src\Makefile.Release
............此处省略21个文件信息
- 上一篇:vfp 商品管理系统
- 下一篇:微星Z77A-GD55 BIOS 添加nvme协议。
相关资源
- flash3.0小游戏
- Scrach 欢乐狙击手.sb2
- c 制作的RPG小游戏
- 多线程实例:桌面智能弹球小游戏
- 小鱼捉迷藏Scratch小游戏
- Scrach3.0 跳一跳小游戏
- js 迷宫小游戏源码
- Greenfoot小游戏合辑
- Scratch 走迷宫 小游戏源码
- Scratch 青蛙过马路 小游戏源码(.sb2)
- Scratch 贪吃蛇 小游戏源码
- Scratch 打地鼠 小游戏源码
- Scratch 贪吃蛇.sb3 小游戏源码
- Scratch 用盆子接水果 小游戏源码(c
- app inventor小游戏打地鼠.aia
- Scratch 地狱边境(小游戏源码).sb2
- Scratch小恐龙躲避仙人掌.sb2
- Scratch Tank 小游戏源码.sb2
- scratch 逃.sb3(小游戏)
- 40款h5游戏+21款热门测试吸粉
- 易语言海战小游戏源码
- 打飞碟游戏
- FLASH小游戏合集 第一弹 绝对经典!
- Pathon开发象棋小游戏总文件
- 微信小游戏扑克24点源码
- Qt写的连连看小游戏
- 是男人就下一百层
- 小程序小游戏你画我,猜亲测可用
- flash做的飞机大战小游戏
- FC炸弹人I图片素材.rar
评论
共有 条评论