#include <qapplication.h>#include<qpixmap.h>#include <qlabel.h>#include<qmovie.h>#include <QMouseEvent>#include<qbitmap>#include <qpainter.h>#include<qtime>#include<vector>#include<list>#include<qlist>bool yes=false;class Window : public QLabel {private: QPoint m_ptPosition;protected: /* virtual void Window::mousePressEvent(QMouseEvent* pe) { m_ptPosition = pe->pos(); }*/ /* virtual void Window::mouseMoveEvent(QMouseEvent* pe) { move(pe->globalPos() - m_ptPosition); }*/ virtual void Window::mousePressEvent(QMouseEvent* pe); virtual void keyPressEvent(QKeyEvent* e);public: Window(QWidget* pwgt = 0) : QLabel(pwgt,Qt::FramelessWindowHint | Qt::Window) { } void paintEvent( QPaintEvent * );void NewPix();int who_is,who_isx,who_isy;QPixmap *p[20];QMovie *pp[20];QPixmap *ball; QPoint m[6][5];int who[6][5];int sost[6][5];QList <int> kept;QList <int>:: iterator er;QLabel lbl;int schet;};void Window::NewPix(){int temp;schet=0; qint32 tx=80,ty=100; for(qint32 y=0;y<5;y++) { for(qint32 x=0;x<6;x++) {m[x][y].setX(tx); m[x][y].setY(ty); tx+=100; } tx=80; ty+=110; }QTime time;srand(time.second());for(int i=0;i<15;i++){temp=rand()%15; kept.append(temp); kept.append(temp);}for(int y=0;y<5;y++) { for(int x=0;x<6;x++) { temp=rand()%kept.count(); who[x][y]=kept.at(temp); kept.removeAt(temp); //kept.remove(temp); //schet++; }}//if(kept.count==0) exit(0);p[0]= new QPixmap( "img/1.png"); p[1]= new QPixmap( "img/2.png"); p[2]= new QPixmap( "img/3.png"); p[3]= new QPixmap( "img/4.png"); p[4]= new QPixmap( "img/5.png"); p[5]= new QPixmap( "img/6.png"); p[6]= new QPixmap( "img/7.png"); p[7]= new QPixmap( "img/8.png"); p[8]= new QPixmap( "img/9.png"); p[9]= new QPixmap( "img/10.png"); p[10]= new QPixmap( "img/11.png"); p[11]= new QPixmap( "img/12.png"); p[12]= new QPixmap( "img/13.png"); p[13]= new QPixmap( "img/14.png"); p[14]= new QPixmap( "img/15.png"); ball=new QPixmap( "img/16.png"); pp[0]= new QMovie( "img/1.gif"); pp[1]= new QMovie( "img/2.gif"); pp[2]= new QMovie( "img/3.gif"); pp[3]= new QMovie( "img/4.gif"); pp[4]= new QMovie( "img/5.gif"); pp[5]= new QMovie( "img/6.gif"); pp[6]= new QMovie( "img/7.gif"); pp[7]= new QMovie( "img/8.gif"); pp[8]= new QMovie( "img/9.gif"); pp[9]= new QMovie( "img/10.gif"); pp[10]= new QMovie( "img/11.gif"); pp[11]= new QMovie( "img/12.gif"); pp[12]= new QMovie( "img/13.gif"); pp[13]= new QMovie( "img/14.gif"); pp[14]= new QMovie( "img/15.gif"); for(int y=0;y<5;y++) for(int x=0;x<6;x++) sost[x][y]=0;who_is=-1;who_isx=-1;who_isy=-1;} void Window::mousePressEvent(QMouseEvent* pe) {//exit(0); int h=pe->x(),t=pe->y(); for(qint32 y=0;y<5;y++)for(qint32 x=0;x<6;x++){ if(m[x][y].x()<h && m[x][y].x()+75>h && m[x][y].y()<t && m[x][y].y()+100>t) if(sost[x][y]!=2) { if (who_is==who[x][y]){schet+=5;sost[x][y]=2; sost[who_isx][who_isy]=2;sost[x][y]==2; who_is=-1; update();} else if(who_is==-1) {who_is=who[x][y];who_isx=x;who_isy=y;sost[x][y]=1; update();} else if(who_is!=-1 && who_is!=who[x][y]) {who_is=-1;sost[who_isx][who_isy]=0;update(); } }} } void Window::paintEvent( QPaintEvent * ){ QPainter pip;QString st=QString::number(schet); pip.begin(this); pip.setFont(QFont("Times",25,QFont::Normal)); pip.drawPixmap(0,0,QPixmap("img/screen6.png")); pip.drawText(800,100,st); if(yes){for(qint32 y=0;y<5;y++)for(qint32 x=0;x<6;x++)if(sost[x][y]==0) pip.drawPixmap(m[x][y],*ball);elseif(sost[x][y]==1)pip.drawPixmap(m[x][y],*p[who[x][y]]);} pip.end();}void Window::keyPressEvent(QKeyEvent* e){ if(e->key()==Qt::Key_Return) exit(0); if(e->key()==Qt::Key_Space) {yes=true; update(); }}// ----------------------------------------------------------------------int main(int argc, char** argv){ QApplication app(argc, argv); Window win; QPixmap pix("img/screen6.png");win.NewPix();win.setWindowTitle("My games");win.move(30,30); win.setPixmap(pix); win.setMask(pix.mask()); //win.setBaseSize(1500,1500); win.setFixedHeight(800); win.setFixedWidth(1000); win.show(); return app.exec();}