Qt版双人俄罗斯方块游戏
来源:互联网 发布:java infinity 编辑:程序博客网 时间:2024/04/30 13:08
Qt版双人俄罗斯方块游戏
转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907
之前写过《VC版双人俄罗斯方块》,将其在Qt下又重写了一遍,核心的算法还是采用VC下曾经用过的C++源码,直接用的是当时封装好的类,写在一个文件中,所以直接拿来用。不同的仍然是与显示有关的东西需要采用Qt下的显示方式。
以下是Qt版运行截图:
先是按键响应槽的实现代码:
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);}
之后还有就是绘制槽的实现代码:
void Tetris::paintEvent(QPaintEvent *event){ QPainter painter(this); unsigned int width,i,j; unsigned int height,width1,height1; unsigned int height2,width2,height3,width3; width=bin->getWidth(); //左边主显示面板宽度与高度的获取 height=bin->getHeight(); width1=bin1->getWidth();//左边预测面板的宽度与高度的获取 height1=bin1->getHeight(); width2=bin2->getWidth();//右边主显示面板宽度与高度的获取 height2=bin2->getHeight(); width3=bin3->getWidth();//右边预测面板的宽度与高度的获取 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); //右边玩家分数的输出 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)); //左边玩家分数的输出 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/yello.png" ":/images/green.png", ":/images/green.png"}; int b,b1,b2; for(i=0;i<height1;i++) { for(j=0;j<width1;j++) { rc1=QRect(j*nSize+300,i*nSize,nSize,nSize);//矩形的区域 if(image1[i][j]!=0) { b=image1[i][j]; // qDebug()<<str[b]; QImage img; img.load(":/images/red.png"); // img.load(str[b]); QBrush brush(img); painter.setBrush(brush); painter.fillRect(rc1,brush); // painter.setBrush(Qt::green); // painter.drawRect(rc1); } } } for(i=0;i<height;i++) { for(j=0;j<width;j++) { rc=QRect(j*nSize+80,i*nSize,nSize,nSize); if(image[i][j]!=0) { b=image[i][j]; //左边玩家主面板砖块的位图填充 // qDebug()<<str[b]; QImage img; img.load(":/images/red.png"); // img.load(str[b]); QBrush brush(img); painter.setBrush(brush); painter.fillRect(rc,brush); } } } ///////////////////////////////////////// if(GameModal==2) { for(i=0;i<height3;i++) { for(j=0;j<width3;j++) { rc3=QRect(j*nSize+420,i*nSize,nSize,nSize); if(image3[i][j]!=0) { b=image3[i][j];//右边玩家预测砖块的位图填充 // qDebug()<<str[b]; QImage img; img.load(":/images/green.png"); // img.load(str[b]); QBrush brush(img); painter.setBrush(brush); painter.fillRect(rc3,brush); } } } for(i=0;i<height2;i++) { for(j=0;j<width2;j++) { rc2=QRect(j*nSize+540,i*nSize,nSize,nSize); if(image2[i][j]!=0) { b=image2[i][j];//右边玩家主面板砖块的位图填充 // qDebug()<<str[b]; QImage img; img.load(":/images/green.png"); // img.load(str[b]); QBrush brush(img); painter.setBrush(brush); painter.fillRect(rc2,brush); } } } }}其他的都和VC下的一样。
转载请标明出处:牟尼的专栏 http://blog.csdn.net/u012027907
2 0
- Qt版双人俄罗斯方块游戏
- MFC双人版俄罗斯方块
- H5 游戏 俄罗斯方块 双人互动游戏
- VC版双人PK版俄罗斯方块
- VC写的双人版俄罗斯方块
- QT -WS俄罗斯方块游戏
- VC/MFC 俄罗斯方块双人版(基于MFC单文档)
- Qt做的俄罗斯方块游戏
- Qt做的俄罗斯方块游戏
- 使用Qt开发俄罗斯方块游戏
- QT项目一:俄罗斯方块游戏
- 【游戏】JavaScript 版俄罗斯方块
- 使用Qt开发俄罗斯方块游戏(1)
- 双人游戏, 双人冒险小游戏 ,双人闯关小游戏
- 【VC++MFC平台游戏】黑白棋双人版
- 奥运版silverlight 俄罗斯方块游戏
- 网页版游戏(俄罗斯方块)
- 【冷却游戏】 安卓版 俄罗斯方块游戏 官方版
- 基础算法之动态规划
- 1008. Elevator
- how to install splint
- 假期总结
- ubuntu14.04 开机自动运行应用程序
- Qt版双人俄罗斯方块游戏
- POJ 2251-Dungeon Master
- RHEL/CentOS 7.x如何启动/关闭、启用/禁用服务? 修改系统运行级别
- 在jstl标签中forEach标签遍历Map
- 【codeforces】Codeforces Round #291 (Div. 2) 题解
- 小马哥---高仿苹果5S 6572芯片 拆机图H5s型号 版本多
- Photoshop入门教程(四):混合模式
- 第一泡吧
- UIDevice Category For Processes