300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > c语言坦克大战源代码vc 6.0 c语言编写坦克大战源代码.doc

c语言坦克大战源代码vc 6.0 c语言编写坦克大战源代码.doc

时间:2019-01-25 15:44:09

相关推荐

c语言坦克大战源代码vc 6.0 c语言编写坦克大战源代码.doc

c语言编写坦克大战源代码

#include "tank.h"

#include "ConOperator.h"

#include

#include

#include

#include

using namespace std;

TankGame::TankGame(int w, int h)

{

// 设定当前关数

no = 1;

// 设定游戏整体高宽

wide = w;

high = h;

HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

COORD sizePos = {2 * wide, high};

SetConsoleScreenBufferSize(hStdOut, sizePos);

// 分配游戏空间状态表

gameSpace = new GameSpace*[high];

for (int i = 0; i != high; i++)

gameSpace[i] = new GameSpace[wide];

// 添加围墙

wall = new Wall(gameSpace, wide, high);

wall->draw();

}

void TankGame::load_init()

{

// 初始化游戏空间

for (int y = 1; y != high-1; y++) {

for (int x = 1; x != wide-1; x++) {

gameSpace[y][x].have = false;

gameSpace[y][x].kind = 0;

gameSpace[y][x].no = 0;

}

}

// 添加地图

map.load(gameSpace, no);

// 初始化自己坦克

me.init_xy();

me.trans_direction(1);

me.set_no(0);

me.init_move(gameSpace, wide / 2 - 2, high - 5);

// 按顺序诞生敌人坦克

creatPlace = 0;

for (int i = 0; i != 3; i++) {

freezeTime[i] = REBIRTHTIME;

enemy[i].init_xy();

enemy[i].set_kind(2);

enemy[i].set_no(i+1);

reset(enemy[i]);

}

// 数目初始化

leftCount = 17;

existCount = 3;

// 显示图片

me.draw_tank();

for (int i = 0; i != 3; i++)

enemy[i].draw_tank();

map.draw();

}

TankGame::~TankGame()

{

if (wall)

delete wall;

if (gameSpace) {

for (int i = 0; i != high; i++)

delete[] gameSpace[i];

delete[] gameSpace;

}

}

void TankGame::reset(Tank& tank)

{

bool success = false;

int t = 3;

while (t && !success) {

creatPlace++;

if (creatPlace == 4)

creatPlace = 1;

// 诞生地点选择

switch (creatPlace) {

case 1:

tank.trans_direction(3); //朝下

if (tank.reset(gameSpace,1,1))

success = true;

break;

case 2:

tank.trans_direction(3);

if (tank.reset(gameSpace,wide / 2 - 2, 1))

success = true;

break;

case 3:

tank.trans_direction(3);

if (tank.reset(gameSpace,wide - 4, 1))

success = true;

break;

}

if (!success)

t--;

}

}

void TankGame::start()

{

char comman

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。