QT的贪吃蛇小游戏开发

时间:2021-12-10 05:11:42
【文件属性】:
文件名称:QT的贪吃蛇小游戏开发
文件大小:695KB
文件格式:ZIP
更新时间:2021-12-10 05:11:42
QT GameWidget::GameWidget(QWidget *parent) : QWidget(parent), ui(new Ui::GameWidget) { ui->setupUi(this); //加背景 QPalette palet; palet.setBrush(QPalette::Background, \ QBrush(QPixmap(":/new/prefix1/img/green.jpg").scaled(580, 370))); this->setPalette(palet); //蛇头产生随机的位置和随机的方向 QTime cur = QTime::currentTime(); qsrand(cur.msec()); snake[0][0] = qrand() % COL; snake[0][1] = qrand() % ROW; direction = qrand() % 4; //食物的随机位置 while (1) { foodx = qrand() % COL; foody = qrand() % ROW; if (foodx != snake[0][0] || foody != snake[0][1]) break; } //创建时钟对象 tm = new QTimer(); tm->setInterval(300); //链接时钟超时信号与槽函数 connect(tm, SIGNAL(timeout()), this, SLOT(timeout_handler())); //连接按键的信号与按钮槽函数 connect(this, SIGNAL(pressKeyASignal()), ui->leftPushButton, SLOT(click())); connect(this, SIGNAL(pressKeySSignal()), ui->downPushButton, SLOT(click())); connect(this, SIGNAL(pressKeyWSignal()), ui->upPushButton, SLOT(click())); connect(this, SIGNAL(pressKeyDSignal()), ui->rightPushButton, SLOT(click())); //初始化 foodcount = 0; score = 0; level = 1; }
【文件预览】:
snake_up
----gamewidget.cpp(5KB)
----snake_up.pro.user(23KB)
----img()
--------11.png(5KB)
--------22.png(6KB)
--------gameover.png(18KB)
--------tr_corner.png(2KB)
--------head2.png(2KB)
--------rat.png(3KB)
--------c.png(4KB)
--------bl_corner.png(2KB)
--------head0.png(2KB)
--------h_body.png(1KB)
--------rats.png(3KB)
--------v_body.png(2KB)
--------tailright.png(1KB)
--------br_corner.png(2KB)
--------1.png(15KB)
--------quit.png(106KB)
--------game.png(25KB)
--------tl_corner.png(2KB)
--------33.png(6KB)
--------tailleft.png(1KB)
--------icon.png(15KB)
--------start.png(25KB)
--------tail.png(2KB)
--------logo.png(42KB)
--------green.jpg(6KB)
--------Enter.png(253KB)
--------tailup.png(2KB)
--------taildown.png(2KB)
--------head1.png(2KB)
--------head3.png(2KB)
--------back.jpg(16KB)
--------apple.png(104KB)
--------button.png(20KB)
----mainwidget.cpp(612B)
----gamewidget.h(1KB)
----mainwidget.h(459B)
----images.qrc(1KB)
----snake_up.pro(1KB)
----mainwidget.ui(2KB)
----main.cpp(183B)
----gamewidget.ui(5KB)
----snake_up.pro.user.cc1bc03(23KB)

网友评论