云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Qt课程设计--贪吃蛇游戏设计

Qt课程设计--贪吃蛇游戏设计

  • 62 次阅读
  • 3 次下载
  • 2025/5/23 1:50:25

nsnake newnsnake; newnsnake.show(); newnsnake.exec(); }

void Games::showdsnake() {

dsnake newdsnake; newdsnake.show(); newdsnake.exec(); }

void Games::showlsnake() {

lsnake newlsnake; newlsnake.show(); newlsnake.exec(); }

//死亡模式

#include \ #include #include #include #include #include #include #include #include #include #include \ #include #include #include deathsnake::deathsnake() {

setWindowTitle(tr(\死亡模式\)); this->resize(800,480);

9

QTextCodec::setCodecForTr(QTextCodec::codecForName(\)); dire=d_right; time=300; sec=0; min=0; hou=0; clear=false; //计时器

jsq=new QLabel(this); jsq->resize(128,128); jsq->move(336,176);

jsq->setPixmap(QString::number(sec)+\); jsq2=new QLabel(this); jsq3=new QLabel(this); food=getFood();

data.push_back(initSnake());

qsrand(QTime().currentTime().msec()); //蛇move

timer=new QTimer(); timer->setInterval(time); timer->start();

Ttimer=this->startTimer(1000);

connect(timer,SIGNAL(timeout()),this,SLOT(smove())); }

deathsnake::~deathsnake() {}

//蛇吃食物

QLabel* deathsnake::getFood() {

int gwidth=800; int gheight=480;

//规定食物大小20,生成的位置是20的倍数 //位置随机,并且在界面范围之内 QLabel *food=new QLabel(this); food->resize(20,20);

food->setAutoFillBackground(true);

food->setPalette(QPalette(QColor(qrand()5+100,qrand()5+100,qrand()5+100)));

10

food->setFrameStyle(QFrame::Box | QFrame::Sunken); food->setLineWidth(3); food->setMidLineWidth(1); int fx=(qrand()%(gwidth/20))*20; int fy=(qrand()%(gheight/20))*20; int n;

//食物不在蛇身上 int s=data.size(); for(n=0;n

int bhx=data[n]->x(); int bhy=data[n]->y(); while(fx==bhx&&fy==bhy) {

fx=(qrand()%(gwidth/20))*20; fy=(qrand()%(gheight/20))*20; } }

//食物不能在墙上 int ws=wdata.size(); for(n=0;n

int wx=wdata[n]->x(); int wy=wdata[n]->y(); while(fx==wx&&fy==wy) {

fx=(qrand()%(gwidth/20))*20; fy=(qrand()%(gheight/20))*20; } }

food->move(fx,fy); food->show(); return food; } //蛇生长

QLabel* deathsnake::snakeGrow() {

11

QLabel *food=new QLabel(this); food->resize(20,20);

food->setAutoFillBackground(true);

food->setPalette(QPalette(QColor(qrand()5+100,qrand()5+100,qrand()5+100))); food->setFrameStyle(QFrame::Box | QFrame::Sunken); food->setLineWidth(3); food->setMidLineWidth(1); food->move(1280,769); food->show(); return food; }

//初始化蛇头位置

QLabel* deathsnake::initSnake() {

QLabel *food=new QLabel(this); food->resize(20,20);

food->setAutoFillBackground(true);

food->setPalette(QPalette(QColor(qrand()5+100,qrand()5+100,qrand()5+100))); food->setFrameStyle(QFrame::Box | QFrame::Sunken); food->setLineWidth(3); food->setMidLineWidth(3); food->move(100,200); food->show(); QMessageBox msg; //level 1

msg.setWindowTitle(tr(\正在进入死亡模式:\)); msg.setText(\ many secs can you hold on?\); msg.setStandardButtons(QMessageBox::Ok); msg.show(); msg.exec(); return food; }

//舍身移动

void deathsnake::smove() {

int nhx=data[0]->x(); int nhy=data[0]->y();

12

搜索更多关于: Qt课程设计--贪吃蛇游戏设计 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

nsnake newnsnake; newnsnake.show(); newnsnake.exec(); } void Games::showdsnake() { dsnake newdsnake; newdsnake.show(); newdsnake.exec(); } void Games::showlsnake() { lsnake newlsnake; newlsnake.show(); newlsnake.exec(); } //死亡模式 #include \ #include #include #include #include #include

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com