代码拉取完成,页面将自动刷新
#include "qpushbox.h"
#include "ui_qpushbox.h"
#include"QAction"
#include"widget.h"
#include"qpushbutton.h"
#include"QMessageBox"
#include"makemap.h"
QpushBox::QpushBox(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::QpushBox)
{
ui->setupUi(this);
//界面的设置
this->setFixedSize(800,655);
this->setWindowIcon(QIcon(":/image/Man.png"));
mpainter=new QPainter(this);
//按钮的设置
QFont f1("宋体",13);
but=new QPushButton(this);
but->move(190,420);
but->resize(100,50);
but->setText("开始游戏");
but->setFont(f1);
connect(but,&QPushButton::clicked,this,&QpushBox::startGame);
but1=new QPushButton(this);
but1->move(500,420);
but1->resize(100,50);
but1->setText("退出游戏");
but1->setFont(f1);
connect(but1,&QPushButton::clicked,this,&QApplication::quit);
but2=new QPushButton(this);
but2->move(190,500);
but2->resize(100,50);
but2->setFont(f1);
but2->setText("自制地图");
connect(but2,&QPushButton::clicked,this,[this](){this->w->show();});
//菜单的设置
createMenu();
createAction();
setWindowTitle(QStringLiteral("推箱子"));
}
//画图时间函数
void QpushBox::paintEvent(QPaintEvent*event)
{
mpainter->begin(this);
QPainter BackgroundPainter(this);
BackgroundPainter.drawImage(QRect(0,30,800,628),QImage("://image/background1.jpg"));
mpainter->end();
}
//创建菜单
void QpushBox::createMenu()
{
startGameAction=new QAction("开始游戏",this);
startGameAction->setShortcut(QKeySequence("Ctrl+S"));//设置快捷键
startGameAction->setStatusTip(QStringLiteral("开始一场游戏"));
connect(startGameAction,&QAction::triggered,this,&QpushBox::startGame);
aboutAction=new QAction(QStringLiteral("关于"),this);
aboutAction->setShortcut(QKeySequence("Ctrl+A"));
aboutAction->setStatusTip(QStringLiteral("关于我"));
connect(aboutAction,&QAction::triggered,this,&QpushBox::showabout);
helpAction=new QAction(QStringLiteral("如何操作"),this);
helpAction->setShortcut(QKeySequence("Ctrl+H"));
helpAction->setStatusTip(QStringLiteral("如何操纵游戏"));
connect(helpAction,&QAction::triggered,this,&QpushBox::showhelp);
speAction=new QAction("版权声明",this);
speAction->setStatusTip("版权声明");
connect(speAction,&QAction::triggered,this,&QpushBox::showspe);
//其他动作的实现
}
//展示相关信息
void QpushBox::showspe()
{
QMessageBox::information(this,QStringLiteral("声明"),"游戏中图片资源、音频资源均来源于网络。<br>部分音频资源:HOYO-Mix 醵饮同饮 Toast to Coast <br> HOYO-Mix 埠上风光 What a Delightful Scenery <br> HOYO-Mix 咏歌与凯旋 Lamentation et triomphe <br>仅供学习使用,如侵权作者将删除");
}
void QpushBox::showhelp()
{
QMessageBox::information(this,QStringLiteral("操作"),QStringLiteral("你可以通过上下左右、WASD、鼠标(双击左键向左、双击右键向右、向上滚动向上、向下滚动向下)来控制小人的方向。"
"<br>将所有“箱子”推到目标位置即为通关。"));
}
void QpushBox::showabout()
{
QMessageBox::information(this,"关于游戏","经典的推箱子是一个来自日本的古老游戏,目的是在训练你的逻辑思考能力。在一个狭小的仓库中,要求把木箱放到指定的位置,稍不小心就会出现箱子无法移动或者通道被堵住的情况,所以需要巧妙的利用有限的空间和通道,合理安排移动的次序和位置,才能顺利的完成任务。"
"<br>作者为推箱子游戏增添更多玩法,通过自制地图,为玩家发挥自主性提供空间。""<br>通关所有地图,自制地图,发给你的朋友。ps:内置关卡不止三关,试试找找彩蛋地图吧!");
}
void QpushBox::createAction()
{
gameMenu=menuBar()->addMenu(QStringLiteral("游戏"));
gameMenu->addAction(startGameAction);
helpMenu=menuBar()->addMenu(QStringLiteral("帮助"));
helpMenu->addAction(aboutAction);
helpMenu->addAction(helpAction);
speMenu=menuBar()->addMenu("声明");
speMenu->addAction(speAction);
}
//游戏开始函数
void QpushBox::startGame()
{
this->hide();
m->show();
QMessageBox::information(nullptr,"提示","在你面前的小人就是你的操作对象,将所有“箱子”放入目标处,就通过了本关。点击上方的按钮可以选择关卡,也可以重新开始对应关卡。快来试试吧""<br>选择关卡后,可以选择是否打开音乐,请注意音量");
}
QpushBox::~QpushBox()
{
delete m;
delete w;
delete ui;
delete but;
delete but1;
delete but2;
delete mpainter;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。