QT version Double Tetris game

Source: Internet
Author: User
Tags textout

QT version Double Tetris game Reprint please indicate the source: Muni column http://blog.csdn.net/u012027907
before the "VC version of Double Tetris", will be rewritten under QT again, the core of the algorithm is the use of VC has used the C + + source, the direct use of the package is a good class, written in a file, so directly to use. The difference is still related to the display of things that need to be used under QT display mode. the following is the QT version run:


First, the implementation code of the key response slot:
void Tetris::keypressevent (Qkeyevent *event) {    if (event->key () = = Qt::key_0)        onPause ();    if (event->key () = = Qt::key_right)        activebrick->shiftright (bin);    else if (event->key () = = Qt::key_left)        activebrick->shiftleft (bin);    else if (event->key () = = qt::key_up)        activebrick->rotateclockwise (bin);    else if (event->key () = = Qt::key_down)        activebrick->shiftdown (bin);    if (event->key () = = Qt::key_6)        activebrick2->shiftright (bin2);    else if (event->key () = = Qt::key_4)        activebrick2->shiftleft (bin2);    else if (event->key () = = Qt::key_8)        activebrick2->rotateclockwise (bin2);    else if (event->key () = = qt::key_5)        activebrick2->shiftdown (bin2);}

And then there is the implementation code that draws the slot:
void Tetris::p aintevent (qpaintevent *event) {qpainter painter (this);    unsigned int width,i,j;    unsigned int height,width1,height1;    unsigned int height2,width2,height3,width3;  Width=bin->getwidth ();    The left main display panel width and height get height=bin->getheight ();    Width1=bin1->getwidth ();//left to predict the width and height of the panel to get Height1=bin1->getheight ();    Width2=bin2->getwidth ();//Right main display panel width and height of the acquisition height2=bin2->getheight ();    Width3=bin3->getwidth ();//Right prediction panel width and height of the acquisition height3=bin3->getheight ();    int nsize=20;    Qrect rect (0,0,860,500);    Qimage Imageback;    Imageback.load (":/images/background.png");    Qbrush brushback (Imageback);    Painter.setbrush (Brushback);    Painter.drawrect (rect);    Right player score output qrect re;    Pdc->fillsolidrect (Re,rgb (210,255,255));   Char buf[100];   sprintf (buf, "%d", numlines*10);    Pdc->textout (330,90,BUF);    Ui->label_scorel->settext (Qstring::number (numlines*10)); Ui->label_scorel_2->settext (Qstring::number (nuMLINES1*10));   Left player score output qrect Re1;   Pdc->fillsolidrect (Re1,rgb (230,255,100));    Char buf1[100];      if (gamemodal==2) {//sprintf (BUF1, "%d", numlines1*10);    Pdc->textout (440,90,BUF1);    } Qrect RC,RC1,RC2,RC3; QString str[] = {":/images/blue.png", ":/images/red.png", ":/images/green.png" , ":/images/blue.png", ":/images/ya.png", ":/images/yell    O.png "":/images/green.png ",":/images/green.png "};    int b,b1,b2; for (i=0;iThe others are the same as the VC. Reprint Please indicate the source: Muni column http://blog.csdn.net/u012027907



QT version Double Tetris game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.