当前位置: 首页 > news >正文

医疗器械网站怎么做深圳网络公司推广公司

医疗器械网站怎么做,深圳网络公司推广公司,买了网站 怎么做呢,全国免费发布广告信息平台一、项目介绍 本项目是一个使用Qt框架开发的经典贪吃蛇游戏,旨在通过简单易懂的游戏机制和精美的用户界面,为玩家提供娱乐和编程学习的机会。 游戏展示 二、主要功能 2.1 游戏界面 游戏主要是由三个界面构成,分别是游戏大厅、难度选择和游戏…

一、项目介绍

本项目是一个使用Qt框架开发的经典贪吃蛇游戏,旨在通过简单易懂的游戏机制和精美的用户界面,为玩家提供娱乐和编程学习的机会。

游戏展示

二、主要功能

2.1 游戏界面

游戏主要是由三个界面构成,分别是游戏大厅、难度选择和游戏内界面,因此需要建立三个.cpp文件,分别对应的是gamehall.cpp、gameselect.cpp和gameroom.cpp。

2.1.1 gamehall.cpp

在游戏大厅界面,需要将图片设置到背景板上,并且创建一个“开始游戏”按钮

GameHall::GameHall(QWidget *parent): QWidget(parent), ui(new Ui::GameHall)
{ui->setupUi(this);// 设置窗口大小、图标、名字this->setFixedSize(1080,720);this->setWindowIcon(QIcon(":Resource/icon.png"));this->setWindowTitle("贪吃蛇大作战");// 设置开始按钮QFont font("华文行楷",18);QPushButton* pushButton_start = new QPushButton(this);pushButton_start->setText("开始游戏");pushButton_start->setFont(font);pushButton_start->move(520,400);pushButton_start->setGeometry(440,520,160,90);pushButton_start->setStyleSheet("QPushButton{border:0px;}");// 点击“开始游戏”按钮进入难度选择界面GameSelect* gameSelect = new GameSelect;connect(pushButton_start,&QPushButton::clicked,[=](){this->close();gameSelect->setGeometry(this->geometry());gameSelect->show();QSound::play(":Resource/clicked.wav");});
}GameHall::~GameHall()
{delete ui;
}void GameHall::paintEvent(QPaintEvent *event)
{(void) *event;// 实例化画家QPainter painter(this);// 实例化绘图设备QPixmap pix(":Resource/game_hall.png");// 绘图painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

2.1.2 gameselect.cpp

在游戏选择界面中,同样是需要设置背景,创建按钮等操作。

其中点击“简单模式”、“正常模式”、“困难模式”可以直接进入游戏房间内,而查阅“历史战绩”时会弹出一个新窗口显示战绩。

GameSelect::GameSelect(QWidget *parent) : QWidget(parent)
{// 设置“难度选择”界面的图标、名字this->setFixedSize(1080,720);this->setWindowIcon(QIcon(":Resource/icon.png"));this->setWindowTitle("难度选择");QFont font("华文行楷",24);GameRoom* gameRoom = new GameRoom;// 设置选择难度按钮和历史战绩按钮QPushButton* pushButton_easy = new QPushButton(this);pushButton_easy->move(460,160);pushButton_easy->setGeometry(460,160,150,80);pushButton_easy->setText("简单模式");pushButton_easy->setFont(font);pushButton_easy->setStyleSheet("QPushButton{border:0px;color:white}");QPushButton* pushButton_normal = new QPushButton(this);pushButton_normal->move(460,280);pushButton_normal->setGeometry(460,280,150,80);pushButton_normal->setText("正常模式");pushButton_normal->setFont(font);pushButton_normal->setStyleSheet("QPushButton{border:0px;color:white}");QPushButton* pushButton_hard = new QPushButton(this);pushButton_hard->move(460,400);pushButton_hard->setGeometry(460,400,150,80);pushButton_hard->setText("困难模式");pushButton_hard->setFont(font);pushButton_hard->setStyleSheet("QPushButton{border:0px;color:white}");QPushButton* pushButton_record = new QPushButton(this);pushButton_record->move(460,520);pushButton_record->setGeometry(460,520,150,80);pushButton_record->setText("历史战绩");pushButton_record->setFont(font);pushButton_record->setStyleSheet("QPushButton{border:0px;color:white}");// 点击不同困难模式按钮进入游戏房间connect(pushButton_easy,&QPushButton::clicked,[=](){this->close();gameRoom->setGeometry(this->geometry());gameRoom->show();QSound::play(":Resource/clicked.wav");gameRoom->setTimeout(300);});connect(pushButton_normal,&QPushButton::clicked,[=](){this->close();gameRoom->setGeometry(this->geometry());gameRoom->show();QSound::play(":Resource/clicked.wav");gameRoom->setTimeout(200);});connect(pushButton_hard,&QPushButton::clicked,[=](){this->close();gameRoom->setGeometry(this->geometry());gameRoom->show();QSound::play(":Resource/clicked.wav");gameRoom->setTimeout(100);});// 设置历史战绩窗口connect(pushButton_record,&QPushButton::clicked,[=](){QWidget* widget = new QWidget;widget->setWindowTitle("历史战绩");widget->setWindowIcon(QIcon(":Resource/icon.png"));widget->setFixedSize(500,300);QSound::play(":Resource/clicked.wav");QTextEdit* edit = new QTextEdit(widget);edit->setFont(font);edit->setFixedSize(500,300);QFile file("D:/bite/C-program/project/Snake/gamedata.txt");file.open(QIODevice::ReadOnly);QTextStream in(&file);int data = in.readLine().toInt();edit->append("历史得分为:");edit->append(QString::number(data));widget->show();});
}void GameSelect::paintEvent(QPaintEvent *event)
{(void) *event;QPainter painter(this);QPixmap pix(":Resource/game_select.png");painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

同时在这个界面中,我们需要创建一个“回退”按钮,点击可回退到游戏大厅界面

    // 设置回退按钮QPushButton* pushButton_back = new QPushButton(this);pushButton_back->move(1000,640);pushButton_back->setGeometry(1000,640,60,60);pushButton_back->setIcon(QIcon(":Resource/back.png"));// 点击回退按钮回到上一页connect(pushButton_back,&QPushButton::clicked,[=](){this->close();GameHall* gameHall = new GameHall;gameHall->show();QSound::play(":Resource/clicked.wav");});

2.1.3 gameroom.cpp

在游戏房间界面中,我们可以看到许多元素,其中不仅有“开始”、“暂停”、“退出”三个按钮,还有控制小蛇移动的方向键按钮,还有计分板等等元素。

我们首先要做的是设计背景以及创建各个按钮。

    // 设置游戏房间大小、图标、名字this->setFixedSize(1080,720);this->setWindowIcon(QIcon(":Resource/icon.png"));this->setWindowTitle("游戏房间");// 开始游戏、暂停游戏QFont font("楷体",20);QPushButton* pushButton_start = new QPushButton(this);pushButton_start->move(890,460);pushButton_start->setGeometry(890,460,100,60);pushButton_start->setText("开始");pushButton_start->setFont(font);connect(pushButton_start,&QPushButton::clicked,[=](){isGameStart = true;timer->start(moveTimeout);sound = new QSound(":Resource/Trepak.wav");sound->play();sound->setLoops(-1);});QPushButton* pushButton_stop = new QPushButton(this);pushButton_stop->move(890,540);pushButton_stop->setGeometry(890,540,100,60);pushButton_stop->setText("暂停");pushButton_stop->setFont(font);connect(pushButton_stop,&QPushButton::clicked,[=](){isGameStart = false;timer->stop();sound->stop();});// 设置方向键的位置、大小、图标和快捷键QPushButton* pushButton_up = new QPushButton(this);pushButton_up->move(900,220);pushButton_up->setGeometry(900,220,80,60);pushButton_up->setIcon(QIcon(":Resource/up1.png"));connect(pushButton_up,&QPushButton::clicked,[=](){if(moveDirect != SnakeDirect::DOWN)moveDirect = SnakeDirect::UP;});pushButton_up->setShortcut(QKeySequence(Qt::Key_W));QPushButton* pushButton_down = new QPushButton(this);pushButton_down->move(900,340);pushButton_down->setGeometry(900,340,80,60);pushButton_down->setIcon(QIcon(":Resource/down1.png"));connect(pushButton_down,&QPushButton::clicked,[=](){if(moveDirect != SnakeDirect::UP)moveDirect = SnakeDirect::DOWN;});pushButton_down->setShortcut(QKeySequence(Qt::Key_S));QPushButton* pushButton_left = new QPushButton(this);pushButton_left->move(820,280);pushButton_left->setGeometry(820,280,80,60);pushButton_left->setIcon(QIcon(":Resource/left1.png"));connect(pushButton_left,&QPushButton::clicked,[=](){if(moveDirect != SnakeDirect::RIGHT)moveDirect = SnakeDirect::LEFT;});pushButton_left->setShortcut(QKeySequence(Qt::Key_A));QPushButton* pushButton_right = new QPushButton(this);pushButton_right->move(980,280);pushButton_right->setGeometry(980,280,80,60);pushButton_right->setIcon(QIcon(":Resource/right1.png"));connect(pushButton_right,&QPushButton::clicked,[=](){if(moveDirect != SnakeDirect::LEFT)moveDirect = SnakeDirect::RIGHT;});pushButton_right->setShortcut(QKeySequence(Qt::Key_D));// 设置退出按钮QPushButton* pushButton_exit = new QPushButton(this);pushButton_exit->move(890,620);pushButton_exit->setGeometry(890,620,100,60);pushButton_exit->setText("退出");pushButton_exit->setFont(font);

2.2 游戏规则

蛇移动时不能碰到自己的身体,否则游戏结束。每吃掉一个食物(食物会随机刷新),身体变长,分数增加。

    // 初始化贪吃蛇snakeList.push_back(QRectF(this->width() * 0.5,this->height() * 0.5,kSnakeNodeWight,kSnakeNodeHeight));moveUP();moveUP();creatFood();timer = new QTimer(this);connect(timer,&QTimer::timeout,[=](){int count = 1;if(snakeList.front().intersects(foodRect)){creatFood();count++;QSound::play(":Resource/eatfood.wav");}while(count--){switch(moveDirect){case SnakeDirect::UP:moveUP();break;case SnakeDirect::DOWN:moveDOWN();break;case SnakeDirect::LEFT:moveLEFT();break;case SnakeDirect::RIGHT:moveRIGHT();break;}}snakeList.pop_back();update();});// 绘制蛇if(moveDirect == SnakeDirect::UP){pix.load(":Resource/up.png");}else if(moveDirect == SnakeDirect::DOWN){pix.load(":Resource/down.png");}else if(moveDirect == SnakeDirect::LEFT){pix.load(":Resource/left.png");}else{pix.load(":Resource/right.png");}// 绘制蛇头、身体和尾巴auto Head = snakeList.front();painter.drawPixmap(Head.x(),Head.y(),Head.width(),Head.height(),pix);pix.load(":Resource/Bd.png");for (int i = 0;i < snakeList.size() - 1;i++){auto Body = snakeList.at(i);painter.drawPixmap(Body.x(),Body.y(),Body.width(),Body.height(),pix);};auto tail = snakeList.back();painter.drawPixmap(tail.x(),tail.y(),tail.width(),tail.height(),pix);// 绘制食物pix.load(":Resource/food.png");painter.drawPixmap(foodRect.x(),foodRect.y(),foodRect.width(),foodRect.height(),pix);
bool GameRoom::checkFail()
{for(int i = 0;i < snakeList.size();i++){for(int j = i + 1;j < snakeList.size();j++){if(snakeList.at(i) == snakeList.at(j)){return true;}}}return false;
}void GameRoom::creatFood()
{foodRect = QRectF(qrand() % (800 / kSnakeNodeWight) * kSnakeNodeWight,qrand() % (this->height() / kSnakeNodeHeight) * kSnakeNodeHeight,kSnakeNodeWight,kSnakeNodeHeight);
}

2.3 控制方式

使用界面上的方向键(上、下、左、右)或者通过键盘上的快捷键(W、S、A、D)来控制蛇的移动方向,但不能直接反向移动。

void GameRoom::moveUP()
{QPointF leftTop;QPointF rightBottom;// 蛇头auto snakeNode = snakeList.front();int headX = snakeNode.x();int headY = snakeNode.y();// 如果穿模if(headY < 20){leftTop = QPointF(headX,this->height() - kSnakeNodeHeight);}else{leftTop = QPointF(headX,headY - kSnakeNodeHeight);}rightBottom = leftTop + QPointF(kSnakeNodeWight,kSnakeNodeHeight);snakeList.push_front(QRectF(leftTop,rightBottom));
}void GameRoom::moveDOWN()
{QPointF leftTop;QPointF rightBottom;auto snakeNode = snakeList.front();int headX = snakeNode.x();int headY = snakeNode.y();if(headY > this->height()){leftTop = QPointF(headX,0);}else{leftTop = snakeNode.bottomLeft();}rightBottom = leftTop + QPointF(kSnakeNodeWight,kSnakeNodeHeight);snakeList.push_front(QRectF(leftTop,rightBottom));
}void GameRoom::moveLEFT()
{QPointF leftTop;QPointF rightBottom;auto snakeNode = snakeList.front();int headX = snakeNode.x();int headY = snakeNode.y();if(headX < 0){leftTop = QPointF(800 - kSnakeNodeWight,headY);}else{leftTop = QPointF(headX - kSnakeNodeWight,headY);}rightBottom = leftTop + QPointF(kSnakeNodeWight,kSnakeNodeHeight);snakeList.push_front(QRectF(leftTop,rightBottom));
}void GameRoom::moveRIGHT()
{QPointF leftTop;QPointF rightBottom;auto snakeNode = snakeList.front();int headX = snakeNode.x();int headY = snakeNode.y();if(headX > 760){leftTop = QPointF(0,headY);}else{leftTop = snakeNode.topRight();}rightBottom = leftTop + QPointF(kSnakeNodeWight,kSnakeNodeHeight);snakeList.push_front(QRectF(leftTop,rightBottom));
}

三、结语

这个项目比较简单,通过这个项目,不仅可以学习到Qt的GUI开发和事件处理技术,还能熟悉C++编程及基本的游戏开发概念。关于Qt中的一些基础知识,我也会在后续逐步更新。

好了,源码我会放在下面,大家有兴趣的可以看一看,欢迎大家一键三连!!!

四、源码

https://gitee.com/hu-jiahao143/project/commit/f83b287c800dd105f8358d7ffb244202ebf015c9

http://www.mmbaike.com/news/48380.html

相关文章:

  • 网站建设的基础内容短视频询盘获客系统
  • 淄博百度网站建设信息流优化师前景
  • wordpress logo大小成都网站快速排名优化
  • 什么是网站代理bt鹦鹉磁力
  • 网页设计制作网站模板免费seo比较好的优化方法
  • 深圳学校网站建设报价域名查询ip
  • 网站建设显示危险常州百度seo排名
  • 免费建造网站百度推广账户登陆
  • 济南企业营销型网站建设优化游戏的软件
  • 做商城网站公司吗违禁网站用什么浏览器
  • 北京网站建设的公seo入门书籍推荐
  • 购买设备有什么网站做参考网上商城网站开发
  • 如何用天地图做网站建站之星网站
  • 上海松江网站建设百度一下百度一下你就知道
  • 给公众号做头像的网站代理怎么引流推广
  • 天津网站建设哪家做得好百度app免费下载安装最新版
  • 做网站开发多少钱爱链网买链接
  • 揭阳网站制作建设网络口碑营销的成功案例
  • 深圳工业设计工资优化科技
  • 做电商网站就业岗位晋升网页设计框架图
  • 阜宁做网站哪家最好深圳seo网站推广方案
  • 旅游网站开发实现开题报告新seo排名点击软件
  • 批发电商做的好的网站百度人工智能开放平台
  • 珠海营销营网站建设公司游戏推广文案
  • 免费发布网站建设信息windows10优化软件
  • 网站开发语言哪一种好些浙江新手网络推广
  • 永康城乡建设局网站邹平县seo网页优化外包
  • 找人做网站需要多少钱外贸网站建设
  • 大连做网站排名长春关键词优化公司
  • 正版厦门网站设计公司某个产品营销推广方案