#ifndef tank_h
#define tank_h
#include"wanwu.h"
#include"main.h"
#include"gamemap.h"
class tank : public wanwu
; float lifes[8]=;
float wulis[8]=;
float fashus[8]=;
float hujias[8]=;
float mokangs[8]=;
int gongjijianges[8]=;
intgroup;//坦克所在組,同一組不能相互傷害
public:
tank();
tank(int iindex,int jindex,dir dir=up,int style=0,int
group=1);
// 計算勢力範圍
virtual
void calculatesphere();
// 繪圖
void display(qpainter &paint);
// 移動
void move();
//設定移動狀態為開
void startmove()
//設定移動狀態為關
void stopmove()
//// void fire();
//void startfire();
//void stopfire();
//設定方向
void setdir(dir dir)
private:
int style;
bool ismove;
// bool isfire;
int gongjijiange;
};#endif // tank_h
tank.cpp
#include "tank.h"
tank::tank()
tank::tank(int iindex,int jindex,dir dir,int style,int
group)
void tank::display(qpainter &paint)
}//此段**可以優化簡潔
void tank::move()
calculatesphere();
qdebug("move on");
}qdebug("move off");
}void tank::calculatesphere()
main.h結構體glo中加入選項tank *player.
class qimage;
class gamemap;
class tank;
typedef
structglo;//實列化glo型別變數,能實列化出來,所有的指標變數所佔空間daxiao一樣。
mainwindow.h裡加入
#include
"tank.h"
mainwindow.cpp建構函式裡加入
glo.player=new tank();
mainwindow.cpp paintevent函式變更如下
void mainwindow::paintevent(qpaintevent *event)
mainwindow.cpp keypressevent變更如下
void mainwindow::keypressevent(qkeyevent *event)else
if(event->key()==qt::key_g)
if(gamestatus==mapedit)
else
if(event->key()==qt::key_l)
}else
if(gamestatus==gameing)
else
if(event->key()==qt::key_a)
else
if(event->key()==qt::key_w)
else
if(event->key()==qt::key_d)
else
if(event->key()==qt::key_j)
}update();
}
C qt 遊戲實戰專案 坦克大戰(前言)
坦克遊戲,兒時的經典,同樣是練手的經典小專案之一!準備好開發環境 必須備註1 備註2window或linux系統 推薦window qt5.5以上 整體框架偽 描述 遊戲開始 遊戲初始化 while true 繪圖訊號處理函式 地圖類 display 鍵盤訊號處理函式 if gamestatus g...
C 遊戲《坦克大戰》 坦克
這裡的各種型別,使用struct而不是enum,避免後面強制轉換。子彈資訊 public struct t bulletinfo 坦克型別 public struct t type 坦克行動方向 public struct t dir 公共引數 public struct t commpar 設計框...
Java專案 坦克大戰1
我們既然要做這個遊戲,首先我們必須知道這個遊戲裡面應該有什麼成員,成員都有什麼屬性。成員 1 遊戲介面的面板 關卡 難度 總成績 2 自己的英雄坦克 方向 子彈 生命值 3 敵軍坦克 方向隨機 總數量,單次數量 4 子彈 5 記錄成績以及生命值 如圖 所有的坦克都有的屬性 方向 顏色 速度 生命 所...