c语言编写坦克大战设计报告,c语言编写坦克大战源代码

《c语言编写坦克大战源代码》由会员分享,可在线阅读,更多相关《c语言编写坦克大战源代码(10页珍藏版)》请在人人文库网上搜索。

1、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);/ 分配游戏空间状。

2、态表gameSpace = new GameSpace*high;for (int i = 0; i != high; i+)gameSpacei = new GameSpacewide;/ 添加围墙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+) gameSpaceyx.have = false;gameSpaceyx.kind = 0;gam。

3、eSpaceyx.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+) freezeTimei = REBIRTHTIME;enemyi.init_xy();enemyi.set_kind(2);enemyi.set_no(i+1);reset(enemyi);。

4、/ 数目初始化leftCount = 17;existCount = 3;/ 显示图片me.draw_tank();for (int i = 0; i != 3; i+)enemyi.draw_tank();map.draw();TankGame:TankGame()if (wall)delete wall;if (gameSpace) for (int i = 0; i != high; i+)delete gameSpacei;delete gameSpace;void TankGame:reset(Tank& tank)bool success = false;int t = 3;whi。

5、le (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(。

6、3);if (tank.reset(gameSpace,wide - 4, 1)success = true;break;if (!success)t-;void TankGame:start()char command;enter_picture(command);if (command != ENTER)return;while (me.blood 0) / init data for runingload_init();/ run a taskruning_a_task();/ determine why returnif (me.blood 0) no+; if (no map.tot。

7、al) success_gameover();break;char command;turn_to_next_task(command);if (command != ENTER)break; else game_over();/voidvoid TankGame:runing_a_task()while (leftCount | existCount) & me.blood) clock_t now = clock();char command = -1; / 主人命令while (clock() - now =0 & command = 1 & shot = 7 & shot = 1 & 。

8、shot 0) for (int i = 0; i != 3; i+) if (enemyi.blood = 0) if (freezeTimei = 0) freezeTimei = REBIRTHTIME;reset(enemyi);existCount+;leftCount-; else freezeTimei-;void TankGame:update_keyBoard_char(char& c)if (_kbhit() c = getch();if (c = -32) c = getch();if (c != UP & c != DOWN & c != LEFT & c != RIG。

9、HT)c = -1;else if (c = RIGHT)c = 0;else if (c = UP)c = 1;else if (c = LEFT)c = 2;elsec = 3; elsec = 32;void TankGame:enter_picture(char &command)string captions6;captions0 = ; captions1 = ; captions2 = ; captions3 = ;captions4 = ;captions5 = ;string s = ;color(0x0e);for (int i = 0; i != 6; i+)grid(7。

10、, 6 + i, captionsi);Frame frame(30,15);frame.draw_frame(4,19,0x09);string sentence3;sentence0 = This small game is made by yzx in 2010.;sentence1 = Wlecome to play it.;sentence2 = All Rights Reserved.;color(0x0e);for (int i = 0; i != 3; i+) for (int k = 0; k != sentencei.size(); k+) grid(14+k,21+2*i。

11、,sentenceik);sleep(50);sleep(1000);grid(7, 28,Enter : 开始 ESC : 退出);while (true) if (_kbhit() command = getch();if (command = ENTER | command = ESC)break;/ clear screen picture in wallclear_picture();void TankGame:turn_to_next_task(char& command)clear_picture();color(0x0e);grid(18, 20, 第);grid(20, 20。

12、, no);grid(22, 20, 关);while (true) if (_kbhit() command = getch();if (command = ENTER | command = ESC)break;grid(18, 20, );void TankGame:success_gameover()clear_picture();Frame frame(30,15);frame.draw_frame(4,10,0x09);string sentence3;sentence0 = Congratulations for Successfully finishing all tasks;。

13、sentence1 = Thank you for using it deeply.;sentence2 = And welcome to use it next time.;color(0x0e);for (int i = 0; i != 3; i+) for (int k = 0; k != sentencei.size(); k+) grid(12+k,14+2*i,sentenceik);sleep(50);sleep(1000);while (true) if (_kbhit() char command = getch();if (command = ENTER | command。

14、 = ESC)break;void TankGame:game_over()clear_picture();Frame frame(30,15);frame.draw_frame(4,15,0x09);string sentence4;sentence0 = Game over, but you can try it again.;sentence1 = Thank you for using it deeply.;sentence2 = And welcome to use it next time.;sentence3 = All rights reserved.(Violators wi。

15、ll be prosecuted.) .;color(0x0e);for (int i = 0; i != 4; i+) for (int k = 0; k != sentencei.size(); k+) grid(13+k,18+2*i,sentenceik);sleep(50);sleep(1000);while (true) if (_kbhit() char command = getch();if (command = ENTER | command = ESC)break;void TankGame:clear_picture()int cirX = wide / 2;int c。

16、irY = high / 2;int depth = cirY cirX ? cirY + 2 : cirX + 2;int lx, rx, uy, by;int l, r, u, b;for (int i = 0; i != depth; i+) lx = cirX - i;rx = cirX + i;uy = cirY - i;by = cirY + i;uy = high - 1 ? b = high - 2 :b = by;lx = wide -1 ? r = wide - 2 : r = rx;if (rx 0) for (int k = u; k 0) for (int k = l; k = r; k+)grid(k, uy, );void TankGame:test()for (int y = 0; y != 40; y+) for (int x = 0; x != 40; x+) if (gameSpaceyx.have)/ & gameSpaceyx.kind = 3)grid(x, 42+y, (char)gameSpaceyx.no);elsegrid(x, 42+y,。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值