赞
踩
先看一下效果:
初始游戏界面具有多个选项:
且具有多个可变设置项,方便个性化调整:
多个模式进行选择:
正式游戏界面,操作流畅,界面简单,且有操作提示:
使用函数封装代码和逻辑控制衔接每个界面,实现连贯性操作,使用逐帧动画的效果展示。
此时博主较忙,所以没有进行代码的讲解,不过原理较为简单,使用全部展示在下面了。
下面是代码:
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <time.h>
- #include <windows.h>
- #include <stdio.h>
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include<algorithm>
- #include<stdio.h>
- #include<string.h>
- #include<conio.h>
- #include<windows.h>
- #include<stdlib.h>
- #include <windows.h>
- #include<stdbool.h>
- using namespace std;
- #pragma warning(disable:4996)
- #define high 25 //数组高
- #define width 60 //数组宽
- #define border -1 //边界
- #define blank 0 //空白
- #define plane 1 //飞机
- #define bullet 2 //子弹
- #define enemy 3 //敌机
- #define destroy 4 //摧毁标记
-
- int canvas[high + 2][width + 2]; //游戏地图的高和宽
- int pos_h, pos_w; //战机位置
- int enemynum = 3; //敌机一次的刷新数量
- int record; //计时器,用次数计时
- int rec_move = 5; //敌机移动的次数频率
- int rec_new = 40; //敌机刷新的次数频率
- int score; //分数
- int num;//发射的子弹数目
- int Over?; //游戏判断监视
- int life = 3;//生命值
-
- void Startup(); //游戏数值初始化
- void Show(); //游戏界面输出
-
- //因输入导致的游戏状态更新
- void Update();//生存模式
- void Update1();//无敌模式
- void Update2();//多命模式
-
- //与输入无关的游戏状态更新
- void NoUpdate(); //生存模式
- void NoUpdate1();//无敌模式
- void NoUpdate2();//多命模式
- void HideCursor(); //隐藏光标
- void gotoxy(int x, int y); //回调光标
- int menu();//菜单面
- int introduce();//介绍面
- int control_introduce();//控制介绍
- int background_introduce();//背景介绍
-
- int setting();//设置面
- int speed_setting();//敌机移动速度设置
- int rec_new_setting();//刷新速度设置
- int enemynum_setting();//敌机一次刷新数目设置
- int life_setting();//生命数设置
- int mode();//模式选择面
- void mode1();//生存模式
- void mode2();//无敌模式
- void mode3();//多命模式
- void result();//结束界面
- void assist(double shoot);//射击评估
- void SetSize(unsigned uCol, unsigned uLine);//窗口大小设置
-
-
- int main() {
- OK:
- if (menu()) {
- int a = mode();
- //根据mode返回的数字判断选择模式
- //返回几就对应进入什么模式
- if (a == 1) {
- mode1();
- if (!Over?) {
- goto over;
- }
- }
- else if (a == 2) {
- mode2();
- if (!Over?) {
- goto over;
- }
- }
- else if (a == 3) {
- mode3();
- if (!Over?) {
- goto over;
- }
- }
- else if (a == 4) {
- goto OK;
- }
- }
- over:
- result();
- cout << "是否重新开始游戏?" << endl;
- cout << "1为是,0为退出游戏" << endl;
- int i = 0;
- cin >> i;
- switch (i) {
- case 1: system("cls"); goto OK; break;
- case 0: break;
- }
- return 0;
- }
- void Startup() { //游戏数值初始化
- Over? = 1;//Over?为1代表没死,为0代表死亡
- num = 0;//初始发射子弹为0
- score = 0; //初始化分数
- for (int i = 0; i < high + 2; i++) { //初始化矩阵元素
- for (int j = 0; j < width + 2; j++) {
- if (i == 0 || i == high + 1 ||
- j == 0 || j == width + 1) {
- canvas[i][j] = border;
- }
- else canvas[i][j] = blank;
- }
- }
- pos_h = high / 2; //初始化飞机竖直坐标
- pos_w = width / 2; //初始化飞机水平坐标
- canvas[pos_h][pos_w] = plane; //初始化飞机位置
- srand(time(NULL));
- record = 4; //初始化计数器
-
- }
- void Show() { //游戏界面输出
- HideCursor(); //隐藏光标
- gotoxy(1, 1); //回调光标、刷新画面
- for (int i = 0; i < high + 2; i++) {
- for (int j = 0; j < width + 2; j++) {
- if (canvas[i][j] == plane) { //当前位置为飞机位置
- printf("W");
- }
- else if (canvas[i][j] == bullet) { //当前位置为子弹位置
- printf("|");
- }
- else if (canvas[i][j] == enemy) { //当前位置为敌机位置
- printf("#");
- }
- else if (canvas[i][j] == border) { //当前位置为边界
- printf("$");
- }
- else if (canvas[i][j] == blank) { //当前位置无物,且在边界内
- printf(" ");
- }
- else if (canvas[i][j] == destroy) { //当前位置无物,且在边界内
- printf("x");
- }
- }
- printf("\n");
- }
- printf("\n你的得分为:%d", score);
- printf("\n已发射子弹数目:%d", num);
- printf("\n精准度为:%f", double(score) / double(num));
- printf("操作说明: ASDW分别操作 左下右上四个的移动\n");
- printf("**空格是发出子弹**\n");
- printf("**T退出游戏**\n");
- }
- void Update() { //因输入导致的游戏状态更新
- //GetKeyState如果高位为1表示按键按下,此时返回值为负数(<0);如果高位为0表示按键弹起,此时返回值为正数(>0)
- char key_W = GetKeyState('W'), //监测 W 键是否按下
- key_S = GetKeyState('S'), //监测 S 键是否按下
- key_A = GetKeyState('A'), //监测 A 键是否按下
- key_D = GetKeyState('D'), //监测 D 键是否按下
- key_attack = GetKeyState(' '),//监测 空格 键是否按下
- key_out = GetKeyState('T');//监测 T 键是否按下
- if (kbhit()) { //当有键按下时为1,无为0
- if (key_W < 0) { //当按下 W 键,上移
- if (pos_h > 1) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h - 1][pos_w] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h - 1][pos_w] = destroy;
- Over? = 0;
- }
- else canvas[--pos_h][pos_w] = plane;
- }
- }
- if (key_S < 0) { //当按下 S 键,下移
- if (pos_h < high) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h + 1][pos_w] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h + 1][pos_w] = destroy;
- Over? = 0;
- }
- else canvas[++pos_h][pos_w] = plane;
- }
- }
- if (key_A < 0) { //当按下 A 键,左移
- if (pos_w > 1) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h][pos_w - 1] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h][pos_w - 1] = destroy;
- Over? = 0;
- }
- else canvas[pos_h][--pos_w] = plane;
- }
- }
- if (key_D < 0) { //当按下 D 键,右移
- if (pos_w < width) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h][pos_w + 1] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h][pos_w + 1] = destroy;
- Over? = 0;
- }
- else canvas[pos_h][++pos_w] = plane;
- }
- }
- if (key_attack < 0) { //当按下空格键,发射子弹
- if (pos_h != 1) {
- canvas[pos_h - 1][pos_w] = bullet;
- num++;
- }
- }
- if (key_out < 0) {
- Over? = 0;
- }
- }
- }
- void Update1() { //因输入导致的游戏状态更新
- char key_W = GetKeyState('W'), //监测 W 键是否按下
- key_S = GetKeyState('S'), //监测 S 键是否按下
- key_A = GetKeyState('A'), //监测 A 键是否按下
- key_D = GetKeyState('D'), //监测 D 键是否按下
- key_attack = GetKeyState(' '), //监测 空格 键是否按下
- key_out = GetKeyState('T');//监测 T 键是否按下
- if (kbhit()) { //当有键按下时为1,无为0
- if (key_W < 0) { //当按下 W 键,上移
- if (pos_h > 1) {
- canvas[pos_h][pos_w] = blank;
- canvas[--pos_h][pos_w] = plane;
- }
- }
- if (key_S < 0) { //当按下 S 键,下移
- if (pos_h < high) {
- canvas[pos_h][pos_w] = blank;
- canvas[++pos_h][pos_w] = plane;
- }
- }
- if (key_A < 0) { //当按下 A 键,左移
- if (pos_w > 1) {
- canvas[pos_h][pos_w] = blank;
- canvas[pos_h][--pos_w] = plane;
- }
- }
- if (key_D < 0) { //当按下 D 键,右移
- if (pos_w < width) {
- canvas[pos_h][pos_w] = blank;
- canvas[pos_h][++pos_w] = plane;
- }
- }
- if (key_attack < 0) { //当按下空格键,发射子弹
- if (pos_h != 1) {
- canvas[pos_h - 1][pos_w] = bullet;
- num++;
- }
- }
- if (key_out < 0) {
- Over? = 0;
- }
- }
- }
- void Update2() { //因输入导致的游戏状态更新
- char key_W = GetKeyState('W'), //监测 W 键是否按下
- key_S = GetKeyState('S'), //监测 S 键是否按下
- key_A = GetKeyState('A'), //监测 A 键是否按下
- key_D = GetKeyState('D'), //监测 D 键是否按下
- key_attack = GetKeyState(' '),//监测 空格 键是否按下
- key_out = GetKeyState('T');//监测 T 键是否按下
- if (kbhit()) { //当有键按下时为1,无为0
- if (key_W < 0) { //当按下 W 键,上移
- if (pos_h > 1) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h - 1][pos_w] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h - 1][pos_w] = destroy;
- life--;
- if (life == 0) { Over? = 0; }
- }
- else canvas[--pos_h][pos_w] = plane;
- }
- }
- if (key_S < 0) { //当按下 S 键,下移
- if (pos_h < high) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h + 1][pos_w] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h + 1][pos_w] = destroy;
- life--;
- if (life == 0) { Over? = 0; }
- }
- else canvas[++pos_h][pos_w] = plane;
- }
- }
- if (key_A < 0) { //当按下 A 键,左移
- if (pos_w > 1) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h][pos_w - 1] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h][pos_w - 1] = destroy;
- life--;
- if (life == 0) { Over? = 0; }
- }
- else canvas[pos_h][--pos_w] = plane;
- }
- }
- if (key_D < 0) { //当按下 D 键,右移
- if (pos_w < width) {
- canvas[pos_h][pos_w] = blank;
- if (canvas[pos_h][pos_w + 1] == enemy) { //下个位置是敌机,撞毁
- canvas[pos_h][pos_w + 1] = destroy;
- life--;
- if (life == 0) { Over? = 0; }
- }
- else canvas[pos_h][++pos_w] = plane;
- }
- }
- if (key_attack < 0) { //当按下空格键,发射子弹
- if (pos_h != 1) {
- canvas[pos_h - 1][pos_w] = bullet;
- num++;
- }
- }
- if (key_out < 0) {
- Over? = 0;
- }
- }
- }
- void NoUpdate() { //与输入无关的游戏状态更新
- int temp[high + 2][width + 2]; //用来判断原位置的临时数组
- for (int i = 1; i <= high; i++) {
- for (int j = 1; j <= width; j++) {
- temp[i][j] = canvas[i][j];
- }
- }
- for (int i = 1; i <= high; i++) { //遍历临时数组,修改数组
- for (int j = 1; j <= width; j++) {
- if (temp[i][j] == enemy && record % rec_move == 0) { //当前位置为敌机
- canvas[i][j] = blank;
- if (temp[i + 1][j] == bullet) { //下面为子弹,敌机被击中
- canvas[i + 1][j] = blank;
- score++;
-
- }
- else if (i < high) {
- canvas[i + 1][j] = enemy;
- }
- if (i + 1 == pos_h && j == pos_w) { //下面为飞机,玩家飞机被撞毁
- canvas[i + 1][j] = destroy;
- Over? = 0;
- }
- }
- if (temp[i][j] == bullet) { //当前位置为子弹
- canvas[i][j] = blank;
- if (temp[i - 1][j] == enemy) { //下个位置是敌机,敌机被击毁
- canvas[i - 1][j] = blank;
- score++;
-
- }
- else if (i > 1) {
- canvas[i - 1][j] = bullet;
- }
- }
- }
- }
- if (record % rec_new == 0) //刚好到时间间隔
- for (int i = 0; i < enemynum; i++) { //新增敌机群
- canvas[rand() % 2 + 1][rand() % width + 1] = enemy;
- }
- if (record <= 100) { //时间间隔计次
- record++;
- }
- else { //时间间隔计次清零
- record = 0;
- }
- }
- void NoUpdate1() { //与输入无关的游戏状态更新
- int temp[high + 2][width + 2]; //用来判断原位置的临时数组
- for (int i = 1; i <= high; i++) {
- for (int j = 1; j <= width; j++) {
- temp[i][j] = canvas[i][j];
- }
- }
- for (int i = 1; i <= high; i++) { //遍历临时数组,修改数组
- for (int j = 1; j <= width; j++) {
- if (temp[i][j] == enemy && record % rec_move == 0) { //当前位置为敌机
- canvas[i][j] = blank;
- if (temp[i + 1][j] == bullet) { //下面为子弹,敌机被击中
- canvas[i + 1][j] = blank;
- score++;
-
- }
- else if (i < high) {
- canvas[i + 1][j] = enemy;
- }
-
- }
- if (temp[i][j] == bullet) { //当前位置为子弹
- canvas[i][j] = blank;
- if (temp[i - 1][j] == enemy) { //下个位置是敌机,敌机被击毁
- canvas[i - 1][j] = blank;
- score++;
-
- }
- else if (i > 1) {
- canvas[i - 1][j] = bullet;
- }
- }
- }
- }
- if (record % rec_new == 0) //刚好到时间间隔
- for (int i = 0; i < enemynum; i++) { //新增敌机群
- canvas[rand() % 2 + 1][rand() % width + 1] = enemy;
- }
- if (record <= 100) { //时间间隔计次
- record++;
- }
- else { //时间间隔计次清零
- record = 0;
- }
- }
- void NoUpdate2() { //与输入无关的游戏状态更新
- int temp[high + 2][width + 2]; //用来判断原位置的临时数组
- for (int i = 1; i <= high; i++) {
- for (int j = 1; j <= width; j++) {
- temp[i][j] = canvas[i][j];
- }
- }
- for (int i = 1; i <= high; i++) { //遍历临时数组,修改数组
- for (int j = 1; j <= width; j++) {
- if (temp[i][j] == enemy && record % rec_move == 0) { //当前位置为敌机
- canvas[i][j] = blank;
- if (temp[i + 1][j] == bullet) { //下面为子弹,敌机被击中
- canvas[i + 1][j] = blank;
- score++;
-
- }
- else if (i < high) {
- canvas[i + 1][j] = enemy;
- }
- if (i + 1 == pos_h && j == pos_w) { //下面为飞机,玩家飞机被撞毁
- canvas[i + 1][j] = destroy;
- life--;
- if (life == 0) {
- Over? = 0;
- }
- }
- }
- if (temp[i][j] == bullet) { //当前位置为子弹
- canvas[i][j] = blank;
- if (temp[i - 1][j] == enemy) { //下个位置是敌机,敌机被击毁
- canvas[i - 1][j] = blank;
- score++;
-
- }
- else if (i > 1) {
- canvas[i - 1][j] = bullet;
- }
- }
- }
- }
- if (record % rec_new == 0) //刚好到时间间隔
- for (int i = 0; i < enemynum; i++) { //新增敌机群
- canvas[rand() % 2 + 1][rand() % width + 1] = enemy;
- }
- if (record <= 100) { //时间间隔计次
- record++;
- }
- else { //时间间隔计次清零
- record = 0;
- }
- }
- void gotoxy(int x, int y) { //回调光标
- COORD pos;
- pos.X = x - 1;
- pos.Y = y - 1;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
- }
- void HideCursor() { //隐藏光标函数
- CONSOLE_CURSOR_INFO cursor;
- cursor.bVisible = FALSE;
- cursor.dwSize = sizeof(cursor);
- HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorInfo(handle, &cursor);
- }
- int menu()
- {
- ///**********************************************************
- /// 函数名 :menu *
- /// 输入参数:无返回值 *
- /// 返回值 : 无 *
- /// 函数功能: *
- /// 用于显示主界面并衔接游戏设置 *
- ///**********************************************************
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "\t\t\t\t Annihilator Battle " << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- cout << "\t\t\t\t| 1:开始游戏 |" << endl;
- cout << "\t\t\t\t| 2: 设 置 |" << endl;
- cout << "\t\t\t\t| 3:游戏介绍 |" << endl;
- cout << "\t\t\t\t| 4:退出游戏 |" << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- HA:
- cout << "\t\t\t\t 请输入选项: ";
- int choice = 0;
- cin >> choice;
- switch (choice)
- {
- case 1:
- system("cls");//可以用gotoxy(0,0)
- rewind(stdin);
- return 1;
- break;
- case 2:
- system("cls");//可以用gotoxy(0,0)
- rewind(stdin);
- return setting();
- break;
- case 3:
- system("cls");//可以用gotoxy(0,0)
- rewind(stdin);
- return introduce();
- break;
- case 4:return 0; break;
- default:
- cout << "输入错误,请重新输入!!";
- goto HA;
- break;
- }
- }
- int introduce() {
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "\t\t\t\t introduce " << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- cout << "\t\t\t\t| 1:操作介绍 |" << endl;
- cout << "\t\t\t\t| 2:背景介绍 |" << endl;
- cout << "\t\t\t\t| 3:返 回 |" << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
-
- YE:
- cout << "\t\t\t\t 请输入选项:";
- int select;
-
- cin >> select;
-
- switch (select)
- {
- case 1:return control_introduce(); break;
- case 2:return background_introduce(); break;
- case 3:system("cls"); return menu(); break;
- default: cout << "输入错误,请重新输入!!";
- goto YE; break;
- }
- }
- int control_introduce() {
- system("cls");
- printf("操作说明: ASDW分别操作 左下右上四个的移动\n");
- printf("**空格是发出子弹**\n");
- printf("**T退出游戏**\n");
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,退出游戏为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return 0;
- }
- }
- int background_introduce() {
- system("cls");
- printf("飞机游戏是一款风靡全球的电视机游戏和掌上游戏机产品,\n");
- printf("曾几何时,它打造了一个无数人回忆的梦,\n");
- printf("曾几何时,它创造了一个无法企及的游戏巅峰,\n");
- printf("也曾影响了一代产业链。虽然它辉煌的业绩在历史的涡轮中渐渐远去,\n");
- printf("但这款游戏每每提及,总会令人爱不释手,魂牵梦绕。 \n");
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,返回设置为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return setting();
- }
- }
- int setting()
- {
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "\t\t\t\t Setting " << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- cout << "\t\t\t\t| 1:敌机移动速度 |" << endl;
- cout << "\t\t\t\t| 2:敌机刷新速度 |" << endl;
- cout << "\t\t\t\t| 3:敌机数目 |" << endl;
- cout << "\t\t\t\t| 4:生命数目 |" << endl;
- cout << "\t\t\t\t| 5:返 回 |" << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
-
- RE:
- cout << "\t\t\t\t 请输入选项:";
- int select;
-
- cin >> select;
- switch (select)
- {
- case 1:return speed_setting(); break;
- case 2:return rec_new_setting(); break;
- case 3:return enemynum_setting(); break;
- case 4:return life_setting(); break;
- case 5:system("cls"); return menu(); break;
- default: cout << "输入错误,请重新输入!!";
- goto RE; break;
- }
- }
- int speed_setting() {
- system("cls");
- cout << "提示:敌机速度尽量设置在0-15,且数值越大移动越慢" << endl;
- cout << "敌机的移动速度设置为:";
- cin >> rec_move;
- cout << "已修改速度为:" << rec_move;
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,返回设置为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return setting();
- }
- }
- int rec_new_setting() {
- system("cls");
- cout << "提示:敌机刷新速度尽量设置在1-20," << endl;
- cout << "备注:数值越小,刷新速度越快,但上限不超过设置的敌机数目!" << endl;
- cout << "敌机的刷新速度设置为:";
- cin >> rec_new;
- cout << "已修改敌机刷新速度为:" << rec_new;
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,返回设置为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return setting();
- }
- }
- int enemynum_setting() {
- system("cls");
- cout << "提示:敌机数目尽量设置在2-30," << endl;
- cout << "敌机的数目设置为:";
- cin >> enemynum;
- cout << "已修改敌机数目为:" << enemynum;
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,返回设置为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return setting();
- }
- }
- int life_setting() {
- system("cls");
- cout << "提示:生命数目尽量设置在2-30," << endl;
- cout << "生命的数目设置为:";
- cin >> life;
- cout << "已修改敌机数目为:" << life;
- cout << endl << "是否返回主菜单?" << endl << "返回主菜单为1,返回设置为0" << endl;
- cout << "你的选择是:";
- int i;
- cin >> i;
- if (i == 1) {
- system("cls");
- return menu();
- }
- if (i == 0) {
- system("cls");
- return setting();
- }
- }
- int mode()
- {
-
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "\t\t\t\t Mode " << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- cout << "\t\t\t\t| 1:生存模式 |" << endl;
- cout << "\t\t\t\t| 2:无敌模式 |" << endl;
- cout << "\t\t\t\t| 3:多命模式 |" << endl;
- cout << "\t\t\t\t| 4:主菜单 |" << endl;
- cout << "\t\t\t\t|-----------------------------|" << endl;
- WH:
- int select;
- cout << "\t\t\t\t 请输入选项:";
- cin >> select;
- switch (select)
- {
-
- case 1:
- system("cls");
- rewind(stdin);//清空输入缓冲区
- return 1;
- break;
- case 2:
- system("cls");
- rewind(stdin);
- return 2;
- break;
- case 3:
- system("cls");
- rewind(stdin);
- return 3;
- break;
- case 4:
- system("cls");
- rewind(stdin);
- return 4; break;
- default:
- cout << "输入错误,请重新输入!!";
- goto WH; break;
- }
- }
- void mode1() {
- SetSize(width + 10, high + 9);
- Startup(); //初始化
- while (Over?) { //游戏循环
- Update();
- NoUpdate();
- Show();
- }
- }
- void mode2() {
- SetSize(width + 10, high + 9);
- Startup(); //初始化
- while (Over?) { //游戏循环
- Update1();
- NoUpdate1();
- Show();
- }
- }
- void mode3() {
- SetSize(width + 10, high + 9);
- Startup(); //初始化
- while (Over?) { //游戏循环
- Update2();
- NoUpdate2();
- Show();
- cout << "剩余生命为:" << life;
- }
- }
- void result() {
- system("cls");
- double shoot = double(score) / double(num);
- cout << endl;
- cout << endl;
- cout << endl;
- cout << "\t\t\t\t game over! " << endl;
- cout << "\t\t\t\t|-----------------------------" << endl;
- printf("\t\t\t\t| 你的得分为:%d \n", score);
- printf("\t\t\t\t| 已发射子弹数目:%d \n", num);
- printf("\t\t\t\t| 精准度为:%f \n", shoot);
- cout << "\t\t\t\t|-----------------------------" << endl;
- //评价
- assist(shoot);
- cout << endl;
- Sleep(2500); //暂停游戏结束界面(毫秒)
- system("pause");
- }
- void assist(double shoot) {
- if (shoot > 0 && shoot <= 0.4)
- {
- cout << "\t\t\t\t| 你的精准度较低!!";
- }
- else if (shoot > 0.4 && shoot <= 0.7) {
- cout << "\t\t\t\t| 你的精准度较好!!";
- }
- else if (shoot > 0.7 && shoot <= 1.0) {
- cout << "\t\t\t\t| 你的精准度优秀!!";
- }
- }
- void SetSize(unsigned uCol, unsigned uLine)//控制台大小控制
- {
- char cmd[64];
- sprintf(cmd, "mode con cols=%d lines=%d", uCol, uLine);
- system(cmd);
- }
分享结束,谢谢!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。