導航:首頁 > 玩小游戲 > qt小游戲

qt小游戲

發布時間:2021-04-21 10:41:33

❶ 基於Qt小游戲的設計與實現

Qt小游戲的設計與實現
這個你想達到的功能是確這樣我才好,幫到你的

❷ qt編程可以做什麼小游戲

在網路上看到的一個貪吃蛇游戲
includelt;iostream.h;
includelt;windows.h;
includelt;time.h;
includelt;stdlib.h;
includelt;conio.h;
define N 21
void gotoxy(int x,int y)//位置函數
{
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a)//顏色函數
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void init(int apple[2])//初始化函數(初始化圍牆、顯示信息、蘋果)
{
int i,j;//初始化圍牆
int wall[N+2][N+2]={{0}};
for(i=1;ilt;=N;i++)
{
for(j=1;jlt;=N;j++)
wall[i][j]=1;
}
color(11);
for(i=0;ilt;N+2;i++)
{
for(j=0;jlt;N+2;j++)
{
if(wall[i][j])
coutlt;lt;;■;;
else coutlt;lt;;□; ;
}
coutlt;lt;endl;
}
gotoxy(N+3,1);//顯示信息
color(20);
coutlt;lt;;按 W S A D 移動方向;lt;lt;endl;
gotoxy(N+3,2);
color(20);
coutlt;lt;;按任意鍵暫停;lt;lt;endl;
gotoxy(N+3,3);
color(20);
coutlt;lt;;得分:;lt;lt;endl;
apple[0]=rand()%N+1;//蘋果
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
coutlt;lt;;●;lt;lt;endl;
}
int main()
{
int i,j;
int** snake=NULL;
int apple[2];
int score=0;
int tail[2];
int len=3;
char ch=;p;;
srand((unsigned)time(NULL));
init(apple);
snake=(int**)realloc(snake,sizeof(int*)*len);
for(i=0;ilt;len;i++)
snake[i]=(int*)malloc(sizeof(int)*2);
for(i=0;ilt;len;i++)
{
snake[i][0]=N/2;
snake[i][1]=N/2+i;
gotoxy(snake[i][0],snake[i][1]);
color(14);
coutlt;lt;;★;lt;lt;endl;
}
while(1)//進入消息循環
{
tail[0]=snake[len-1][0];
tail[1]=snake[len-1][1];
gotoxy(tail[0],tail[1]);
color(11);
coutlt;lt;;■;lt;lt;endl;
for(i=len-1;i;0;i--)
{
snake[i][0]=snake[i-1][0];
snake[i][1]=snake[i-1][1];
gotoxy(snake[i][0],snake[i][1]);
color(14);
coutlt;lt;;★;lt;lt;endl;
}
if(kbhit())
{
gotoxy(0,N+2);
ch=getche();
}
switch(ch)
{
case ;w;:snake[0][1]--;break;
case ;s;:snake[0][1]++;break;
case ;a;:snake[0][0]--;break;
case ;d;:snake[0][0]++;break;
default: break;
}
gotoxy(snake[0][0],snake[0][1]);
color(14);
coutlt;lt;;★;lt;lt;endl;
Sleep(abs(200-0.5*score));
if(snake[0][0]==apple[0]snake[0][1]==apple[1])//吃掉蘋果後蛇分數加1,蛇長加1
{
score++;
len++;
snake=(int**)realloc(snake,sizeof(int*)*len);
snake[len-1]=(int*)malloc(sizeof(int)*2);
apple[0]=rand()%N+1;
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
coutlt;lt;;●;lt;lt;endl;
gotoxy(N+5,3);
color(20);
coutlt;lt;scorelt;lt;endl;
}
if(snake[0][1]==0snake[0][1]==Nsnake[0][0]==0snake[0][0]==N)//撞到圍牆後失敗
{
gotoxy(N/2,N/2);
color(30);
coutlt;lt;;Game over;lt;lt;endl;
for(i=0;ilt;len;i++)
free(snake[i]);
Sleep(INFINITE);
exit(0);
}
}
return 0;
}

❸ 現在大型單機游戲大都是用QT開發的嗎

Qt只是一個跨平台的應用程序開發框架,在游戲方面和使用C++也才不多,對於大型游戲開發還是要使用游戲引擎,所以幾乎很少

❹ QT是什麼游戲

《兲驕3》更是被評為業界最看好的網游大作

❺ 用Qt編程紙牌游戲中的紙牌用什麼構件啊

QGraphicsItem,QGraphicsView,QGraphicsScene.
很難的,但是很靈活.
祝好運.

❻ qt打字小游戲

1.打字訓練游戲

typeGame QDialog
1-1 字母 / 磚塊 繪制
paintEvent() ---- update()
QPainter 類

資源清單: 26個字母 磚塊 背景

數據處理:
struct _STCH
QString szPath
QPoint cPos

QSize 磚塊大小
QPoint 桌上角第一塊磚的位置

const int max_ch = 5
最多5個字母同時出現

1.繪制磚頭 40*40
800/40 = 20 col
640/40 = 16 row

13 14 15
2.處理數據********

3.隨機出現字母

字母圖片和位置

4.捕獲用戶按鍵

KeyPressEvent
5.計分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

首先建一個文件叫typeGame 選擇 基類 QDialog
名字設為dialog

1.dialog.cpp

#include "dialog.h"
#include "ui_dialog.h"

#include <QMessageBox>

// 聲明它是一個外部變數
extern int gScore;

void Dialog::on_startBtn_clicked()
{
initImgList(); // 1.初始化圖片路徑
initPosList(); // 2.初始化圖片位置
// initWallList(); // 3.初始化磚頭列表
checkCrash(); // 4.檢查字母是否撞倒磚頭
// 3.定義控制字母下移的定時器
QTimer *pDownTimer = new QTimer;
connect(pDownTimer,SIGNAL(timeout()),
this,SLOT(updateMap()));
pDownTimer->start(1000);

// 4.定義產生字母的定時器
QTimer *pCharTimer = new QTimer;
connect(pCharTimer,SIGNAL(timeout()),
this,SLOT(createChar()));
pCharTimer->start(3000);
// 5.定義一個刷新顯示分數的定時器
QTimer *pScoreTimer = new QTimer;
connect(pScoreTimer,SIGNAL(timeout()),
this,SLOT(updateScore()));
pScoreTimer->start(500);
// 6.定義一個刷新計時的定時器
QTimer *pTimeTimer = new QTimer;
connect(pTimeTimer,SIGNAL(timeout()),
this,SLOT(updateTime()));
pTimeTimer->start(1000);
}

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog),
m_iTime(60)
{
ui->setupUi(this);
initWallList();
checkCrash();
}

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

void Dialog::paintEvent(QPaintEvent * event)
{
QPainter p(this);
// 1.繪制背景
p.drawPixmap(0,0,800,640,QPixmap(":image/back.jpg"));
// 2.繪制磚頭
for(int i = 0; i < m_WallList.size(); ++i)
{
int x = m_WallList.at(i).x();
int y = m_WallList.at(i).y();
p.drawPixmap(x,y,40,40,QPixmap(":image/wall.jpg"));
}

// 3.繪制隨機產生的字母
for(int i = 0; i < m_CharList.size(); ++ i)
{
int x = m_CharList.at(i).x;
int y = m_CharList.at(i).y;
int iIndex = m_CharList.at(i).iIndex;
p.drawPixmap(x,y,40,40,QPixmap(m_ImgList.at(iIndex)));
}
}

// 按鍵事件
void Dialog::keyPressEvent(QKeyEvent * event)
{
m_key = event->key();
m_key += 32;
for(int i = 0; i < m_CharList.size(); ++ i)
if( m_key == m_CharList.at(i).value)
{
m_CharList.removeAt(i);
gScore += 10;
break;
}
update();
return ;
}

// 更新地圖
void Dialog::updateMap()
{
// 1.改變字母的位置
for(int i = 0; i < m_CharList.size(); ++ i)
m_CharList[i].y += 40;
// 2.檢查字母是否撞倒磚頭
checkCrash();
// 3.重繪地圖
update();
return ;
}

// 產生字母
void Dialog::createChar()
{
if( m_CharList.size() > 4)
return ;

STCHAR stChar;
stChar.iIndex = rand()%m_ImgList.size();
stChar.x = m_PosList.at(stChar.iIndex%20).x();
stChar.y = m_PosList.at(stChar.iIndex%20).y();
stChar.value = stChar.iIndex + 'a';

m_CharList.append(stChar);
return ;
}

// 1.初始化圖片路徑
void Dialog::initImgList()
{
for(char i = 'a'; i<='z'; ++i)
{
QString szPath = QString(":image/%1.jpg").arg(i);
m_ImgList.append(szPath);
}
return ;
}
// 2.初始化圖片位置
void Dialog::initPosList()
{
for(int iCol = 0; iCol < 20; ++iCol)
m_PosList.append(QPoint(iCol*40,0));
return ;
}
// 3.初始化磚頭列表
void Dialog::initWallList()
{
for(int iRow = 13; iRow < 16; ++ iRow)
for(int iCol = 0; iCol < 20; ++iCol)
m_WallList.append(QPoint(iCol*40,iRow*40));
return ;
}

// 4.檢查字母是否撞倒磚頭
void Dialog::checkCrash()
{
for(int i = 0; i < m_CharList.size(); ++i)
for(int j = 0; j < m_WallList.size(); ++j)
{
int x1 = m_CharList.at(i).x;
int y1 = m_CharList.at(i).y;
int x2 = m_WallList.at(j).x();
int y2 = m_WallList.at(j).y();
if ( x1 == x2 && y1 == y2)
{
m_CharList.removeAt(i);
m_WallList.removeAt(j);
gScore -=5;
return ;
}
}
}

// 5.定義一個刷新顯示分數
void Dialog::updateScore()
{
ui->scoreLcd->display(gScore);
return ;
}

// 5.定義一個刷新顯示時間
void Dialog::updateTime()
{
ui->timeLcd->display(m_iTime--);
if( m_iTime < 0 )
close();
return ;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

2.dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include <QPainter>
#include <QTimer>
#include <QKeyEvent>

// 字元信息結構體
typedef struct _STCHAR
{
int iIndex; // 字母索引值
int x; // 字母X坐標
int y; // 字母Y坐標
int value; // 字母值
}STCHAR;

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
void initImgList(); // 1.初始化圖片路徑
void initPosList(); // 2.初始化圖片位置
void initWallList(); // 3.初始化磚頭列表
void checkCrash(); // 4.檢查字母是否撞倒磚頭
protected:
void paintEvent(QPaintEvent * event); // 繪圖事件
void keyPressEvent(QKeyEvent * event); // 按鍵事件
public slots:
void updateMap(); // 更新地圖
void createChar(); // 創建字元
void updateScore(); // 更新分數
void updateTime(); // 更新時間
private slots:
void on_startBtn_clicked();

private:
Ui::Dialog *ui;
QList<QString> m_ImgList; // 字母圖片路徑
QList<QPoint> m_PosList; // 字母初始位置
QList<STCHAR> m_CharList; // 字元鏈表
QList<QPoint> m_WallList; // 磚頭列表
int m_key; // 用戶輸入Key
int m_iTime; // 計時時間
int gScore = 0;
};

#endif // DIALOG_H
---------------------
作者:王木木界
來源:CSDN
原文:https://blog.csdn.net/sinat_24880087/article/details/52433687
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

閱讀全文

與qt小游戲相關的資料

熱點內容
手機vr射擊游戲 瀏覽:260
幼兒園拼音游戲 瀏覽:486
兒童學詩游戲 瀏覽:439
蘋果手機賽車游戲排行 瀏覽:750
小饅頭迷你游戲狙擊地圖解說 瀏覽:68
兒童游戲賽跑 瀏覽:988
植物大戰僵屍免費游戲 瀏覽:707
幼兒小班室內游戲大全 瀏覽:863
小班闖關游戲 瀏覽:352
憶涵游戲解說直播木蘭 瀏覽:220
游戲怎麼封號 瀏覽:377
直播游戲賭 瀏覽:867
推塔手機游戲 瀏覽:340
仙劍奇俠傳3單機游戲 瀏覽:452
開發大腦的益智游戲 瀏覽:920
捉泥鰍親子游戲 瀏覽:424
游戲直播圈粉 瀏覽:154
安卓模擬器游戲數據包 瀏覽:812
三國志單機游戲大全 瀏覽:79
游戲時光直播 瀏覽:181