热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

08翻金币游戏

mianscene类:游戏的开始界面mypushbutton类:为开始按钮和返回按钮封装的无边框的按钮控件chooselevelscene类

mianscene类:游戏的开始界面

mypushbutton类:为开始按钮和返回按钮封装的无边框的按钮控件

chooselevelscene类:选择游戏关卡的界面

playscene类:游戏的出场景

mycoin类:为金币封装的按钮

dataconfig类:游戏配置类

 


mainscene.h

#ifndef MAINSCENE_H
#define MAINSCENE_H#include
#include "chooselevelscene.h"namespace Ui {
class MainScene;
}class MainScene : public QMainWindow
{Q_OBJECTpublic:explicit MainScene(QWidget *parent = 0);~MainScene();void paintEvent(QPaintEvent *event);ChooseLevelScene *chooseScene = NULL;private:Ui::MainScene *ui;
};#endif // MAINSCENE_H

mainscene.cpp

#include "mainscene.h"
#include "ui_mainscene.h"
#include
#include "mypushbutton.h"
#include
#include
#include MainScene::MainScene(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainScene)
{ui->setupUi(this);//配置主场景//设置固定大小setFixedSize(320,588);//设置图标setWindowIcon(QIcon(":/res/Coin0001.png"));//设置标题setWindowTitle("翻金币主场景");connect(ui->actionquit, &QAction::triggered, [=](){this->close();});//开始音效QSound *startSound = new QSound(":/res/TapButtonSound.wav", this);//开始按钮MyPushButton *startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");startBtn->setParent(this);startBtn->move(this->width() * 0.5 - startBtn->width() * 0.5, this->height() * 0.7);//实例化选择关卡场景this->chooseScene = new ChooseLevelScene;//监听选择关卡的信号//监听代码要写在这里,不然没点击一次开始按钮就会执行一次connect(chooseScene, &ChooseLevelScene::chooseSceneBack, this, [=](){this->setGeometry(chooseScene->geometry());chooseScene->hide();this->show();});connect(startBtn, &MyPushButton::clicked, [=](){
// qDebug() <<"点击了开始按钮";//播放开始音效资源startSound->play();startBtn->zoom1();startBtn->zoom2();//延时进入到选择关卡中QTimer::singleShot(500, this, [&#61;](){//设置chooseScene场景的位置chooseScene->setGeometry(this->geometry());//自身隐藏this->hide();//显示chooseScene->show();});});
}void MainScene::paintEvent(QPaintEvent *event) {QPainter painter(this);QPixmap pix;pix.load(":/res/PlayLevelSceneBg.png");//自适应painter.drawPixmap(0, 0, this->width(), this->height(), pix);//画背景上的图标pix.load(":/res/Title.png");pix &#61; pix.scaled(pix.width() *0.5, pix.height()*0.5);painter.drawPixmap(10,30,pix);}MainScene::~MainScene()
{delete ui;
}

mypushbutton.h

#ifndef MYPUSHBUTTON_H
#define MYPUSHBUTTON_H#include class MyPushButton : public QPushButton
{Q_OBJECT
public:
// explicit MyPushButton(QWidget *parent &#61; nullptr);MyPushButton(QString normalImg, QString pressImg &#61; "");QString nornalImgPath;QString PressImgPath;void mousePressEvent(QMouseEvent *e);void mouseReleaseEvent(QMouseEvent *e);//弹跳特效void zoom1(); //向下跳void zoom2(); //向上跳signals:public slots:
};#endif // MYPUSHBUTTON_H

mypushbutton.cpp

#include "mypushbutton.h"
#include
#include MyPushButton::MyPushButton(QString normalImg, QString pressImg) {this->nornalImgPath &#61; normalImg;this->PressImgPath &#61; pressImg;QPixmap pix;bool ret &#61; pix.load(normalImg);if (!ret) {qDebug() <<"图片加载失败";return;}//设置图片固定大小this->setFixedSize(pix.width(), pix.height());//设置不规则图片样式this->setStyleSheet("QPushButton{border:0px}");//设置图标this->setIcon(pix);//设置图标大小this->setIconSize(QSize(pix.width(), pix.height()));
}
void MyPushButton::zoom1() {//创建动态对象QPropertyAnimation *animation &#61; new QPropertyAnimation(this, "geometry");//设置动画的时间间隔animation->setDuration(200);//起始位置animation->setStartValue(QRect(this->x(), this->y(), this->width(), this->height()));//结束为止animation->setEndValue(QRect(this->x(), this->y()&#43;10, this->width(), this->height()));//设置弹跳曲线animation->setEasingCurve(QEasingCurve::OutBounce);//执行动画animation->start();
}void MyPushButton::zoom2() {//创建动态对象QPropertyAnimation *animation &#61; new QPropertyAnimation(this, "geometry");//设置动画的时间间隔animation->setDuration(200);//起始位置animation->setStartValue(QRect(this->x(), this->y()&#43;10, this->width(), this->height()));//结束为止animation->setEndValue(QRect(this->x(), this->y(), this->width(), this->height()));//设置弹跳曲线animation->setEasingCurve(QEasingCurve::OutBounce);//执行动画animation->start();
}void MyPushButton::mousePressEvent(QMouseEvent *e) {if(this->PressImgPath !&#61; "") {QPixmap pix;bool ret &#61; pix.load(this->PressImgPath);if (!ret) {qDebug() <<"图片加载失败";return;}//设置图片固定大小this->setFixedSize(pix.width(), pix.height());//设置不规则图片样式this->setStyleSheet("QPushButton{border:0px}");//设置图标this->setIcon(pix);//设置图标大小this->setIconSize(QSize(pix.width(), pix.height()));}//让父类执行其他的内容return QPushButton::mousePressEvent(e);
}void MyPushButton::mouseReleaseEvent(QMouseEvent *e) {if(this->PressImgPath !&#61; "") {QPixmap pix;bool ret &#61; pix.load(this->nornalImgPath);if (!ret) {qDebug() <<"图片加载失败";return;}//设置图片固定大小this->setFixedSize(pix.width(), pix.height());//设置不规则图片样式this->setStyleSheet("QPushButton{border:0px}");//设置图标this->setIcon(pix);//设置图标大小this->setIconSize(QSize(pix.width(), pix.height()));}//让父类执行其他的内容return QPushButton::mouseReleaseEvent(e);
}
//MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
//{//}

chooselevelscene.h

#ifndef CHOOSELEVELSCENE_H
#define CHOOSELEVELSCENE_H#include
#include class ChooseLevelScene : public QMainWindow
{Q_OBJECT
public:explicit ChooseLevelScene(QWidget *parent &#61; nullptr);void paintEvent(QPaintEvent *event);//游戏场景指针PlayScene *play &#61; NULL;signals:void chooseSceneBack();
public slots:
};#endif // CHOOSELEVELSCENE_H

chooselevelscene.cpp

#include "chooselevelscene.h"
#include
#include
#include "mypushbutton.h"
#include
#include
#include
#include ChooseLevelScene::ChooseLevelScene(QWidget *parent) : QMainWindow(parent)
{this->setFixedSize(320, 588);this->setWindowIcon(QPixmap(":/res/Coin0001.png"));this->setWindowTitle("选择关卡场景");QMenuBar *bar &#61; menuBar();setMenuBar(bar);QMenu *startMenu &#61; bar->addMenu("开始");QAction *quitAction &#61; startMenu->addAction("退出");connect(quitAction, &QAction::triggered, [&#61;](){this->close();});//选择关卡音效QSound *chooseSound &#61; new QSound(":/res/TapButtonSound.wav", this);//返回按钮音效QSound *backSound &#61; new QSound(":/res/BackButtonSound.wav", this);//返回按钮MyPushButton *backBtn &#61; new MyPushButton(":/res/BackButton.png", ":/res/BackButtonSelected.png");backBtn->setParent(this);backBtn->move(this->width() - backBtn->width(), this->height() - backBtn->height());connect(backBtn, &MyPushButton::clicked, [&#61;](){
// qDebug() <<"点击了返回按钮";backSound->play();//延时返回QTimer::singleShot(200, this, [&#61;](){emit this->chooseSceneBack();});});//创建选择关卡的按钮for (int i &#61; 0; i <20; i&#43;&#43;) {MyPushButton *menuBtn &#61; new MyPushButton(":/res/LevelIcon.png");menuBtn->setParent(this);menuBtn->move(25 &#43; i%4 * 70, 130 &#43; i / 4 * 70);//监听每个按钮的点击事件connect(menuBtn, &MyPushButton::clicked, [&#61;](){chooseSound->play();QString str &#61; QString("您选择的是第 %1 关").arg(i &#43; 1);qDebug() <hide();this->play &#61; new PlayScene(i &#43; 1);//设置游戏场景的初始位置play->setGeometry(this->geometry());play->show();connect(play, &PlayScene::chooseSceneBack, [&#61;](){this->setGeometry(play->geometry());this->show();// 因为每关不一样&#xff0c;所以要delete掉比较好delete play;play &#61; NULL;});});QLabel *label &#61; new QLabel;label->setParent(this);label->setFixedSize(menuBtn->width(), menuBtn->height());label->setText(QString::number(i&#43;1));label->move(25 &#43; i%4 * 70, 130 &#43; i / 4 * 70);//设置 水平居中和垂直居中label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);//设置鼠标穿透 51号属性label->setAttribute(Qt::WA_TransparentForMouseEvents);}
}void ChooseLevelScene::paintEvent(QPaintEvent *event) {//加载背景QPainter painter(this);QPixmap pix;pix.load(":/res/OtherSceneBg.png");painter.drawPixmap(0, 0, this->width(), this->height(), pix);//加载标题pix.load(":/res/Title.png");painter.drawPixmap(this->width() * 0.5 - pix.width() * 0.5, 30, pix.width(), pix.height(), pix);
}

mycoin.h

#ifndef MYCOIN_H
#define MYCOIN_H#include
#include class MyCoin : public QPushButton
{Q_OBJECT
public:
// explicit MyCoin(QWidget *parent &#61; nullptr);//参数代表传入的是金币路径还是银币路径MyCoin(QString btnImg);//金币的属性int posX;int posY;//金币的正反面 正true 反falsebool flag;//改变标志的方法void changeFlag();QTimer *timer1;QTimer *timer2;int min &#61; 1;int max &#61; 8;//执行动画的标志&#xff0c;防止在未执行完动画的时候点击按钮bool isAnimation &#61; false;//重写按下 释放void mousePressEvent(QMouseEvent *e);//用于胜利后每个按钮停止翻转bool isWin &#61; false;signals:public slots:
};#endif // MYCOIN_H

mycoin.cpp

#include "mycoin.h"
#include MyCoin::MyCoin(QString btnImg) {QPixmap pix;bool ret &#61; pix.load(btnImg);if (!ret) {QString str&#61; QString("图片 %1 加载失败").arg(btnImg);qDebug() <setFixedSize(pix.width(), pix.height());this->setStyleSheet("QPushButton{border:0px;}");this->setIcon(pix);this->setIconSize(QSize(pix.width(), pix.height()));//初始化定时器对象this->timer1 &#61; new QTimer(this);this->timer2 &#61; new QTimer(this);connect(timer1, &QTimer::timeout, [&#61;](){QPixmap pix;QString str &#61; QString(":/res/Coin000%1.png").arg(this->min&#43;&#43;);pix.load(str);this->setFixedSize(pix.width(), pix.height());this->setStyleSheet("QPushButton{border:0px;}");this->setIcon(pix);this->setIconSize(QSize(pix.width(), pix.height()));//判断如果翻完了&#xff0c;将min重置为1if (this->min > this->max) {this->min &#61; 1;this->isAnimation &#61; false;timer1->stop();}});connect(timer2, &QTimer::timeout, [&#61;](){QPixmap pix;QString str &#61; QString(":/res/Coin000%1.png").arg(this->max--);pix.load(str);this->setFixedSize(pix.width(), pix.height());this->setStyleSheet("QPushButton{border:0px;}");this->setIcon(pix);this->setIconSize(QSize(pix.width(), pix.height()));//判断如果翻完了&#xff0c;将min重置为1if (this->max min) {this->max &#61; 8;this->isAnimation &#61; false;timer2->stop();}});
}void MyCoin::changeFlag() {if (this->flag) {timer1->start(30);this->isAnimation &#61; true;this->flag &#61; false;} else {timer2->start(30);this->isAnimation &#61; true;this->flag &#61; true;}
}void MyCoin::mousePressEvent(QMouseEvent *e) {if (this->isAnimation || this->isWin) { //胜利后屏蔽点击return;} else {QPushButton::mousePressEvent(e);}
}//MyCoin::MyCoin(QWidget *parent) : QPushButton(parent)
//{//}

playscene.h

#ifndef PLAYSCENE_H
#define PLAYSCENE_H#include
#include class PlayScene : public QMainWindow
{Q_OBJECT
public:
// explicit PlayScene(QWidget *parent &#61; nullptr);PlayScene(int levelNum);int levelIndex;void paintEvent(QPaintEvent *event);int gameArray[4][4];MyCoin *coinBtn[4][4];bool isWin;
signals:void chooseSceneBack();
public slots:
};#endif // PLAYSCENE_H

playscene.cpp

#include "playscene.h"
#include
#include
#include
#include "mypushbutton.h"
#include
#include
#include "mycoin.h"
#include "dataconfig.h"
#include
#include PlayScene::PlayScene(int levelNum) {QString str &#61; QString("进入了第 1% 关").arg(levelNum);qDebug() <levelIndex &#61; levelNum;//初始化游戏场景this->setFixedSize(320,588);this->setWindowIcon(QPixmap(":/res/Coin0001.png"));this->setWindowTitle("翻金币场景");//点击按钮 实现退出游戏QMenuBar *bar &#61; menuBar();setMenuBar(bar);QMenu *startMenu &#61; bar->addMenu("开始");QAction *quitAction &#61; startMenu->addAction("退出");connect(quitAction, &QAction::triggered, [&#61;](){this->close();});//添加音效QSound *backSound &#61; new QSound(":/res/BackButtonSound.wav", this);QSound *flipSound &#61; new QSound(":/res/ConFlipSound.wav", this);QSound *winSound &#61; new QSound(":/res/LevelWinSound.wav", this);//返回按钮MyPushButton *backBtn &#61; new MyPushButton(":/res/BackButton.png", ":/res/BackButtonSelected.png");backBtn->setParent(this);backBtn->move(this->width() - backBtn->width(), this->height() - backBtn->height());connect(backBtn, &MyPushButton::clicked, [&#61;](){qDebug() <<"返金币场景中点击了返回按钮";backSound->play();QTimer::singleShot(200, this, [&#61;](){emit this->chooseSceneBack();});});//显示当前的关卡数QLabel *label &#61; new QLabel;label->setParent(this);QFont font;font.setFamily("华文新魏");font.setPointSize(20);label->setFont(font);QString str1 &#61; QString("Level:%1").arg(this->levelIndex);label->setText(str1);label->setGeometry(30, this->height() - 50, 120, 50);//初始化每个关卡的二维数组dataConfig config;for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {this->gameArray[i][j] &#61; config.mData[this->levelIndex][i][j];}}//胜利图片的显示QLabel *winLabel &#61; new QLabel;QPixmap pix;pix.load(":/res/LevelCompletedDialogBg.png");winLabel->setGeometry(0,0,pix.width(),pix.height());winLabel->setPixmap(pix);winLabel->setParent(this);winLabel->move((this->width() - pix.width()) * 0.5, -pix.height());//显示金币背景图案for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {QPixmap pix &#61; QPixmap(":/res/BoardNode.png");QLabel *label &#61; new QLabel;label->setGeometry(0,0,pix.width(),pix.height()); //几何label->setPixmap(pix);label->setParent(this);label->move(57 &#43; i*50, 200 &#43; j*50);//创建金币if (this->gameArray[i][j] &#61;&#61; 1) {//显示金币str &#61; ":/res/Coin0001.png";} else {//显示银币str &#61; ":/res/Coin0008.png";}MyCoin *coin &#61; new MyCoin(str);coin->setParent(this);coin->move(59 &#43; i*50, 204 &#43; j*50);//给金币的属性赋值coin->posX &#61; i;coin->posY &#61; j;coin->flag &#61; this->gameArray[i][j]; //1正面 0反面//将金币放入金币的二维数组&#xff0c;以便后期的维护coinBtn[i][j] &#61; coin;//点击金币 进行翻转connect(coin, &MyCoin::clicked, [&#61;](){//点击后仅用所有金币,以防胜利时手快点击其他的按钮再进行无用的反转flipSound->play();for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {this->coinBtn[i][j]->isWin &#61; true;}}coin->changeFlag();this->gameArray[i][j] &#61; this->gameArray[i][j] &#61;&#61; 0 ? 1 : 0;//翻转周围的金币&#xff0c;延时翻转QTimer::singleShot(300, this, [&#61;](){if (coin->posX &#43; 1 <&#61; 3) { //右侧//翻转coinBtn[coin->posX &#43; 1][coin->posY]->changeFlag();//维护正反面数组this->gameArray[coin->posX &#43; 1][coin->posY] &#61;this->gameArray[coin->posX &#43; 1][coin->posY] &#61;&#61; 0 ? 1 : 0;}if (coin->posX - 1 >&#61; 0) { //左侧coinBtn[coin->posX - 1][coin->posY]->changeFlag();this->gameArray[coin->posX - 1][coin->posY] &#61;this->gameArray[coin->posX - 1][coin->posY] &#61;&#61; 0 ? 1 : 0;}if (coin->posY &#43; 1 <&#61; 3) { //下侧coinBtn[coin->posX][coin->posY &#43; 1]->changeFlag();this->gameArray[coin->posX][coin->posY &#43; 1] &#61;this->gameArray[coin->posX][coin->posY &#43; 1] &#61;&#61; 0 ? 1 : 0;}if (coin->posY - 1 >&#61; 0) { //上侧coinBtn[coin->posX][coin->posY - 1]->changeFlag();this->gameArray[coin->posX][coin->posY - 1] &#61;this->gameArray[coin->posX][coin->posY - 1] &#61;&#61; 0 ? 1 : 0;}//翻转完成后解开禁用for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {this->coinBtn[i][j]->isWin &#61; false;}}//判断是否胜利this->isWin &#61; true;for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {if (coinBtn[i][j]->flag &#61;&#61; false) { //flag是coin中表示正反面的标志this->isWin &#61; false;break;}}}if (this->isWin &#61;&#61; true) {winSound->play();qDebug() <<"游戏胜利";for (int i &#61; 0; i <4; i&#43;&#43;) {for (int j &#61; 0; j <4; j&#43;&#43;) {coinBtn[i][j]->isWin &#61; true;}}//将胜利的图片移动下来QPropertyAnimation *animation &#61; new QPropertyAnimation(winLabel, "geometry");//设置时间间隔animation->setDuration(1000);//设置开始位置animation->setStartValue(QRect(winLabel->x(), winLabel->y(), winLabel->width(), winLabel->height()));//设置结束位置animation->setEndValue(QRect(winLabel->x(), winLabel->y()&#43;114, winLabel->width(), winLabel->height()));//设置缓和曲线animation->setEasingCurve(QEasingCurve::OutBounce);//执行动画animation->start();}});});}}
}void PlayScene::paintEvent(QPaintEvent *event) {QPainter painter(this);QPixmap pix;pix.load(":/res/PlayLevelSceneBg.png");painter.drawPixmap(0,0,this->width(),this->height(),pix);pix.load(":/res/Title.png");pix &#61; pix.scaled(pix.width()*0.5, pix.height()*0.5);painter.drawPixmap(10, 30, pix.width(), pix.height(), pix);
}//PlayScene::PlayScene(QWidget *parent) : QMainWindow(parent)
//{//}

dataconfig.h

#ifndef DATACONFIG_H
#define DATACONFIG_H#include
#include
#include class dataConfig : public QObject
{Q_OBJECT
public:explicit dataConfig(QObject *parent &#61; 0);public:QMap > >mData;signals:public slots:
};#endif // DATACONFIG_H

dataconfig.cpp

#include "dataconfig.h"
#include
dataConfig::dataConfig(QObject *parent) : QObject(parent)
{int array1[4][4] &#61; {{1, 1, 1, 1},{1, 1, 0, 1},{1, 0, 0, 0},{1, 1, 0, 1} } ;QVector> v;for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array1[i][j]);}v.push_back(v1);}mData.insert(1,v);int array2[4][4] &#61; { {1, 0, 1, 1},{0, 0, 1, 1},{1, 1, 0, 0},{1, 1, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array2[i][j]);}v.push_back(v1);}mData.insert(2,v);int array3[4][4] &#61; { {0, 0, 0, 0},{0, 1, 1, 0},{0, 1, 1, 0},{0, 0, 0, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array3[i][j]);}v.push_back(v1);}mData.insert(3,v);int array4[4][4] &#61; { {0, 1, 1, 1},{1, 0, 0, 1},{1, 0, 1, 1},{1, 1, 1, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array4[i][j]);}v.push_back(v1);}mData.insert(4,v);int array5[4][4] &#61; { {1, 0, 0, 1},{0, 0, 0, 0},{0, 0, 0, 0},{1, 0, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array5[i][j]);}v.push_back(v1);}mData.insert(5,v);int array6[4][4] &#61; { {1, 0, 0, 1},{0, 1, 1, 0},{0, 1, 1, 0},{1, 0, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array6[i][j]);}v.push_back(v1);}mData.insert(6,v);int array7[4][4] &#61; { {0, 1, 1, 1},{1, 0, 1, 1},{1, 1, 0, 1},{1, 1, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array7[i][j]);}v.push_back(v1);}mData.insert(7,v);int array8[4][4] &#61; { {0, 1, 0, 1},{1, 0, 0, 0},{0, 0, 0, 1},{1, 0, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array8[i][j]);}v.push_back(v1);}mData.insert(8,v);int array9[4][4] &#61; { {1, 0, 1, 0},{1, 0, 1, 0},{0, 0, 1, 0},{1, 0, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array9[i][j]);}v.push_back(v1);}mData.insert(9,v);int array10[4][4] &#61; { {1, 0, 1, 1},{1, 1, 0, 0},{0, 0, 1, 1},{1, 1, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array10[i][j]);}v.push_back(v1);}mData.insert(10,v);int array11[4][4] &#61; { {0, 1, 1, 0},{1, 0, 0, 1},{1, 0, 0, 1},{0, 1, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array11[i][j]);}v.push_back(v1);}mData.insert(11,v);int array12[4][4] &#61; { {0, 1, 1, 0},{0, 0, 0, 0},{1, 1, 1, 1},{0, 0, 0, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array12[i][j]);}v.push_back(v1);}mData.insert(12,v);int array13[4][4] &#61; { {0, 1, 1, 0},{0, 0, 0, 0},{0, 0, 0, 0},{0, 1, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array13[i][j]);}v.push_back(v1);}mData.insert(13,v);int array14[4][4] &#61; { {1, 0, 1, 1},{0, 1, 0, 1},{1, 0, 1, 0},{1, 1, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array14[i][j]);}v.push_back(v1);}mData.insert(14,v);int array15[4][4] &#61; { {0, 1, 0, 1},{1, 0, 0, 0},{1, 0, 0, 0},{0, 1, 0, 1}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array15[i][j]);}v.push_back(v1);}mData.insert(15,v);int array16[4][4] &#61; { {0, 1, 1, 0},{1, 1, 1, 1},{1, 1, 1, 1},{0, 1, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array16[i][j]);}v.push_back(v1);}mData.insert(16,v);int array17[4][4] &#61; { {0, 1, 1, 1},{0, 1, 0, 0},{0, 0, 1, 0},{1, 1, 1, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array17[i][j]);}v.push_back(v1);}mData.insert(17,v);int array18[4][4] &#61; { {0, 0, 0, 1},{0, 0, 1, 0},{0, 1, 0, 0},{1, 0, 0, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array18[i][j]);}v.push_back(v1);}mData.insert(18,v);int array19[4][4] &#61; { {0, 1, 0, 0},{0, 1, 1, 0},{0, 0, 1, 1},{0, 0, 0, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array19[i][j]);}v.push_back(v1);}mData.insert(19,v);int array20[4][4] &#61; { {0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}} ;v.clear();for(int i &#61; 0 ; i <4;i&#43;&#43;){QVectorv1;for(int j &#61; 0 ; j <4;j&#43;&#43;){v1.push_back(array20[i][j]);}v.push_back(v1);}mData.insert(20,v);//测试数据
// for( QMap > >::iterator it &#61; mData.begin();it !&#61; mData.end();it&#43;&#43; )
// {
// for(QVector >::iterator it2 &#61; (*it).begin(); it2!&#61; (*it).end();it2&#43;&#43;)
// {
// for(QVector::iterator it3 &#61; (*it2).begin(); it3 !&#61; (*it2).end(); it3&#43;&#43; )
// {
// qDebug() <<*it3 ;
// }
// }
// qDebug() <// }}

 

 

 

 


推荐阅读
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • Java容器中的compareto方法排序原理解析
    本文从源码解析Java容器中的compareto方法的排序原理,讲解了在使用数组存储数据时的限制以及存储效率的问题。同时提到了Redis的五大数据结构和list、set等知识点,回忆了作者大学时代的Java学习经历。文章以作者做的思维导图作为目录,展示了整个讲解过程。 ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文详细介绍了Java中vector的使用方法和相关知识,包括vector类的功能、构造方法和使用注意事项。通过使用vector类,可以方便地实现动态数组的功能,并且可以随意插入不同类型的对象,进行查找、插入和删除操作。这篇文章对于需要频繁进行查找、插入和删除操作的情况下,使用vector类是一个很好的选择。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
  • 模板引擎StringTemplate的使用方法和特点
    本文介绍了模板引擎StringTemplate的使用方法和特点,包括强制Model和View的分离、Lazy-Evaluation、Recursive enable等。同时,还介绍了StringTemplate语法中的属性和普通字符的使用方法,并提供了向模板填充属性的示例代码。 ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • 本文介绍了一个Java猜拳小游戏的代码,通过使用Scanner类获取用户输入的拳的数字,并随机生成计算机的拳,然后判断胜负。该游戏可以选择剪刀、石头、布三种拳,通过比较两者的拳来决定胜负。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
author-avatar
陳小勳2502936731
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有