1. 程式人生 > >QT/c++ 簡易俄羅斯方塊

QT/c++ 簡易俄羅斯方塊

第一次用QT寫的小專案,一切為了實現效果不擇手段,沒注意優化演算法什麼,後期也懶得去改了,遊戲目前還有個小bug,消兩行只加一行的分數,懶鬼實在不想改了。
此文單純留作記錄。
另外樣式表內容參考《QT CREATOR快速入門第三版》,不得不說這本書對於萌新真的很友好。

大概介面
大佬輕噴。



首介面fuck標頭檔案
 
 
#ifndef FUCK_H
#define FUCK_H

#include <QDialog>

namespace Ui {
class Fuck;
}

class Fuck : public QDialog
{
    Q_OBJECT

public:
    explicit Fuck(QWidget *parent = 0);
    ~Fuck();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::Fuck *ui;
};

#endif // FUCK_H

首介面CPP檔案

#include "fuck.h"
#include "ui_fuck.h"

Fuck::Fuck(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Fuck)
{
    ui->setupUi(this);
}

Fuck::~Fuck()
{
    delete ui;
}

void Fuck::on_pushButton_clicked()
{
    accept();
}

void Fuck::on_pushButton_2_clicked()
{
    exit(0);
}
選擇難度介面 .h
#ifndef LAST_SELECT_H
#define LAST_SELECT_H
#include"fuck.h"
#include <QDialog>

namespace Ui {
class Last_select;
}

class Last_select : public QDialog
{
    Q_OBJECT

public:
    explicit Last_select(QWidget *parent = 0);
    ~Last_select();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_pushButton_3_clicked();

    void on_pushButton_4_clicked();

private:
    Ui::Last_select *ui;
    int x;
signals:
    void send_hell(int x);
     void send_king(int x);
      void send_mortal(int x);
};

選擇難度介面 .cpp

#include "last_select.h"
#include "ui_last_select.h"


Last_select::Last_select(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Last_select)
{
    ui->setupUi(this);
    this->setWindowTitle("選擇");
}

Last_select::~Last_select()
{
    delete ui;
}

void Last_select::on_pushButton_clicked()
{

        x=60;
        emit send_hell(x);
        accept();
}

void Last_select::on_pushButton_2_clicked()
{
     x=120;
    emit send_king(x);
   accept();
}

void Last_select::on_pushButton_3_clicked()
{
     x=250;
    emit send_mortal(x);
    accept();
}

void Last_select::on_pushButton_4_clicked()
{
    Fuck x;
    x.exec();
   // this->close();
}
遊戲介面.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QPainter>
#include<QTimer>
#include<QKeyEvent>
#include<QLabel>
#include<QDebug>
#include<QTime>
#include"newhead.h"
#include"last_select.h"
namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    bool fallToGround(QVector<QPointF>x);
    bool touchSide(QVector<QPointF>x);
    bool keyPress;
    bool freeze(QVector<QPointF>x);
    void rotate_p(QPointF base,QPointF& x);
    void clearGround();
    void cleardate();
    void change_showtime_x();
    int speed;
private:
    Ui::Widget *ui;
    int direction;
    int showtime_x;
    QString str_score;
    QLabel* scorelabel;
    QLabel*  scoreshow;
    QTimer* timer;
     QPointF poly1_1; QPointF poly1_2; QPointF poly1_3; QPointF poly1_4;
     QPointF poly2_1; QPointF poly2_2; QPointF poly2_3; QPointF poly2_4;
     QPointF poly3_1; QPointF poly3_2; QPointF poly3_3; QPointF poly3_4;
     QPointF poly4_1; QPointF poly4_2; QPointF poly4_3; QPointF poly4_4;
     QPointF poly5_1; QPointF poly5_2; QPointF poly5_3; QPointF poly5_4;
    QVector<QPointF>point_poly1;QVector<int>point_poly1_color;
    QVector<QPointF>point_poly2;QVector<int>point_poly2_color;
    QVector<QPointF>point_poly3;QVector<int>point_poly3_color;
    QVector<QPointF>point_poly4;QVector<int>point_poly4_color;
    QVector<QPointF>point_poly5;QVector<int>point_poly5_color;
    QVector<QPointF>tmp;QVector<int>tmp_color;
    QVector<QVector<QPointF>>Sum_poly;QVector<QVector<int>>Sum_poly_color;
    Last_select* select;
    int score;
    QVector<QPointF> rand_tmp;
    int x_fortest;//用於測試

protected:
    void paintEvent(QPaintEvent*);
    void keyPressEvent(QKeyEvent *event);
signals:
    void signal_rotate();
    void gameover();
public slots:
    void timeUpDate();//預設下墜
    void rotate_block();//注意旋轉的時候打破兩邊邊界要考慮//是否和固定多邊形重合也要考慮
    void restart();//廢棄
    void get_mortal(int x);
    void get_king(int x);
    void get_hell(int x);

};
#endif // WIDGET_H


 遊戲介面.cpp 
 

#include "widget.h"
#include "ui_widget.h"
#include<QImage>
#include<QMessageBox>
class degree_Select;
#define Side_L 20

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    qDebug("建構函式");
    x_fortest=0;
    select=new Last_select ();
    connect(select,SIGNAL(send_hell(int)),this,SLOT(get_hell(int)));
    connect(select,SIGNAL(send_king(int)),this,SLOT(get_king(int)));
    connect(select,SIGNAL(send_mortal(int)),this,SLOT(get_mortal(int)));
    select->exec();

    QPalette palette;
    palette.setBrush(QPalette::Background,QBrush(QPixmap(":/image/bg.png").scaled(this->size())));
    this->setPalette(palette);
    this->setWindowTitle(tr("俄俄俄……俄羅斯方塊"));
     this->setWindowIcon(QIcon(":/image/icon.png"));
    this->resize(640,480);
    this->setMaximumSize(640,480);

    score=0;
    keyPress=0;


    QFont font;
    font.setFamily("Consolas");
    font.setBold(true);
    font.setPixelSize(19);

    scorelabel=new QLabel("分數:",this);
    scorelabel->setFont(font);
    scorelabel->setGeometry(QRect(520,0,60,30));
    scorelabel->setStyleSheet("color:rbga(255,225,255,200)");

    scoreshow=new QLabel(this);
    scoreshow->setFont(font);
    scoreshow->setGeometry(QRect(580,0,60,30));
    scoreshow->setStyleSheet("color:rbga(255,225,255,200)");


    qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
    int showtime_x=qrand()%25;
     poly1_1.rx()=0+Side_L*showtime_x;poly1_1.ry()=0;//(20+Side_L*showtime_x,20);
     poly1_2.rx()=20+Side_L*showtime_x;poly1_2.ry()=0;//(20+Side_L*showtime_x,40);//(40,20);
     poly1_3.rx()=0+Side_L*showtime_x;poly1_3.ry()=20;//poly1_3(40+Side_L*showtime_x,40);//(40,40);
     poly1_4.rx()=20+Side_L*showtime_x;poly1_4.ry()=20;
    point_poly1.push_back(poly1_1);point_poly1_color.push_back(1);
    point_poly1.push_back(poly1_2);point_poly1_color.push_back(1);
    point_poly1.push_back(poly1_3);point_poly1_color.push_back(1);
    point_poly1.push_back(poly1_4);point_poly1_color.push_back(1);

    poly2_1.rx()=0+Side_L*showtime_x;poly2_1.ry()=0;
    poly2_2.rx()=0+Side_L*showtime_x;poly2_2.ry()=20;
    poly2_3.rx()=20+Side_L*showtime_x;poly2_3.ry()=20;
    poly2_4.rx()=20+Side_L*showtime_x;poly2_4.ry()=40;

    point_poly2.push_back(poly2_1);point_poly2_color.push_back(2);
    point_poly2.push_back(poly2_2);point_poly2_color.push_back(2);
    point_poly2.push_back(poly2_3);point_poly2_color.push_back(2);
    point_poly2.push_back(poly2_4);point_poly2_color.push_back(2);


    poly3_1.rx()=0+Side_L*showtime_x;poly3_1.ry()=0;
    poly3_2.rx()=20+Side_L*showtime_x;poly3_2.ry()=0;
    poly3_3.rx()=40+Side_L*showtime_x;poly3_3.ry()=0;
    poly3_4.rx()=40+Side_L*showtime_x;poly3_4.ry()=20;
    point_poly3.push_back(poly3_1);point_poly3_color.push_back(3);
    point_poly3.push_back(poly3_2);point_poly3_color.push_back(3);
    point_poly3.push_back(poly3_3);point_poly3_color.push_back(3);
    point_poly3.push_back(poly3_4);point_poly3_color.push_back(3);

    poly4_1.rx()=0+Side_L*showtime_x;poly4_1.ry()=0;
    poly4_2.rx()=20+Side_L*showtime_x;poly4_2.ry()=0;
    poly4_3.rx()=40+Side_L*showtime_x;poly4_3.ry()=0;
    poly4_4.rx()=60+Side_L*showtime_x;poly4_4.ry()=0;
    point_poly4.push_back(poly4_1);point_poly4_color.push_back(4);
    point_poly4.push_back(poly4_2);point_poly4_color.push_back(4);
    point_poly4.push_back(poly4_3);point_poly4_color.push_back(4);
    point_poly4.push_back(poly4_4);point_poly4_color.push_back(4);

    poly5_1.rx()=0+Side_L*showtime_x;poly5_1.ry()=0;
    poly5_2.rx()=20+Side_L*showtime_x;poly5_2.ry()=0;
    poly5_3.rx()=40+Side_L*showtime_x;poly5_3.ry()=0;
    poly5_4.rx()=20+Side_L*showtime_x;poly5_4.ry()=20;
    point_poly5.push_back(poly5_1);point_poly5_color.push_back(3);
    point_poly5.push_back(poly5_2);point_poly5_color.push_back(3);
    point_poly5.push_back(poly5_3);point_poly5_color.push_back(3);
    point_poly5.push_back(poly5_4);point_poly5_color.push_back(3);

    int tpye=qrand()%4;
    switch (tpye) {
    case 0:
        tmp =point_poly1;tmp_color=point_poly1_color;
        break;
    case 1:
        tmp =point_poly2;tmp_color=point_poly2_color;
        break;
    case 2:
        tmp =point_poly3;tmp_color=point_poly3_color;
        break;
    case 3:
        tmp =point_poly4;tmp_color=point_poly4_color;
    case 4:
        tmp =point_poly5;tmp_color=point_poly5_color;
        break;
    default:
        break;
    }   


    connect(this,&Widget::signal_rotate,this,&Widget::rotate_block);
    timer=new QTimer (this);

    connect(timer,QTimer::timeout,this,Widget::timeUpDate);



}

Widget::~Widget()
{
    delete ui;
}

bool Widget::fallToGround(QVector<QPointF>x)
{
    for(int i=0;i<x.size();i++)
    {
        if(x[i].y()>=460)
            return true;
    }
    return false;
}

bool Widget::freeze(QVector<QPointF> x)
{

    for(int i=0;i<x.size();i++)
    {
        for(int k=0;k<Sum_poly.size();k++)
        {
            for(int s=0;s<Sum_poly[k].size();s++)
            {
                QPointF tmp(x[i].x(),x[i].y()+Side_L);
                if(tmp==Sum_poly[k][s])
                    return 1;
            }
        }
    }
    return 0;
}

void Widget::clearGround()
{
    int Count[24];
    for(int i=0;i<24;i++)
        Count[i]=0;
    for(int i=0;i<Sum_poly.size();i++)
    {
        for(int k=0;k<Sum_poly[i].size();k++)
        {
           int tmp=Sum_poly[i][k].y()/20;
           Count[tmp]++;
        }
    }

    QVector<QPointF>::iterator iter;
     QVector<int>::iterator iter2;
    for(int i=0;i<24;i++)
        if(Count[i]==32)
        {
            score+=1000;
                //刪除一整行
                   for(int k=0;k<Sum_poly.size();k++)
                   {
                               iter=Sum_poly[k].begin();
                               iter2=Sum_poly_color[k].begin();
                               for(;iter!=Sum_poly[k].end();)
                               {
                                   if(iter->y()==i*Side_L)
                                    {
                                       iter=Sum_poly[k].erase(iter);
                                       iter2=Sum_poly_color[k].erase(iter2);
                                   }
                                   else
                                       ++iter,++iter2;
                               }
                    }
                    //把上面向下平移
                             for(int ii=0;ii<Sum_poly.size();ii++)
                              {
                                    for(int kk=0;kk<Sum_poly[ii].size();kk++)
                                        if(Sum_poly[ii][kk].y()<i*Side_L)
                                            Sum_poly[ii][kk].ry()+=Side_L;
                              }

        }
}

void Widget::cleardate()
{
    qDebug("cleardate");
    Sum_poly.clear();
    Sum_poly_color.clear();
   // tmp.clear();
    //tmp_color.clear();
}

void Widget::change_showtime_x()
{
    qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
    showtime_x=(qrand()*2)%25;
  //之所以要全都X改一遍是因為防止後期出現的新的圖形(不止四個方塊)
    poly1_1.rx()=0+Side_L*showtime_x;poly1_1.ry()=0;//(20+Side_L*showtime_x,20);
    poly1_2.rx()=20+Side_L*showtime_x;poly1_2.ry()=0;//(20+Side_L*showtime_x,40);//(40,20);
    poly1_3.rx()=0+Side_L*showtime_x;poly1_3.ry()=20;//poly1_3(40+Side_L*showtime_x,40);//(40,40);
    poly1_4.rx()=20+Side_L*showtime_x;poly1_4.ry()=20;
    point_poly1.clear();
   point_poly1.push_back(poly1_1);point_poly1_color.push_back(1);
   point_poly1.push_back(poly1_2);point_poly1_color.push_back(1);
   point_poly1.push_back(poly1_3);point_poly1_color.push_back(1);
   point_poly1.push_back(poly1_4);point_poly1_color.push_back(1);

   qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
    showtime_x=(qrand()*2)%25;
   poly2_1.rx()=0+Side_L*showtime_x;poly2_1.ry()=0;
   poly2_2.rx()=0+Side_L*showtime_x;poly2_2.ry()=20;
   poly2_3.rx()=20+Side_L*showtime_x;poly2_3.ry()=20;
   poly2_4.rx()=20+Side_L*showtime_x;poly2_4.ry()=40;
    point_poly2.clear();
   point_poly2.push_back(poly2_1);point_poly2_color.push_back(2);
   point_poly2.push_back(poly2_2);point_poly2_color.push_back(2);
   point_poly2.push_back(poly2_3);point_poly2_color.push_back(2);
   point_poly2.push_back(poly2_4);point_poly2_color.push_back(2);

   qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
    showtime_x=(qrand()*2)%25;

   poly3_1.rx()=0+Side_L*showtime_x;poly3_1.ry()=0;
   poly3_2.rx()=20+Side_L*showtime_x;poly3_2.ry()=0;
   poly3_3.rx()=40+Side_L*showtime_x;poly3_3.ry()=0;
   poly3_4.rx()=40+Side_L*showtime_x;poly3_4.ry()=20;
    point_poly3.clear();
   point_poly3.push_back(poly3_1);point_poly3_color.push_back(3);
   point_poly3.push_back(poly3_2);point_poly3_color.push_back(3);
   point_poly3.push_back(poly3_3);point_poly3_color.push_back(3);
   point_poly3.push_back(poly3_4);point_poly3_color.push_back(3);

   qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
   showtime_x=(qrand()*2)%25;
   poly4_1.rx()=0+Side_L*showtime_x;poly4_1.ry()=0;
   poly4_2.rx()=20+Side_L*showtime_x;poly4_2.ry()=0;
   poly4_3.rx()=40+Side_L*showtime_x;poly4_3.ry()=0;
   poly4_4.rx()=60+Side_L*showtime_x;poly4_4.ry()=0;
    point_poly4.clear();
   point_poly4.push_back(poly4_1);point_poly4_color.push_back(4);
   point_poly4.push_back(poly4_2);point_poly4_color.push_back(4);
   point_poly4.push_back(poly4_3);point_poly4_color.push_back(4);
   point_poly4.push_back(poly4_4);point_poly4_color.push_back(4);

   qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
   showtime_x=(qrand()*2)%25;
   poly5_1.rx()=0+Side_L*showtime_x;poly5_1.ry()=0;
   poly5_2.rx()=20+Side_L*showtime_x;poly5_2.ry()=0;
   poly5_3.rx()=40+Side_L*showtime_x;poly5_3.ry()=0;
   poly5_4.rx()=20+Side_L*showtime_x;poly5_4.ry()=20;
   point_poly5.clear();
   point_poly5.push_back(poly5_1);point_poly5_color.push_back(3);
   point_poly5.push_back(poly5_2);point_poly5_color.push_back(3);
   point_poly5.push_back(poly5_3);point_poly5_color.push_back(3);
   point_poly5.push_back(poly5_4);point_poly5_color.push_back(3);
}


bool Widget::touchSide(QVector<QPointF>x)
{
    for(int i=0;i<x.size();i++)
    {
        if(x[i].x()>=640||x[i].x()<0)
            return 1;
    }
    return 0;
}

void Widget::rotate_p(QPointF base, QPointF & x)
{
    QPointF temp;
            if (x.x()> base.x()&&base.y() == x.y())//x+
            {
                temp.rx() = base.x();
                temp.ry ()= base.y() + x.x() - base.x();
            }
            if (x.x() < base.x()&&x.y() == base.y())//x-
            {
                temp.rx() = base.x();
                temp.ry() = base.y() - base.x() + x.x();
            }

            if (x.y()> base.y()&&x.x() == base.x())//y+
            {
                temp.rx() = base.x() - x.y() + base.y();
                temp.ry() = base.y();
            }
            if (x.y()<base.y()&&x.x() == base.x())//y-
            {
                temp.rx ()= base.x() - x.y() + base.y();
                temp.ry() = base.y();
            }
            if (x.x ()> base.x()&&x.y() > base.y())//1
            {
                temp.rx() = base.x() - x.y() + base.y();
                temp.ry() = base.y() + x.x() - base.x();
            }
            if (x.x()<base.x()&&x.y()>base.y())//2
            {
                temp.rx() = base.x() - x.y() + base.y();
                temp.ry() = base.y() + x.x() - base.x();
            }
            if (x.x() < base.x()&&x.y() < base.y())//3
            {
                temp.rx() = base.x() + base.y() - x.y();
                temp.ry() = base.y() - base.x ()+ x.x();
            }
            if (x.x()>base.x()&&x.y() < base.y())//4
            {
                temp.rx() = base.x() + base.y() - x.y();
                temp.ry ()= base.y() - base.x() + x.x();
            }
            if (x.x() == base.x()&&x.y() == base.y())
            {
                temp.rx() = base.x();
                temp.ry ()= base.y();
            }
            x = temp;
}

void Widget::rotate_block()
{
    for(int i=1;i<tmp.size();i++)
    {
        rotate_p(tmp[0],tmp[i]);
    }
    if(touchSide(tmp)||freeze(tmp))
    {
         for(int i=1;i<tmp.size();i++)
              rotate_p(tmp[0],tmp[i]);
         for(int i=1;i<tmp.size();i++)
              rotate_p(tmp[0],tmp[i]);
         for(int i=1;i<tmp.size();i++)
              rotate_p(tmp[0],tmp[i]);
    }
}

void Widget::restart()
{
    Widget *x=new Widget();
    x->show();
}

void Widget::get_mortal(int x )
{
    speed=x;
    score=0;

}

void Widget::get_king(int x)
{
    speed=x;
     score=0;

}
void Widget::get_hell(int x)
{
    speed=x;
     score=0;

}
void Widget::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    str_score=QString::number(score);
    scoreshow->setText(str_score);

    clearGround();

                for(int i=0;i<Sum_poly.size();i++)//每次輸出固定
                {
                    for(int k=0;k<Sum_poly[i].size();k++)
                    {
                        //  painter.drawRect(Sum_poly[i][k].x(),Sum_poly[i][k].y(),Side_L,Side_L);
                        switch(Sum_poly_color[i][k])
                        {
                        case 1:painter.drawImage(Sum_poly[i][k].x(),Sum_poly[i][k].y(),QImage(":/image/block_1.png"));break;
                        case 2:painter.drawImage(Sum_poly[i][k].x(),Sum_poly[i][k].y(),QImage(":/image/block_2.png"));break;
                        case 3:painter.drawImage(Sum_poly[i][k].x(),Sum_poly[i][k].y(),QImage(":/image/block_3.png"));break;
                        case 4:painter.drawImage(Sum_poly[i][k].x(),Sum_poly[i][k].y(),QImage(":/image/block_4.png"));break;
                        case 5:painter.drawImage(Sum_poly[i][k].x(),Sum_poly[i][k].y(),QImage(":/image/block_3.png"));break;
                        }

                   }
                }

                 if(!fallToGround(tmp)&&!freeze(tmp))
                 {
                    for(int i=0;i<tmp.size();i++)
                    {
                         // painter.drawRect(tmp[i].x(),tmp[i].y(),Side_L,Side_L);
                        switch(tmp_color[i])
                        {
                        case 1:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_1.png"));break;
                        case 2:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_2.png"));break;
                        case 3:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_3.png"));break;
                        case 4:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_4.png"));break;
                        case 5:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_3.png"));break;
                        }

                 }
                 }
        else
    {
                    //固定的時候還是要列印一下
                        for(int i=0;i<tmp.size();i++)   
                        {
                             //painter.drawRect(tmp[i].x(),tmp[i].y(),Side_L,Side_L);
                            switch(tmp_color[i])
                            {
                            case 1:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_1.png"));break;
                            case 2:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_2.png"));break;
                            case 3:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_3.png"));break;
                            case 4:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_4.png"));break;
                            case 5:painter.drawImage(tmp[i].x(),tmp[i].y(),QImage(":/image/block_3.png"));break;
                            }
                        }

       change_showtime_x();

                            Sum_poly.push_back(tmp);
                             Sum_poly_color.push_back(tmp_color);
                             qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
                            int rand=qrand()%5;
                            switch (rand) {
                            case 0:
                            {

                                 tmp =point_poly1;tmp_color=point_poly1_color;
                                break;
                            }
                            case 1:
                            {

                                 tmp =point_poly2;tmp_color=point_poly2_color;
                                break;
                            }
                            case 2:
                            {
                                change_showtime_x();
                                tmp =point_poly3;tmp_color=point_poly3_color;
                               break;
                            }
                            case 3:
                            {
                                tmp =point_poly4;tmp_color=point_poly4_color;
                                break;
                            }
                            case 4:
                            {
                                tmp =point_poly5;tmp_color=point_poly5_color;
                                break;
                            }
                            }
                          //  cleardate();

                 }


}
void Widget::keyPressEvent(QKeyEvent *event)
{
    keyPress=1;
    if(event->key()==Qt::Key_W)
    {
            for(int k=0;k<tmp.size();k++)
               tmp[k].ry()-=Side_L;
    }
    if(event->key()==Qt::Key_J)

    {
        emit signal_rotate();
    }
     if(event->key()==Qt::Key_P)
     {
        timer->stop();
     }
     if(event->key()==Qt::Key_O)
     {
        timer->start(speed);
     }

    if(event->key()==Qt::Key_A)
    {
        for(int k=0;k<tmp.size();k++)
           tmp[k].rx()-=Side_L;
        if(touchSide(tmp)||freeze(tmp))
            for(int k=0;k<tmp.size();k++)
               tmp[k].rx()+=Side_L;
    }
    if(event->key()==Qt::Key_S)
    {
        for(int k=0;k<tmp.size();k++)
           tmp[k].ry()+=Side_L;
        if(touchSide(tmp)||freeze(tmp)||fallToGround(tmp))
            for(int k=0;k<tmp.size();k++)
               tmp[k].ry()-=Side_L;
    }
    if(event->key()==Qt::Key_D)
    {
        for(int k=0;k<tmp.size();k++)
           tmp[k].rx()+=Side_L;
        if(touchSide(tmp)||freeze(tmp))
            for(int k=0;k<tmp.size();k++)
               tmp[k].rx()-=Side_L;
    }
}

void Widget::timeUpDate()
{


    for(int k=0;k<Sum_poly.size();k++)
    {
        for(int i=0;i<Sum_poly[k].size();i++)//在掉落方塊儲存在總點之前判斷
        {
            if(Sum_poly[k][i].ry()<=40)
          {
                cleardate();
                switch (speed) {
                case 60:
                {
                    if(QMessageBox::question(this,"提示","誰給你的勇氣玩這種級別?還要再來?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
                     {
                        timer->stop();
                         this->hide();
                        timer->setInterval(speed);
                         if( select->exec()==Last_select::Accepted)
                         {
                             this->show();
                         }
                     }
                     else
                         exit(0);
                    goto part;
                    break;
                }
                case 120:
                {
                    if(QMessageBox::question(this,"提示","萌新就好好回去玩你的冒險,還來?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
                     {
                        timer->stop();
                        this->hide();
                        timer->setInterval(speed);
                         if( select->exec()==Last_select::Accepted)
                         {
                             this->show();
                         }
                     }
                     else
                         exit(0);
                    goto part;
                    break;
                }

                case 250:
                {
                    if(QMessageBox::question(this,"提示","這麼簡單都能GG,你退群吧?",QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes)
                     {
                        timer->stop();
                         this->hide();
                        timer->setInterval(speed);
                         if( select->exec()==Last_select::Accepted)
                         {
                             this->show();
                         }
                     }
                     else
                         exit(0);
                    goto part;
                    break;
                }

                default:
                    break;
            }
                }

          }
        }

    part:;
    //預設下墜
    if(keyPress==0)
    {
    for(int k=0;k<tmp.size();k++)
       tmp[k].ry()+=Side_L;
    }
    this->update();
    keyPress=0;
}