版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、#include tank.h#include ConOperator.h#include #include #include #include using namespace std;TankGame:TankGame(int w, int h)/ 設定當前關數(shù)no = 1;/ 設定游戲整體高寬wide = w;high = h;HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);COORD sizePos = 2 * wide, high;SetConsoleScreenBufferSize(hStdOut, sizePos);/ 分配游戲空間
2、狀態(tài)表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;ga
3、meSpaceyx.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、;/ 數(shù)目初始化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;wh
5、ile (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.to
7、tal) 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 != RI
9、GHT)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+)gri
10、d(7, 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
11、+2*i,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(2
12、0, 20, 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 t
13、asks;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 | co
14、mmand = 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.(Violato
15、rs will 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;
16、int cirY = 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 wide - 1) for (int k = u; k 0) for (int k = u; k = b; k+)grid(lx, k, );if (
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 小額汽車貸款合同范例
- 2024年企業(yè)租車合同協(xié)議樣本
- 標準版市政道路工程合同
- 上門服務協(xié)議合同范本2024年
- 小型貨車銷售合同
- 網(wǎng)絡廣告合作協(xié)議
- 2024年度網(wǎng)絡安全防護服務合同
- 辦公租賃合同模板
- (2024版)人工智能醫(yī)療診斷系統(tǒng)開發(fā)合同
- 2024年度醫(yī)療器械獨家代理合同
- 跨境數(shù)據(jù)流動的全球治理進展、趨勢與中國路徑
- 【多旋翼無人機的組裝與調(diào)試5600字(論文)】
- 2023年遼陽市宏偉區(qū)事業(yè)單位考試真題
- 環(huán)境工程專業(yè)英語 課件
- 繼電保護動作分析報告課件
- 五年級數(shù)學上冊8解方程課件
- 教學工作中存在問題及整改措施
- 內(nèi)部項目跟投協(xié)議書(正)
- 鋼管靜壓樁質(zhì)量監(jiān)理細則
- 5000頭奶牛養(yǎng)殖場新建項目環(huán)境評估報告書
- 16飛機顛簸教學課件
評論
0/150
提交評論