C++ 发展历程全解析

news/2024/12/21 10:38:18/

引言

C++ 是一种静态类型的、编译式的、通用的、大小写敏感的、不仅支持面向过程的程序设计,还支持面向对象的程序设计(OOP)和泛型编程的程序设计语言。它由丹麦计算机科学家 Bjarne Stroustrup 于1979年在贝尔实验室开始设计开发。C++ 的发展经历了多个阶段,从最初的实验性扩展到如今广泛应用于各种领域的成熟语言。本文将带你回顾 C++ 的发展历程,并探讨其未来的发展方向。


一、C++ 的起源与早期发展 (1979 - 1985)

1.1 C with Classes 的诞生

1979年,Bjarne Stroustrup 在研究分布式系统时遇到了一些问题,他发现当时的编程语言无法很好地满足他的需求。于是,他决定基于 C 语言进行扩展,加入类的概念,从而创建了 "C with Classes"。这是 C++ 的雏形,它引入了类、继承等面向对象的特性,但仍然保留了 C 语言的高效性和灵活性。

1.2 第一个 C++ 编译器 cfront

1983年,Stroustrup 开发了第一个 C++ 编译器 cfront,它可以将 C++ 代码转换为 C 代码,然后再用传统的 C 编译器编译。cfront 的出现极大地推动了 C++ 的普及和发展,使得更多开发者能够使用这种强大的新语言。


二、标准化进程 (1985 - 2003)

2.1 C++ 成为商业产品

1985年,AT&T 发布了第一个商用版本的 C++ 编译器,标志着 C++ 正式进入市场。同年,Stroustrup 出版了《The C++ Programming Language》第一版,这本书成为了 C++ 程序员的经典参考书之一。

2.2 ANSI/ISO 标准化

随着 C++ 的流行,不同厂商的实现之间出现了兼容性问题。为了统一标准,1990年成立了 ANSI 和 ISO 的联合委员会来制定 C++ 的国际标准。经过多年的努力,1998年发布了第一个正式的 C++ 标准 ISO/IEC 14882:1998,即 C++98。这个版本奠定了现代 C++ 的基础,引入了许多重要的特性,如模板、异常处理、RTTI(运行时类型识别)等。

2.3 C++03 标准

2003年,C++ 标准进行了小幅修订,形成了 C++03。这次修订主要是修复了一些已知的问题,并对标准库进行了优化。虽然没有引入太多新特性,但它为后续版本的发展奠定了坚实的基础。


三、现代化转型 (2003 - 2011)

3.1 C++0x 计划

进入新世纪后,C++ 社区意识到需要进一步增强语言的功能以适应新的计算环境。因此,提出了 C++0x 计划,旨在通过一系列重大改进使 C++ 更加现代化。然而,由于涉及的内容过于庞大复杂,导致该计划未能按时完成,最终推迟到了2011年才发布,也就是我们熟知的 C++11。

3.2 C++11 标准

C++11 是 C++ 历史上最重要的里程碑之一。它引入了大量创新性的特性,包括但不限于:

  • 自动类型推导auto 和 decltype
  • Lambda 表达式
  • 右值引用与移动语义
  • 智能指针std::unique_ptrstd::shared_ptr
  • 线程库:多线程编程的支持
  • 正则表达式库
  • 随机数生成库

这些特性的加入让 C++ 不仅保持了原有的高性能优势,同时也变得更加简洁易用,大大提高了开发效率。


四、持续演进 (2011 - 至今)

4.1 C++14 标准

继 C++11 之后,C++14 作为一次较小规模的更新,在2014年发布。它主要集中在对 C++11 特性的完善和优化上,例如:

  • 支持可变参数模板的默认模板参数
  • 泛型 lambda 表达式
  • 返回类型后置语法
  • 以及一些标准库的改进

尽管变化不大,但这些改进依然提升了代码的可读性和表达力。

4.2 C++17 标准

2017年发布的 C++17 又是一次较为全面的升级,带来了许多实用的新特性:

  • 结构化绑定:简化了从元组或结构体中解构数据的方式
  • 内联变量:允许在头文件中定义全局变量而不会引起重复定义错误
  • if/switch 初始化器:可以在条件语句中直接声明并初始化变量
  • 文件系统库:提供了跨平台的操作文件系统的接口
  • 并行算法:增强了 STL 中算法的并发执行能力

此外,C++17 还移除了某些过时的特性,使语言更加精简。

4.3 C++20 标准

2020年是 C++ 的又一个重要年份,C++20 标准正式发布。这一版本引入了多项革命性的特性,彻底改变了 C++ 的面貌:

  • 模块化:解决了长期以来困扰 C++ 的头文件依赖问题,显著提高了编译速度
  • 协程:支持异步编程模型,简化了复杂的任务调度逻辑
  • 概念:为模板编程提供了一种更安全、更直观的方式
  • 范围库:增强了迭代器和容器的操作方式,提供了更灵活的数据处理手段

C++20 的发布标志着 C++ 已经成为一门真正意义上的现代编程语言,具备了与其他新兴语言竞争的实力。

4.4 C++23 及未来展望

目前,C++23 的工作正在进行当中,预计将在2023年底或2024年初发布。根据当前的提案,我们可以期待看到更多令人兴奋的变化,比如:

  • 继续改进模块系统
  • 引入更多的语言级并发支持
  • 对现有标准库进行扩展和完善

总之,C++ 的发展从未停止,它始终紧跟时代步伐,不断吸收新的思想和技术,力求为开发者提供更好的工具和服务。


结语

从最初的小众实验性语言到如今广泛应用于各个领域的主流编程语言,C++ 走过了漫长而辉煌的道路。每一次标准的更新都凝聚着无数开发者的心血和智慧,也为后来者铺平了前进的道路。相信在未来,C++ 将继续发挥其独特的优势,在软件开发领域占据重要地位。

个人看法

一、C++ 的现状与挑战

尽管 C++ 已经取得了巨大的成功,但它仍然面临着一些挑战和争议。以下是一些主要的问题:

  1. 复杂性
    C++ 的语法和语义非常复杂,学习曲线陡峭。许多高级特性(如模板元编程、多重继承、虚函数等)需要开发者具备深厚的知识背景和丰富的经验。这种复杂性不仅增加了学习成本,还可能导致代码难以维护和调试。

  2. 性能与安全性的平衡
    C++ 以其高性能著称,但在追求性能的同时,安全性往往被忽视。例如,指针操作容易引发内存泄漏、空指针解引用等问题。虽然 C++ 引入了智能指针和 RAII 等机制来提高安全性,但这些问题仍然存在。如何在保持高性能的同时提升安全性,是 C++ 面临的一个重要挑战。

  3. 跨平台支持
    尽管 C++ 可以在多种平台上运行,但不同平台之间的差异仍然较大。例如,Windows 和 Linux 系统在文件路径、线程模型等方面存在差异,这给跨平台开发带来了困难。此外,C++ 编译器的实现也不完全一致,导致代码在不同编译器上可能表现出不同的行为。

  4. 社区与生态
    C++ 拥有一个庞大的开发者社区,但也存在一些问题。例如,C++ 的标准委员会(ISO C++ Committee)决策过程较为缓慢,新特性的引入周期较长。此外,C++ 的文档和教程质量参差不齐,缺乏统一的学习资源。这些问题影响了 C++ 的普及和发展。

二、C++ 的未来展望

面对上述挑战,C++ 社区正在积极寻求解决方案,推动语言的进一步发展。以下是 C++ 未来可能的发展方向:

  1. 简化语法与提高易用性
    未来的 C++ 版本可能会继续简化语法,降低学习门槛。例如,引入更多的自动推导机制(如 auto 和 decltype),减少显式类型声明;引入更简洁的语法糖(如范围 for 循环、结构化绑定等),提高代码的可读性和简洁性。此外,C++ 可能会借鉴其他语言的成功经验,引入一些新的编程范式(如函数式编程、数据流编程等),丰富编程表达方式。

  2. 增强安全性和可靠性
    安全性是 C++ 未来发展的重要方向之一。未来的 C++ 版本可能会引入更多的静态分析工具和编译时检查机制,帮助开发者提前发现潜在的安全隐患。例如,引入更严格的指针操作规则,防止空指针解引用;引入更智能的内存管理机制,减少内存泄漏和越界访问等问题。此外,C++ 可能会借鉴 Rust 等语言的经验,引入所有权和借用检查机制,从根本上解决内存安全问题。

  3. 提升性能与效率
    性能一直是 C++ 的核心优势之一,未来的 C++ 版本将继续优化性能。例如,引入更多的编译时优化技术(如内联展开、常量折叠等),减少运行时开销;引入更高效的并发编程模型(如协程、任务并行库等),充分利用多核处理器的计算能力。此外,C++ 可能会进一步优化标准库的实现,提供更高性能的数据结构和算法。

  4. 加强跨平台支持
    未来的 C++ 版本可能会加强对跨平台开发的支持。例如,引入更多的跨平台库(如 Boost、Qt 等),简化跨平台开发流程;引入更统一的文件系统接口和线程模型,减少不同平台之间的差异。此外,C++ 可能会进一步规范编译器的行为,确保代码在不同编译器上具有一致的行为。

  5. 构建更完善的生态系统
    C++ 社区正在努力构建一个更完善的生态系统。例如,引入更多的开源项目和第三方库,丰富 C++ 的应用场景;引入更高质量的文档和教程,降低学习成本;引入更活跃的技术交流平台(如 Stack Overflow、GitHub 等),促进开发者之间的合作与交流。此外,C++ 标准委员会也在加快决策速度,缩短新特性引入的周期,推动语言的快速发展。

附录

一、C++不同标准可运行的代码:

C++98

这是最早的C++标准之一,引入了STL(标准模板库)等重要特性。

// C++98 特性示例
#include <iostream>
#include <vector>int main() {std::vector<int> vec;vec.push_back(1);vec.push_back(2);for (std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) {std::cout << *it << " ";}std::cout << std::endl;return 0;
}

C++03

C++03 主要是对C++98的缺陷修复和澄清,并没有引入太多新特性。

// C++03 没有显著的新特性,但可以使用一些改进后的库函数
#include <iostream>
#include <vector>
#include <algorithm>int main() {std::vector<int> vec = {1, 2, 3, 4, 5};std::sort(vec.begin(), vec.end());for (std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it) {std::cout << *it << " ";}std::cout << std::endl;return 0;
}

C++11

C++11 引入了许多现代化的特性,如autolambda表达式、nullptr、右值引用等。

// C++11 特性示例
#include <iostream>
#include <vector>
#include <memory>int main() {// 使用 auto 和 lambda 表达式auto vec = std::vector<int>{1, 2, 3, 4, 5};vec.push_back(6);// Lambda 表达式std::for_each(vec.begin(), vec.end(), [](int x) { std::cout << x << " "; });std::cout << std::endl;// 使用智能指针std::unique_ptr<int> ptr(new int(10));std::cout << *ptr << std::endl;return 0;
}

C++14

C++14 是对C++11的小幅增强,增加了泛型lambda表达式、返回类型推导等。

// C++14 特性示例
#include <iostream>
#include <vector>int main() {// 泛型 lambda 表达式auto print = [](auto x) { std::cout << x << " "; };auto vec = std::vector<int>{1, 2, 3, 4, 5};std::for_each(vec.begin(), vec.end(), print);std::cout << std::endl;// 返回类型推导auto add = [](int a, int b) -> decltype(a + b) { return a + b; };std::cout << add(3, 4) << std::endl;return 0;
}

C++17

C++17 引入了结构化绑定、if/switch语句中的初始化器、文件系统库等。

// C++17 特性示例
#include <iostream>
#include <tuple>
#include <filesystem>int main() {// 结构化绑定std::tuple<int, double, char> t = std::make_tuple(42, 3.14, 'A');auto [i, d, c] = t;std::cout << i << ", " << d << ", " << c << std::endl;// 文件系统库namespace fs = std::filesystem;std::cout << "Current path is: " << fs::current_path() << std::endl;return 0;
}

C++20

C++20 引入了概念(Concepts)、模块(Modules)、协程(Coroutines)等重大特性。

// C++20 特性示例
#include <iostream>
#include <concepts>
#include <coroutine>// Concepts 示例
template<typename T>
concept Integral = std::is_integral_v<T>;void print(Integral auto x) {std::cout << x << std::endl;
}// 协程示例
struct Task {struct promise_type {Task get_return_object() { return {}; }std::suspend_never initial_suspend() { return {}; }std::suspend_never final_suspend() noexcept { return {}; }void return_void() {}void unhandled_exception() {}};
};Task async_op() {co_await std::suspend_always{};
}int main() {print(42); // 只能传入整数类型// 协程调用async_op();return 0;
}

二、基于C++20标准的小游戏(参考) 

*注:以下部分需要Windows环境

1.贪吃蛇

#include <iostream>
#include <list>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <algorithm>
#include <conio.h>
#include <windows.h>
using namespace std;
class Node {
public:int x, y;Node(int x1, int y1);
};class UserData {
public:string name;long long score;int gt;int gr;UserData(string s, long long sc,int gametime,int grade);friend bool operator < (UserData a, UserData b);
};#define RIGHT 0x4d
#define LEFT 0x4b
#define UP 0x48
#define DOWN 0x50
#define YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define CYAN FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define ORANGE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define PURPLE FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define RED  FOREGROUND_RED | FOREGROUND_INTENSITY
const int STARTX = 8;
const int STARTY = 4;
const int RANGEX = 60;
const int RANGEY = 20;
int point=10;
const int ENDX = STARTX + RANGEX;
const int ENDY = STARTY + RANGEY;
bool isSnake[RANGEY + 10 ][RANGEX + 10];
int speed;
int sysj;
int gametime;
list<Node> snake;
int curDiraction; //蛇的当前前进方向, 1上, 2下, 3左, 4右
int score; //当前分数
int grade;
int snakeLen; //蛇的长度
int foodx, foody; //食物坐标
int gox, goy; //蛇头坐标
int mj;
void GoTo(short x, short y); //定位光标
void DrawBoard(); //绘制边框
void ShowInformation(); //展示游戏信息
void Init(); //初始化游戏
void RunSnake(int x, int y); //绘制蛇身
void Try(int& x, int& y); //试走
bool IsGoodCoord(int x, int y); //前进坐标是否合法
void AddFood();
void EartFood();
void InitSnake();
bool EndGame();
bool StartGame();
bool GameMenu(); //游戏菜单
void ShowRanking(); //排行榜
void ShowAbout(); //相关信息
void InputData(); //输入玩家名字int main() {while (true) {if (!GameMenu()) return 0;}return 0;
}Node::Node(int x1, int y1) { //构造Node对象x = x1; y = y1;
}int SuiJi()
{
srand((unsigned)time(NULL));
return (rand()*rand()+rand()*rand())%14;
}bool operator < (UserData a, UserData b) { //重载运算符,按分数由大到小排列if(a.score != b.score)return a.score > b.score;if(a.gt !=b.gt)return a.gt > b.gt;elsereturn a.gr > b.gr;
}
UserData::UserData(string s, long long sc,int gametime_,int _grade) { //构造UserData对象name = s; score = sc; gt=gametime_; gr=_grade;
}void color(WORD A)
{SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), A);
}void Color(int a)
{switch (a%4){case 0:color(RED);break;case 1:color(CYAN);break;case 2:color(YELLOW);break;case 3:color(PURPLE);break;}
}void GoTo(short x, short y) { //定位光标COORD coord = { x, y };SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
//第一部分代码 
void ShowInformation() { //输出游戏信息color(YELLOW);GoTo(73,5);printf("贪吃蛇游戏 v1.1");GoTo(78,18);gametime=(clock()-mj)/1000;grade=snakeLen-3;printf("生存时间:%3d 秒",(clock()-mj)/1000);GoTo(78,8);printf("游戏规则:");GoTo(78,10);printf("请按 ↑ ↓ ← →来控制您的蛇吃东西");GoTo(78,12);printf("吃得越多,蛇就越长,您的等级也将越高");GoTo(78,14);printf("当蛇吃到自己或撞上墙时,游戏结束");GoTo(78,16);printf("自动前进时间:%3dms",speed);GoTo(78,20);printf("当前等级: %8d",snakeLen-3);GoTo(78,23);printf("您的分数: %d",score);color(CYAN);printf("+%D=%d",score/3,score*3/2);color(YELLOW);GoTo(78,25);printf("剩余时间:%d秒",20+(snakeLen-3)*5-gametime);sysj=20+(snakeLen-3)*5-gametime;}void DrawBoard() { //绘制墙体HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //获得输出句柄CONSOLE_CURSOR_INFO cursor_info = { 1, 0 }; //光标信息SetConsoleCursorInfo(hOut, &cursor_info); //隐藏光标COORD size = { 120, 30 };SetConsoleScreenBufferSize(hOut, size); //重设缓冲区大小SMALL_RECT rc = { 0 , 0, 120, 30 };SetConsoleWindowInfo(hOut, true, &rc); //重设窗口大小SetConsoleTextAttribute(hOut, CYAN);for (int i = STARTX - 2; i <= ENDX + 2; i += 2) { //横向墙体GoTo(i, STARTY - 1);printf("■");GoTo(i, ENDY + 1);printf("■");}for (int i = STARTY - 1; i <= ENDY + 1; ++i) { //竖向墙体GoTo(STARTX - 2, i);printf("■");GoTo(ENDX + 2, i);printf("■");}
}
void draw()
{char m=snakeLen+62;Color(score);cout<<m;}
void Init() { //初始化游戏system("cls");memset(isSnake, 0, sizeof(isSnake));speed = 200;curDiraction = 4;score = 0;DrawBoard();InitSnake();ShowInformation();AddFood();mj=clock();point=20;sysj=20;
}void RunSnake(int x, int y) { //绘制蛇身SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);score += snakeLen + 1;if (x == foodx && y == foody) {EartFood();AddFood();return;}DrawBoard();snake.push_front(Node(x, y));isSnake[y][x] = true;GoTo(x, y);draw();Node back = snake.back();snake.pop_back();isSnake[back.y][back.x] = false;GoTo(back.x, back.y);printf(" ");
}void Try(int& x, int& y) { //试走int key, cnt = 100;while (cnt--) { //多次检测键盘状态if (_kbhit()) {key = getch();switch (key) {case UP:
//                if (curDiraction == 1 || curDiraction == 2) break;--y; curDiraction = 1; return;case DOWN:
//                if (curDiraction == 1 || curDiraction == 2) break;++y; curDiraction = 2; return;case LEFT:
//                if (curDiraction == 3 || curDiraction == 4) break;x -= 2; curDiraction = 3; return;case RIGHT:
//                if (curDiraction == 3 || curDiraction == 4) break;x += 2; curDiraction = 4; return;}}}if (curDiraction == 1) --y; //用户没有输入时else if (curDiraction == 2) ++y;else if (curDiraction == 3) x -= 2;else x += 2;
}bool IsGoodCoord(int x, int y) { //判断光标是否合法if (x <= ENDX && y <= ENDY && x >= STARTX && y >= STARTY)return true;elsereturn false;
}void AddFood() { //增加食物SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), PURPLE);srand((unsigned)time(NULL));while (true) {foodx = (rand()%ENDX) + 1;foody = (rand()%ENDY) + 1;if (foodx&1) foodx++;if (!isSnake[foody][foodx] && IsGoodCoord(foodx, foody)) break;}GoTo(foodx, foody);int a=rand()%5;if(a>=4)printf("@");else if(a<=1)printf("#");elseprintf("&");
}void EartFood() { //吃东西point+=4;int sb=gametime=(clock()-mj)/1000;sysj=point-sb;score+=score/2;SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);snake.push_front(Node(foodx, foody));isSnake[foody][foodx] = true;++snakeLen;if (speed >= 55) speed -= 5;GoTo(foodx, foody);draw();AddFood();
}void InitSnake() { //初始化蛇身SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);snakeLen = 3, gox = 18, goy = 14;snake.clear();snake.push_front(Node(12, 14));snake.push_front(Node(14, 14));snake.push_front(Node(16, 14));for (int i = 12; i <= 16; i += 2) {GoTo(i, 14);draw();isSnake[14][i] = true;}
}
bool EndGame() { //结束游戏system("cls");DrawBoard();SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);GoTo(28, 10);printf("您的本局游戏得分: %d分", score);GoTo(32, 18);printf("....你挂了....");GoTo(27, 20);printf("是否继续游戏: 是(1), 否(0)");GoTo(27, 22);char key = getch();while (true) {if (key == '1') return false;else if (key == '0'){GoTo(ENDX+1,ENDY+2);exit(0);return true;}else key = getch();}
}bool StartGame() { //启动游戏Init();while (sysj>0) { //开挂RunSnake(gox, goy);ShowInformation();Try(gox, goy);Sleep(speed);}InputData();return true;
}
//第二部分代码 
bool GameMenu() { //游戏菜单system("cls");DrawBoard();GoTo(STARTX+22,STARTY+4);printf("欢迎进入游戏!");GoTo(STARTX+24,STARTY+10);printf("1.新游戏");GoTo(STARTX+24,STARTY+12);printf("2.排行榜");GoTo(STARTX+24,STARTY+14);printf("3.关于游戏");GoTo(STARTX+24,STARTY+16);printf("4.退出游戏");while (true) {if (_kbhit()) {char key = getch();switch (key) {case '1':if (!StartGame()) return false;else return true;case '2':ShowRanking(); return true;case '3':ShowAbout(); return true;case '4':GoTo(1,ENDY+2);return false;default:return true;}}}
}void ShowRanking() { //展示排行榜vector<UserData> vu;FILE *fp = fopen("Gamedata2.txt", "r");if (fp == NULL) fp = fopen("Gamedata2.txt", "w+");char name[20];int len = 0;while (fscanf(fp, "%s", name) != EOF) {++len;int score,g=grade;fscanf(fp, "%d%d%d%*c", &score,&gametime,&g);vu.push_back(UserData(string(name), score,gametime,g));}fclose(fp);sort(vu.begin(), vu.end()); //对得分进行排名system("cls");DrawBoard();SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), CYAN);GoTo(STARTX + 8, STARTY + 2);printf("用户");GoTo(STARTX + 20, STARTY + 2);printf("分数");GoTo(STARTX + 32, STARTY + 2);printf("生存时间");GoTo(STARTX + 44, STARTY + 2);printf("排行");SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);for (int i = 0; i < len && i < 10; ++i) { //打印前十名用户数据char const *p = vu[i].name.c_str();Color(score);GoTo(STARTX + 8, STARTY + 4 + i);printf("%s", p);GoTo(STARTX + 20, STARTY + 4 + i);printf("%d分", vu[i].score);GoTo(STARTX + 32, STARTY + 4 + i);printf("%d秒", vu[i].gt);GoTo(STARTX + 44, STARTY + 4 + i);printf(" %d", i + 1);}GoTo(STARTX + 4, ENDY - 2);printf("-----------------  按'1'返回游戏菜单  ---------------");while (true) {if (_kbhit()) {char key = getch();if (key == '1') break;}}
}void ShowAbout() { //展示游戏相关system("cls");DrawBoard();SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), YELLOW);GoTo(STARTX + 4, STARTY + 2);printf("-------------------  贪吃蛇游戏  -------------------");GoTo(STARTX + 10,STARTY + 8);printf("贪吃蛇游戏");GoTo(STARTX + 10,STARTY + 10);printf("游戏规则:");GoTo(STARTX + 10,STARTY + 12);printf("请按 ↑ ↓ ← →  来控制您的蛇吃东西");GoTo(STARTX + 10,STARTY + 14);printf("吃的越多,蛇就越长,您的等级也将越高");GoTo(STARTX + 10,STARTY + 16);printf("当蛇吃到自己或撞上墙时,游戏结束。");GoTo(STARTX + 4, ENDY - 2);printf("-----------------  按'1'返回游戏菜单  ---------------");while (true) {if (_kbhit()) {char key = getch();if (key == '1') break;}}
}void InputData() { //用户输入名字char name[20];if(score>=1000){GoTo(STARTX + 10, STARTY + 10);SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), RED);printf("请输入你的名字: ");COORD coord = { STARTX + 10, STARTY + 12 };SetConsoleCursorPosition(GetStdHandle(STD_INPUT_HANDLE), coord);while (true) { //忽略非法字符scanf("%s", name);if (name[0] != 0 && name[0] != ' ') break;}FILE *fp = fopen("Gamedata2.txt", "a");if (fp == NULL) fp = fopen("Gamedata2.txt", "w+");fprintf(fp, "%s %d %d \n", name, score,gametime);fclose(fp);}else{GoTo(STARTX + 20, STARTY + 10);cout<<"哟!这分数也能上榜??"<<endl;Sleep(1000);}EndGame();}

2.俄罗斯方块

#include<iostream>#include<string>#include<cstdlib>#include<windows.h>#include<ctime>#include<conio.h>#include<cstdio>using namespace std;class Tetris{private:int rank; // 游戏难度等级int score; // 得分int id; // 图形IDint point[2]; // 两基点int top; // 最高点高度public:Tetris();void Welocme(); // 首界面void DrawMap(); // 游戏界面void SetColor(int); // 控制颜色void Draw(int, int, int); // 画图形void Run(); // 运行游戏void ReDraw(int, int, int); // 清除图形bool Judge(int, int, int);void Turn(int); // 旋转void Updata(); // 更新界面void Pause(); // 游戏暂停void Input_score();};const int sharp[15][8] = //组成图形的各个点的各个坐标,先纵后横{{0,0,1,0,2,0,3,0},{0,0,0,1,0,2,0,3},{0,0,1,0,0,1,1,1},{0,0,1,0,1,1,1,2},{0,1,1,1,2,0,2,1},{0,0,0,1,0,2,1,2},{0,0,0,1,1,0,2,0},{1,0,1,1,1,2,0,2},{0,0,0,1,1,1,2,1},{0,0,0,1,0,2,1,0},{0,0,1,0,2,0,2,1},{0,0,0,1,1,1,1,2},{0,1,1,0,1,1,2,0},{0,1,0,2,1,0,1,1},{0,0,1,0,1,1,2,1}};const int high[15] = { 4,1,2,2,3,2,3,2,3,2,3,2,3,2,3 };int map[28][16];#define a1 0 //条形#define a2 1#define b 2 // 方块#define c1 3 //L形#define c2 4#define c3 5#define c4 6#define d1 7 //T形#define d2 8#define d3 9#define d4 10#define e1 11 //闪电1形#define e2 12#define f1 13 //闪电2形#define f2 14Tetris::Tetris() //构造函数, 初始化各个值{point[0] = 0;point[1] = 5;score = 0;top = 25;}void Tetris::Turn(int num) //旋转函数{switch (num){case a1: id = a2; break; //条形互换case a2: id = a1; break;case b: id = b; break; //方块无法旋转case c1: id = c2; break; //各种L形互换case c2: id = c3; break;case c3: id = c4; break;case c4: id = c1; break;case d1: id = d2; break; //各种T形互换case d2: id = d3; break;case d3: id = d4; break;case d4: id = d1; break;case e1: id = e2; break; //两种闪电形互换case e2: id = e1; break;case f1: id = f2; break;case f2: id = f1; break;}}void SetPos(int i, int j) //控制光标位置, 列, 行{COORD pos = { i,j };SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}void Tetris::Pause() // 暂停函数{SetPos(32, 10);cout << "游戏已暂停!" << endl;SetPos(30, 11);cout << "你的分数为:" << score;char temp;while (1){while (1){if (_kbhit()){temp = _getch();break;}}if (temp == 32)break;}SetPos(32, 10); // 清除暂停时显示的信息cout << " ";SetPos(30, 11);cout << " ";}void Tetris::Updata() //更新函数{int i, flag;int nx, ny;for (i = 0; i < 4; i++){nx = point[0] + sharp[id][i * 2];ny = point[1] + sharp[id][i * 2 + 1];SetPos((ny + 1) * 2, nx + 1);SetColor(0);cout << "■";map[nx][ny] = 1; //界面各个点是否为空的更新}if (point[0] < top)top = point[0]; //最高点的更新for (i = point[0]; i < point[0] + high[id]; i++) //消除行{flag = 1;for (int j = 0; j < 13; j++) //判定某一行是否满, 用flag来标记if (map[i][j] == 0)flag = 0;if (flag == 1){for (int k = i; k >= top; k--){for (int p = 0; p < 13; p++){map[k][p] = map[k - 1][p];SetPos((p + 1) * 2, k + 1);if (map[k][p] == 1)cout << "■";else cout << " ";}}score += 10;Input_score();}}}void Tetris::Input_score(){SetColor(3);SetPos(30, 19);cout << "得分: " << score;}void Tetris::Welocme() // 欢迎界面{SetColor(3);char x;while (1){system("cls");cout << "■■■■■■■■■■■■■■■■■■■■■" << endl;cout << " 俄罗斯方块游戏 V2.6 " << endl;cout << "■■■■■■■■■■■■■■■■■■■■■" << endl;cout << " 【操作方式】:" << endl;cout << " 【↑ - 旋转】" << endl;cout << " 【↓ - 下移】" << endl;cout << " 【← - 左移】" << endl;cout << " 【→ - 右移】" << endl;cout << " 【空格- 暂停】" << endl;cout << "■■■■■■■■■■■■■■■■■■■■■" << endl;cout << "■ [按1—3选择难度] ■" << endl;SetPos(20, 10);x = getchar();if (x <= '9' && x >= '0'){rank = x - '0';break;}}}void Tetris::SetColor(int color_num) // 设置颜色{int n;switch (color_num){case 0: n = 0x04; break;case 1: n = 0x0C; break;case 2: n = 0x0D; break;case 3: n = 0x0E; break;case 4: n = 0x0A; break;}SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), n);}void Tetris::DrawMap() // 画游戏时界面{int i;SetColor(0);for (i = 0; i < 24; i++) // 宽24格{SetPos(i * 2, 0);cout << "■";SetPos(i * 2, 26);cout << "■";}for (i = 0; i < 26; i++) // 高26格{SetPos(0, i);cout << "■";SetPos(28, i);cout << "■";SetPos(46, i);cout << "■";}for (i = 14; i < 24; i++){SetPos(i * 2, 16);cout << "■";}SetColor(3);Input_score();SetPos(30, 21);cout << "难度等级:" << rank;SetPos(32, 2);cout << "下一图形:";}void Tetris::Draw(int x, int y, int num) // 画图形{int nx, ny;for (int i = 0; i < 4; i++){nx = x + sharp[num][2 * i];ny = y + sharp[num][2 * i + 1];SetPos((ny + 1) * 2, nx + 1);SetColor(i + 1);cout << "■";}}void Tetris::ReDraw(int x, int y, int num) // 为更新图形的位置清除图形{int nx, ny;for (int i = 0; i < 4; i++){nx = x + sharp[num][2 * i];ny = y + sharp[num][2 * i + 1];SetPos((ny + 1) * 2, nx + 1);cout << " ";}}bool Tetris::Judge(int x, int y, int num) // 判定在x, y 所指位置是否可画编号为{ // num 的图形, 若不可画则反回trueint nx, ny;for (int i = 0; i < 4; i++){nx = x + sharp[num][2 * i];ny = y + sharp[num][2 * i + 1];if (!(nx < 25 && nx >= 0 && ny < 13 && ny >= 0 && !map[nx][ny]))return true;}return false;}void Tetris::Run() //运行游戏{int next_id;srand((int)time(0));id = rand() % 15;next_id = rand() % 15;Draw(point[0], point[1], id);Draw(5, 16, next_id);int count;if (rank == 1)count = 150;else if (rank == 2)count = 100;elsecount = 50;count = 5;int i = 0; //不同等级对应不同countwhile (1){if (!(i < count)) //i 与 count 用于控制时间{i = 0;if (Judge(point[0] + 1, point[1], id)) //在某一位置不能下落的话{Updata();id = next_id;ReDraw(5, 16, next_id);next_id = rand() % 15;point[0] = 0; point[1] = 5;Draw(point[0], point[1], id);Draw(5, 16, next_id);if (Judge(point[0], point[1], id)){system("cls");SetPos(20, 10);cout << "【游戏结束,继续加油】" << endl;SetPos(20, 11);cout << "【你的分数】:" << score << endl;system("pause");exit(1);}}else //继续下落{ReDraw(point[0], point[1], id);point[0]++;Draw(point[0], point[1], id);}}if (_kbhit()) //键盘输入值时{int key, key2;key = _getch();if (key == 224){key2 = _getch();if (key2 == 72) //按向上方向键时{int temp = id;Turn(id);if (Judge(point[0], point[1], id))id = temp;ReDraw(point[0], point[1], temp);Draw(point[0], point[1], id);}if (key2 == 80) //按向下方向键时{if (!Judge(point[0] + 2, point[1], id)){ReDraw(point[0], point[1], id);point[0] += 2;Draw(point[0], point[1], id);}}else if (key2 == 75) //按向左方向键时{if (!Judge(point[0], point[1] - 1, id)){ReDraw(point[0], point[1], id);point[1]--;Draw(point[0], point[1], id);}}else if (key2 == 77) //按向右方向键时{if (!Judge(point[0], point[1] + 1, id)){ReDraw(point[0], point[1], id);point[1]++;Draw(point[0], point[1], id);}}}else if (key == 32) // 按下空格暂停Pause();}Sleep(50); //等待1毫秒i++; //控制下落间隔}}int main(){Tetris game;game.Welocme();system("cls"); //清除欢迎界面game.DrawMap();game.Run();}

3.火柴人跑酷

#include<bits/stdc++.h>	
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define Nor if(B[b].x<5) B[b].x=5;
#define Out1 Bx1-Bvx1<=6||Bx1-Bvx1>=28||By1-Bvy1<=7||By1-Bvy1>=27
#define Out2 Bx2-Bvx2<=6||Bx2-Bvx2>=28||By2-Bvy2<=7||By2-Bvy2>=27
#define Chang1 {Bwhat1=0;Bvx1=Bvy1=0;memset(Bgo1,0,sizeof(Bgo1));}
#define Chang2 {Bwhat2=0;Bvx2=Bvy2=0;memset(Bgo2,0,sizeof(Bgo2));}
#define Chang3 {Bwhat3=0;Bvx3=Bvy3=0;memset(Bgo3,0,sizeof(Bgo3));}
using namespace std;
int ti(float a) {return ((int)(a*10+5))/10;}
void Setpos(float x,float y){COORD pos;pos.X=ti(y*4)/2;pos.Y=ti(x);SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void Color( int a){if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE);if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE);if(a==11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE);if(a==12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);if(a==13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);if(a==14) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE);}
int Blomax,Ren,Exp,Expmax,Lv,Lvl,Ice,Drug,ar1,ar2,Tar1,Tar2,bl,br,Win,T,Tb,Sy,Up,Upt,Down,u1,u2,Kill,Killb,L,Ll[4],Li,D,Gd[10],Biao,Fire,Fir,Water,Thun,Wind,Magne,I[20][2],ib,Dis,Disb,Dis1,Disb1,Boss,Bblo,Bblomax,Bwhat1,Bwhat2,Bwhat3,Bgo1[10],Bgo2[10],Bgo3[10],Bbr,Bbl,Bl[4];
float X,Y,Vx,Vy,Ding,Blo,Hui,Bx1,By1,Bx2,By2,Bx3,By3,Bvx1,Bvy1,Bvx2,Bvy2,Bvx3,Bvy3,Bway[1001][2];
struct bullet{float x,y,vx,vy;int what;int a,t,How;int life;bool kill;}B[100001];
void Map(int a,int b);
void Pan(int a,float x,float y,int b)
{float Nox[4],Noy[4];Nox[0]=X,Noy[0]=Y;if(Down==1&&X==22) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;else if(Down==2) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;else if(Down==1||X<18) Nox[1]=X-1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;else Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;for(int i=0;i<3;i++){if(a==-1){if(abs(x-Nox[i])+abs(y-Noy[i])<1.5) {if(B[b].what==-10)Exp+=2;if(B[b].what==-11)Exp+=1;B[b].life=0;if(B[b].life==0&&b==bl) bl++;Map(3,b);break;}}if(a==-2){if(abs(x-Nox[i])+abs(y-Noy[i])<2.5) {if(B[b].what==-2)Exp+=5,Biao+=5;if(B[b].what==-3)Fire=300,Ice=0,Fir=3;if(B[b].what==-4)Water=200;if(B[b].what==-5){Wind=70;Ding=28.25;Ice=0;if(Y<Ding-1)Vy=5;else Vy=0;if(Up>=1) Vx=-5;if(Down==2) Vx=5;}if(B[b].what==-6){Thun=200;system("color 1F");Sleep(20);system("color 6F");Sleep(10);system("color 0F");}if(B[b].what==-7)Magne=300;if(B[b].what==-8)Ice=0,Drug=0,Blo=fmin((float)Blomax,Blo+20);if(B[b].what==-9)Exp=fmin((float)Expmax,Exp+20);B[b].life=0;if(B[b].life==0&&b==bl) bl++;Map(3,b);break;}}}if(Wind==0&&Thun==0&&(B[b].kill!=0||Killb>=15||Ren==1&&Killb>0)) return;for(int i=0;i<3;i++){if((Wind>=1||Thun>=1)&&abs(x-Nox[i])+abs(y-Noy[i])<2.5) {if(B[b].what<98)Exp+=2;B[b].life=0;Map(3,b);break;}if(a==1) {if(abs(x-Nox[i])<0.5&&abs(y-Noy[i])<1) {if(B[b].what>=99)Blo-=10;if(B[b].what==14)Blo-=15,Ice=100,B[b].life=0;else if(B[b].what==15)Blo-=20,Ice=0,B[b].life=0;else if(B[b].what==17)Blo-=5,Drug=100,B[b].life=0;else if(B[b].what>=13&&B[b].what<=17)Blo-=10,B[b].life=0;else Blo-=15;B[b].kill=1,Killb=20;Kill=1;Map(3,b);break;}}if (a==2||a==6||a==8||a==9||a==10||a==11||a==12) {if(abs(x-Nox[i])+abs(y-Noy[i])<1.5) {if(a==2)Blo-=20;else if(a==8)Blo-=10;else Blo-=15;B[b].kill=1,Killb=20;Kill=1;if(a!=2){B[b].life=0;if(B[b].life==0&&b==bl) bl++;Map(3,b);break;}}}if(a==4) {if((Wind>=1||Thun>=1)&&abs(x-Nox[i])<1.5&&Noy[i]-y<=0&&Noy[i]-y>=-8) {if(B[b].what<98)Exp+=2;B[b].life=0;Map(3,b);break;}if(abs(x-Nox[i])<1&&Noy[i]-y<=0&&Noy[i]-y>=-8) {Blo-=25,B[b].kill=1,Killb=20;Kill=1;Vy=-1;Y-=0.5;break;}}}
}
void Map(int a,int b){Color(0);if(a==-1){if(Boss==1||Boss==6){if(Bwhat1==5){if(ti(Bx1)==20)Setpos(Bx1,By1),cout<<"==";else Setpos(Bx1,By1),cout<<"  ";}else{Setpos(Bx1-1,By1-0.5),cout<<"    ";Setpos(Bx1,By1-1),cout<<"      ";Setpos(Bx1+1,By1-0.5),cout<<"    ";if(abs(ti(Bx1)-20)<=1)Setpos(20,By1-1),cout<<"======";}}if(Boss==2||Boss==6){Setpos(Bx2-1,By2-1);cout<<"    ";Setpos(Bx2,By2-1);cout<<"      ";Setpos(Bx2+1,By2-1),cout<<"      ";Color(0);if(abs(ti(Bx2)-20)<=1)Setpos(20,By2-1),cout<<"======";}if(Boss==3||Boss==6){Setpos(Bx3-1,By3-0.5);cout<<"     ";Setpos(Bx3,By3);cout<<"  ";Setpos(Bx3+1,By3-1),cout<<"      ";Color(0);if(abs(ti(Bx3)-20)<=1)Setpos(20,By3-1),cout<<"=======";}if(X<0)return;if(X>=17&&X<=19){Setpos(X-1,Y);cout<<"  ";Setpos(X,Y-1);cout<<"   ";Setpos(X+1,Y-1),cout<<"   ";}else if(X<=23&&X>=21){Setpos(X+1,Y);cout<<"  ";Setpos(X,Y-1);cout<<"   ";Setpos(X-1,Y-1),cout<<"    ";}else if(X>23){Setpos(X,Y-1);cout<<"    ";Setpos(X-1,Y-0.5),cout<<"   ";}else if(X<17&&Upt!=0){Setpos(X,Y-1);cout<<"    ";Setpos(X+1,Y-1.5),cout<<"    ";}else if(X<17){Setpos(X,Y-1);cout<<"    ";Setpos(X+1,Y-0.5),cout<<"   ";}if(Thun>0){Setpos(X-2,Y-1),cout<<"    ";Setpos(X+2,Y-1),cout<<"    ";Setpos(X,Y+2),cout<<"  ";Setpos(X,Y-2.5),cout<<"  ";Setpos(X-1,Y+1),cout<<"  ";Setpos(X+1,Y+1),cout<<"  ";Setpos(X-1,Y-2),cout<<"  ";Setpos(X+1,Y-2),cout<<"  ";Setpos(20,Y-2.5),cout<<"============";}if(Wind!=0){Setpos(X+1,Y-5);cout<<"        ";Setpos(X,Y-5);cout<<"        ";Setpos(X-1,Y-5);cout<<"        ";Setpos(20,Y-5),cout<<"========";}if(Water!=0){Setpos(X,Y-4);cout<<"       ";Setpos(X+2,Y-3.5);cout<<"     ";Setpos(X-2,Y-3.5);cout<<"     ";Setpos(X+1,Y-3.5);cout<<"     ";Setpos(X-1,Y-3.5);cout<<"     ";Setpos(20,Y-5),cout<<"========";}if(Fire!=0){Setpos(X,Y+1),cout<<"  ";Setpos(X+1,Y),cout<<"  ";Setpos(X-1,Y-1),cout<<"  ";Setpos(20,Y-1);cout<<"======";}}if(a==0){if(Boss==1||Boss==6){if(Bwhat1==5)Color(5),Setpos(Bx1,By1),cout<<"█",Color(0);else if(Bwhat1==4&&Bgo1[1]>6&&Bgo1[1]<11)Color(4),Setpos(Bgo1[5]-1,Bgo1[6]),cout<<"︻",Setpos(Bgo1[5],Bgo1[6]-1),cout<<"【",Setpos(Bgo1[5],Bgo1[6]+1),cout<<"】",Setpos(Bgo1[5]+1,Bgo1[6]),cout<<"︼",Color(0);else{Setpos(Bx1-1,By1-0.5),Color(0),cout<<"●●";Setpos(Bx1,By1-1);if(Bwhat1==2&&Bgo1[1]<=5)Color(1);else if(Bwhat1==3&&Bgo1[1]<=5)Color(5);else if(Bwhat1==6&&Bgo1[1]<=5)Color(8); else Color(4);if(Bwhat1==4) Setpos(Bx1,By1-0.5),cout<<"██(";else cout<<")██(";Setpos(Bx1+1,By1-0.5),cout<<"……";Color(0);}}if(Boss==2||Boss==6){Setpos(Bx2-1,By2-1);Color(0),cout<<"\\ ";Color(0);cout<<"●";Setpos(Bx2,By2-1);Color(3);cout<<"◥";Color(5),cout<<"JJJ";Color(0),cout<<">";Color(3);Setpos(Bx2+1,By2-1),cout<<"◢█◣";Color(0);}if(Boss==3||Boss==6){Setpos(Bx3-1,By3-0.5);if(Bwhat3==3||Bwhat3==9) Color(1);else if(Bwhat3==4||Bwhat3==10) Color(4);else if(Bwhat3==5||Bwhat3==11) Color(5);if(Bwhat3==11)cout<<' ';else if(Bwhat3==6) Color(3);else Color(2);cout<<"●-";Setpos(Bx3,By3);if(Bwhat3==11)cout<<"/";else cout<<"┃";Color(0);Setpos(Bx3+1,By3-1),cout<<"●●●";}if(X<0)return;if(Ren==2) Color(12);if(Ren==3) Color(1);if(Ren==4) Color(3);if(Ren==5) Color(4);if(Ren==6) Color(2);if(Drug!=0&&T%5!=0) Color(11);if(Drug!=0&&T%5==0) Color(11);if(Ice!=0) Color(6);if(b==1) Color(8);if(Li!=0) Color(5);if(Ren==1&&Killb>0&&T%4<2) Color(13);if(Wind>0&&T%4<=1) Color(1);if(Wind>0&&T%4>=2) Color(0);if(Thun>0&&T%4<=1) Color(1);if(Thun>0&&T%4>=2) Color(6);if(X>=17&&X<=19){Setpos(X-1,Y);cout<<"●";Setpos(X,Y-1);cout<<"━/";if(T%10<3) Setpos(X+1,Y-1),cout<<"┛╲";else if(T%10<6) Setpos(X+1,Y-1),cout<<"┦ ";else Setpos(X+1,Y-1),cout<<"╯>";if(Wind>0&&T%3==0) Setpos(X+1,Y-1),cout<<"┛╲";else if(Wind>0&&T%3==1) Setpos(X+1,Y-1),cout<<"┦ ";else if(Wind>0&&T%3==2)Setpos(X+1,Y-1),cout<<"╯>";}else if(X<=23&&X>=21){Setpos(X+1,Y);cout<<"●";Setpos(X,Y-1);cout<<"━\\";if(T%10<3) Setpos(X-1,Y-1),cout<<"┓╱";else if(T%10<6) Setpos(X-1,Y-1),cout<<"┪ ";else Setpos(X-1,Y-1),cout<<"╮>";if(Wind>0&&T%3==0) Setpos(X-1,Y-1),cout<<"┓╱";else if(Wind>0&&T%3==1) Setpos(X-1,Y-1),cout<<"┪ ";else if(Wind>0&&T%3==2)Setpos(X-1,Y-1),cout<<"╮>";}else if(X>23){Setpos(X,Y-1);cout<<"━ ●";Setpos(X-1,Y-0.5),cout<<"│>";}else if(X<17&&Upt!=0){Setpos(X,Y-1);cout<<"━ ●";Setpos(X+1,Y-1.5),cout<<"╱ >";}else if(X<17){Setpos(X,Y-1);cout<<"━ ●";Setpos(X+1,Y-0.5),cout<<"│>";}if(Thun>0){Setpos(X-2,Y-1),cout<<"▄▄";Setpos(X+2,Y-1),cout<<"▄▄";Setpos(X,Y+2),cout<<"▌";Setpos(X,Y-2.5),cout<<"▌";Setpos(X-1,Y+1),cout<<"█";Setpos(X+1,Y+1),cout<<"█";Setpos(X-1,Y-2),cout<<"█";Setpos(X+1,Y-2),cout<<"█";}if(Magne>0&&T%7<2)Setpos(X,Y),Color(5),cout<<"★";if(Wind>1){if(T%6<2)Color(1);else Color(0);if(T%8<=1){Setpos(X+1,Y-5);cout<<"----  --";Setpos(X,Y-5);cout<<"-  --- -";Setpos(X-1,Y-5);cout<<"--- - --";}else if(T%8<=3){Setpos(X+1,Y-5);cout<<"------  ";Setpos(X,Y-5);cout<<" --  ---";Setpos(X-1,Y-5);cout<<"----- - ";}else if(T%8<=5){Setpos(X+1,Y-5);cout<<"  ------";Setpos(X,Y-5);cout<<"-- --  -";Setpos(X-1,Y-5);cout<<"- ----- ";}else if(T%8<=7){Setpos(X+1,Y-5);cout<<"--  ----";Setpos(X,Y-5);cout<<" --- -- ";Setpos(X-1,Y-5);cout<<"- - ----";}}if(Water!=0){Color(1);if(T%20<5){Setpos(X+2,Y-3);cout<<"■";Setpos(X+1,Y-3.5);cout<<"■";Setpos(X-1,Y-2.5);cout<<"■";Setpos(X-2,Y-3);cout<<"■";}else if(T%20<10||T%20>=15){Setpos(X+2,Y-3);cout<<"■";Setpos(X,Y-4);cout<<"■■";Setpos(X-2,Y-3);  cout<<"■";}else if(T%20<15){Setpos(X+2,Y-3.5);cout<<"■";Setpos(X+1,Y-3);cout<<"■";Setpos(X-1,Y-3.5);cout<<"■";Setpos(X-2,Y-3);cout<<"■";}}if(Fire!=0){if(T%6<3)Color(4);else Color(5);if(Fir>=1)Setpos(X,Y+1),cout<<"●";if(Fir>=2)Setpos(X+1,Y),cout<<"●";if(Fir>=3)Setpos(X-1,Y-1),cout<<"●";}}if(a==1||a==3){if(B[b].what==1){Nor;Setpos(B[b].x,B[b].y-1);if(ti(B[b].x)==20)cout<<"======";else cout<<"      ";if(B[b].life!=0){B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);if(B[b].How<=1) Color(13);else Color(4);cout<<"●";if(a==1) Pan(1,B[b].x,B[b].y,b);}}if(B[b].what==2){Nor;Setpos(B[b].x-1,B[b].y-1);if(ti(B[b].x-1)==20)cout<<"======";else cout<<"      ";Setpos(B[b].x,B[b].y-1);if(ti(B[b].x)==20)cout<<"======";else cout<<"      ";Setpos(B[b].x+1,B[b].y-1);if(ti(B[b].x+1)==20)cout<<"======";else cout<<"      ";if(B[b].life!=0){B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);Color(5);if(B[b].How==0){Setpos(B[b].x-1,B[b].y),cout<<"↑";Setpos(B[b].x,B[b].y-1),cout<<"←┼ →";Setpos(B[b].x+1,B[b].y),cout<<"↓";}else if(B[b].How==1){Setpos(B[b].x-1,B[b].y-1),cout<<"↖  ↗";Setpos(B[b].x,B[b].y),cout<<"╳";Setpos(B[b].x+1,B[b].y-1),cout<<"↙  ↘";} if(a==1) Pan(2,B[b].x,B[b].y,b);}}if(B[b].what==3||B[b].what==5){Nor;Setpos(B[b].x,B[b].y);if(ti(B[b].x)==20)cout<<"==";else cout<<"  ";if(B[b].life!=0){B[b].y-=B[b].vy;B[b].x-=B[b].vx;Setpos(B[b].x,B[b].y);if(B[b].How==1) Color(5);else Color(4);cout<<"◎";}}if(B[b].what==4){Nor;Setpos(B[b].x,fmax((float)0,B[b].y-8));if(ti(B[b].x)==20){for(int i=max(0,(int)B[b].y-8);i<=B[b].y;i++)cout<<"==";}else {for(int i=max(0,(int)B[b].y-8);i<=B[b].y;i++)cout<<"  ";}if(B[b].life!=0){B[b].y-=B[b].vy;Setpos(B[b].x,fmax((float)0,B[b].y-8));Color(6); for(int i=max(0,(int)B[b].y-8);i<=B[b].y;i++)cout<<"═"; if(a==1) Pan(4,B[b].x,B[b].y,b);}}if(B[b].what==6||B[b].what==8||B[b].what==9){Nor;Setpos(B[b].x-1,B[b].y);if(ti(B[b].x)-1==20)cout<<"==";else cout<<"  ";Setpos(B[b].x+1,B[b].y);if(ti(B[b].x)+1==20)cout<<"==";else cout<<"  ";Setpos(B[b].x,B[b].y-1);if(ti(B[b].x)==20)cout<<"======";else cout<<"      ";if(B[b].life!=0){B[b].y-=B[b].vy;B[b].x-=B[b].vx;Setpos(B[b].x,B[b].y-1);if(B[b].what==6){if(B[b].How<=1) Color(1); else Color(6);}if(B[b].what==9){if(B[b].How<=1) Color(4); else Color(8);}if(B[b].what==8)Color(5);Setpos(B[b].x-1,B[b].y);cout<<"︹";Setpos(B[b].x+1,B[b].y);cout<<"︺";Setpos(B[b].x,B[b].y-1);if(B[b].How%2==1) cout<<"〔●〕"; else cout<<"﹝○﹞"; if(a==1) Pan(6,B[b].x,B[b].y,b);}}if(B[b].what==7){Nor;Setpos(B[b].x,B[b].y);if(B[b].How<0) for(int i=19;i>=20+B[b].How;i--) {Setpos(i,B[b].y);cout<<"  ";}if(B[b].How>0) for(int i=21;i<=20+B[b].How;i++) {Setpos(i,B[b].y);cout<<"  ";}if(B[b].life!=0){B[b].y-=B[b].vy;if(B[b].How<0) for(int i=19;i>=20+B[b].How;i--) {Setpos(i,B[b].y);cout<<"║"; if(a==1) Pan(7,i,B[b].y,b);}if(B[b].How>0) for(int i=21;i<=20+B[b].How;i++) {Setpos(i,B[b].y);cout<<"║"; if(a==1) Pan(7,i,B[b].y,b);}}}if(B[b].what==10||B[b].what==11||B[b].what==12){Nor;Setpos(B[b].x,B[b].y);if(ti(B[b].x)==20)cout<<"==";else cout<<"  ";if(B[b].life!=0){B[b].x-=B[b].vx;B[b].y-=B[b].vy;if(B[b].How==1){B[b].vy-=0.2;}else B[b].vx-=0.35;if(B[b].x>=25) B[b].x=25,B[b].vx*=-0.8;if(B[b].what==11&&B[b].y<=1) B[b].y=1,B[b].vy*=-1;if(B[b].what==12&&B[b].y<=1) B[b].y=1,B[b].vx=0,B[b].vy=-0.5,B[b].How=1;Setpos(B[b].x,B[b].y);if(B[b].what==11)Color(1);else if(B[b].what==12)Color(5);else Color(0);if(B[b].t%4<2)cout<<"▃";else cout<<"▍";if(a==1) Pan(B[b].what,B[b].x,B[b].y,b);}}if(B[b].what>=13&&B[b].what<=17){Nor;Setpos(B[b].x,B[b].y);if(ti(B[b].x)==20)cout<<"====";else cout<<"    ";if(B[b].life!=0){B[b].x-=B[b].vx;B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);if(B[b].what==14) Color(1);else if(B[b].what==15) Color(4);else if(B[b].what==16) Color(5);else if(B[b].what==17) Color(3);else Color(2);cout<<"●";if(B[b].what==14)cout<<"*";if(B[b].what==15)cout<<"";if(B[b].what==16)cout<<"<";if(B[b].what==17)cout<<"X";} if(a==1) Pan(1,B[b].x,B[b].y,b);}if(B[b].what==98&&B[b].life!=0){B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);if(ti(B[b].x==20))cout<<"==";else cout<<"  ";if(B[b].y<=3)B[b].life=0;} if(B[b].what>=99){if(B[b].y<=3)B[b].life=0;if(B[b].life!=0){B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);Color(5);if(B[b].what==99)cout<<"█";if(B[b].what>=100&&B[b].what<200){if(B[b].what%5==0)cout<<"我";if(B[b].what%5==1)cout<<"是";if(B[b].what%5==2)cout<<"最";if(B[b].what%5==3)cout<<"强";if(B[b].what%5==4)cout<<"的";}if(B[b].what>=200&&B[b].what<300){if(B[b].what%6==0)cout<<"神";if(B[b].what%6==1)cout<<"级";if(B[b].what%6==2)cout<<"怪";if(B[b].what%6==3)cout<<"物";if(B[b].what%6==4)cout<<"之";if(B[b].what%6==5)cout<<"光";}if(B[b].what>=300&&B[b].what<400){if(B[b].what%8==0)cout<<"颤";if(B[b].what%8==1)cout<<"抖";if(B[b].what%8==2)cout<<"吧";if(B[b].what%8==3)cout<<"无";if(B[b].what%8==4)cout<<"能";if(B[b].what%8==5)cout<<"的";if(B[b].what%8==6)cout<<"人";if(B[b].what%8==7)cout<<"类";}if(B[b].what>=400&&B[b].what<500){if(B[b].what%8==0)cout<<"还";if(B[b].what%8==1)cout<<"不";if(B[b].what%8==2)cout<<"快";if(B[b].what%8==3)cout<<"跪";if(B[b].what%8==4)cout<<"倒";if(B[b].what%8==5)cout<<"在";if(B[b].what%8==6)cout<<"朕";if(B[b].what%8==7)cout<<"前";}if(B[b].what>=500&&B[b].what<600){if(B[b].what%8==0)cout<<"看";if(B[b].what%8==1)cout<<"懂";if(B[b].what%8==2)cout<<"这";if(B[b].what%8==3)cout<<"句";if(B[b].what%8==4)cout<<"话";if(B[b].what%8==5)cout<<"的";if(B[b].what%8==6)cout<<"是";if(B[b].what%8==7)cout<<"猪";} if(a==1) Pan(1,B[b].x,B[b].y,b);}}if(B[b].what==-1){Nor;Setpos(B[b].x,B[b].y);if(ti(B[b].x)==20)cout<<"==";else cout<<"  ";if(Boss==0) B[b].life=0;else if(((Boss==1&&abs(B[b].x-Bx1)+abs(B[b].y-By1)<1.5)||(Boss==2&&abs(B[b].x-Bx2)+abs(B[b].y-By2)<1.5)||(Boss==3&&abs(B[b].x-Bx3)+abs(B[b].y-By3)<1.5)||(B[b].t==10))&&B[b].life==1) Bblo-=8+Lv*2,B[b].life=0;if(B[b].life!=0){if(Boss==1)B[b].x=B[b].x+(Bx1-B[b].x)/(10-B[b].t)*1.0,B[b].y=B[b].y+(By1-B[b].y)/(10-B[b].t)*1.0;if(Boss==2)B[b].x=B[b].x+(Bx2-B[b].x)/(10-B[b].t)*1.0,B[b].y=B[b].y+(By2-B[b].y)/(10-B[b].t)*1.0;if(Boss==3)B[b].x=B[b].x+(Bx3-B[b].x)/(10-B[b].t)*1.0,B[b].y=B[b].y+(By3-B[b].y)/(10-B[b].t)*1.0;Setpos(B[b].x,B[b].y);Color(7);if(B[b].t%2==0) cout<<"+";else cout<<"×";}}if(B[b].what<=-2&&B[b].what>=-9){Nor;Setpos(B[b].x-1,B[b].y);if(ti(B[b].x)-1==20)cout<<"==";else cout<<"  ";Setpos(B[b].x+1,B[b].y);if(ti(B[b].x)+1==20)cout<<"==";else cout<<"  ";Setpos(B[b].x,B[b].y-1);if(ti(B[b].x)==20)cout<<"======";else cout<<"      ";if(B[b].life!=0){B[b].y-=B[b].vy;B[b].x-=B[b].vx;if(B[b].what<=-3&&B[b].what>=-7){if(B[b].x<=7)B[b].x=7;if(B[b].x>=28)B[b].x=28;else if(B[b].x>=B[b].a+1&&B[b].How==1)B[b].How=0;else if(B[b].x<=B[b].a-1&&B[b].How==0)B[b].How=1;if(B[b].How==1&&B[b].vx>=-1)B[b].vx-=0.2;if(B[b].How==0&&B[b].vx<=1)B[b].vx+=0.2;}if(B[b].what==-2) Color(3);if(B[b].what==-3) Color(4);if(B[b].what==-4) Color(1);if(B[b].what==-5) Color(0);if(B[b].what==-6) Color(6);if(B[b].what==-7) Color(5);if(B[b].what==-8) Color(2);if(B[b].what==-9) Color(14);if(T%7<=1&&B[b].what==-5)Color(1);else if(T%7<=1)Color(0);Setpos(B[b].x-1,B[b].y);cout<<"︹";Setpos(B[b].x+1,B[b].y);cout<<"︺";Setpos(B[b].x,B[b].y-1);if(B[b].what==-2) cout<<"﹝镖﹞";if(B[b].what==-3) cout<<"﹝火﹞";if(B[b].what==-4) cout<<"﹝水﹞";if(B[b].what==-5) cout<<"﹝风﹞";if(B[b].what==-6) cout<<"﹝雷﹞";if(B[b].what==-7) cout<<"﹝磁﹞";if(B[b].what==-8) cout<<"﹝血﹞";if(B[b].what==-9) cout<<"﹝忍﹞"; if(a==1) Pan(-2,B[b].x,B[b].y,b);}}if(B[b].what==-11||B[b].what==-12){Nor;Setpos(B[b].x,B[b].y);if(ti(B[b].x)==20)cout<<"==";else cout<<"  ";if(B[b].life!=0){if(Magne>0)B[b].How++,B[b].x=B[b].x+(X-B[b].x)/(10-B[b].How)*1.0,B[b].y=B[b].y+(Y-B[b].y)/(10-B[b].How)*1.0;B[b].y-=B[b].vy;Setpos(B[b].x,B[b].y);if(B[b].what==-10) Color(5);if(B[b].what==-11) Color(7);if(T%7<=1)Color(0);cout<<"◆"; if(a==1) Pan(-1,B[b].x,B[b].y,b);}}if(B[b].what==-13){Nor;Setpos(B[b].x,B[b].y-0.5);if(ti(B[b].x)==20)cout<<"===";else cout<<"   ";if(B[b].life!=0){if(B[b].a==13880086){if(Boss==0) B[b].life=0;else if(((Boss==1&&abs(B[b].x-Bx1)+abs(B[b].y-By1)<1.5)||(Boss==2&&abs(B[b].x-Bx2)+abs(B[b].y-By2)<1.5)||(Boss==3&&abs(B[b].x-Bx3)+abs(B[b].y-By3)<1.5)||(B[b].t==5))&&B[b].life==1) Bblo-=8+Lv*2,B[b].life=0;if(B[b].life!=0){if(Boss==1)B[b].x=B[b].x+(Bx1-B[b].x)/(5-B[b].t)*1.0,B[b].y=B[b].y+(By1-B[b].y)/(5-B[b].t)*1.0;if(Boss==2)B[b].x=B[b].x+(Bx2-B[b].x)/(5-B[b].t)*1.0,B[b].y=B[b].y+(By2-B[b].y)/(5-B[b].t)*1.0;if(Boss==3)B[b].x=B[b].x+(Bx3-B[b].x)/(5-B[b].t)*1.0,B[b].y=B[b].y+(By3-B[b].y)/(5-B[b].t)*1.0;}}else{if(B[B[b].a].life==0) B[b].life=0;else if((abs(B[b].x-B[B[b].a].x)+abs(B[b].y-B[B[b].a].y)<1.5||(B[b].t==5))&&B[b].life==1) Exp+=2,B[B[b].a].life=B[b].life=0;if(B[b].life!=0){B[b].x=B[b].x+(B[B[b].a].x-B[b].x)/(5-B[b].t)*1.0,B[b].y=B[b].y+(B[B[b].a].y-B[b].y)/(5-B[b].t)*1.0;}}Setpos(B[b].x,B[b].y-0.5);if(T%6<3)Color(5);else Color(4);cout<<"●";}}}if(br<bl) {br=-1,bl=0;memset(B,0,sizeof(B));}Color(0);
}
void Move(){if(X<3) X=3;if(Y<1) Y=1,Vy=0;if(Y>29) Y=29,Vy=0;if(Ice!=0){X-=Vx/2.0;Y+=Vy/2.0;Vy=fmax(Vy-0.025,(float)0);if(T%6==0&&Up==0&&Y<Ding) Y+=0.25;if(T%6==3&&Up==0&&Y>=Ding) Y-=0.25;if(Up==0&&Y<=Ding-1.25) Vy=0.25;if(Up==0&&Y>=Ding+1.25&&Wind==0) Vy=-0.25;if(Up==0&&Down==0&&Vx>0&&X<=18) Up=0,Down=0,Vx=0,Vy=0,X=18,Setpos(20,Y-2.5),cout<<"==========";else if(Down==2&&X<=22) Up=0,Down=1,Vx=0,Vy=0,X=22,Setpos(20,Y-2.5),cout<<"==========";else if(Up==0&&Down==1&&Vx<0&&X>=22) Up=0,Down=1,Vx=0,Vy=0,X=22,Setpos(20,Y-2.5),cout<<"==========";else if(Up>0&&Down==0&&X>18) Up=0,Vx=0,Vy=0,X=18,Setpos(20,Y-2.5),cout<<"==========";else if(Down==2) Vx+=0.175;else if(Up>0&&Upt==0) Vx-=0.175;else if(Up>0&&Upt>0) {Vx=fmax(Vx-0.125,(float)0);if(Upt==1&&T%2==0)Map(-1,0);if(T%2==0)Upt--;}}else{X-=Vx;Y+=Vy;Vy=fmax(Vy-0.05,(float)0);if(Wind==0){if(T%6==0&&Up==0&&Y<Ding) Y+=0.5;if(T%6==3&&Up==0&&Y>=Ding) Y-=0.5;}else{if(T%2==0&&Up==0&&Y<Ding) Y+=0.5;if(T%2==1&&Up==0&&Y>=Ding) Y-=0.5;}if(Up==0&&Y<=Ding-1.25) Vy=0.5;if(Up==0&&Y>=Ding+1.25&&Wind==0) Vy=-0.5;if(Up==0&&Down==0&&Vx>0&&X<=18) Up=0,Down=0,Vx=0,Vy=0,X=18,Setpos(20,Y-2.5),cout<<"==========";else if(Down==2&&X<=22) Up=0,Down=1,Vx=0,Vy=0,X=22,Setpos(20,Y-2.5),cout<<"==========";else if(Up==0&&Down==1&&Vx<0&&X>=22) Up=0,Down=1,Vx=0,Vy=0,X=22,Setpos(20,Y-2.5),cout<<"==========";else if(Up>0&&Down==0&&X>18) Up=0,Vx=0,Vy=0,X=18,Setpos(20,Y-2.5),cout<<"==========";else if(Down==2) Vx+=0.35;else if(Up>0&&Upt==0) Vx-=0.35;else if(Up>0&&Upt>0) {Vx=fmax(Vx-0.25,(float)0);if(Upt==1)Map(-1,0); Upt--;}}for(int i=bl;i<=br;i++){if(B[i].what<98)if(B[i].x-B[i].vx<=5||B[i].x-B[i].vx>=30||B[i].y-B[i].vy<=0||B[i].y-B[i].vy>=30){B[i].life=0;Map(1,i);}for(int j=0;j<20;j++)if(B[i].what>0&&B[i].life!=0&&abs(B[i].x-I[j][0])<2&&B[i].y-I[j][1]<=2){Setpos(I[j][0],I[j][1]);if(I[j][0]==20) cout<<"===";else cout<<"   ";I[j][0]=I[j][1]=-1;B[i].life=0;Exp+=2;}if(B[i].t>=100)B[i].life=0;if(B[i].life==0&&i==bl) bl++;Map(1,i);if(B[i].life==0) continue;else{B[i].t++;if(B[i].what==1){if(B[i].y<=25&&B[i].How==0) B[i].vy=0,B[i].How=1;if(B[i].t==30) B[i].y+=1.5,B[i].How=2;if(B[i].t==35) B[i].vy=1.5,B[i].How=3;}if(B[i].what==2){if(B[i].t%3==0) B[i].How=!B[i].How;} if(B[i].what==3||B[i].what==5){if(B[i].what==3&&B[i].y<=20) B[i].vy=0;if(B[i].what==5&&B[i].y<=21) B[i].vy=0;if(B[i].t>30&&B[i].t%2==0) B[i].How=!B[i].How;if(B[i].what==5&&B[i].t<=30&&B[i].x<X) B[i].vx=-0.2;else if(B[i].what==5&&B[i].t<=70&&B[i].x>X) B[i].vx=0.2;else B[i].vx=0;if(B[i].t==45){B[i].life=0;br++;B[br].what=4;B[br].x=B[i].x;B[br].y=32;B[br].vy=3;B[br].life=1;}}if(B[i].what==6||B[i].what==8||B[i].what==9){if(B[i].vx<0.25&&B[i].vy<0.25&&B[i].t>=50){B[i].life=0;if(B[i].life==0&&i==bl) bl++;Map(1,i);break;}if(B[i].t%5==0) B[i].How=rand()%4;if(B[i].what==9){if(B[i].t==7){X9:float xx=(rand()%41)/40.0,yy=(rand()%41)/40.0;if(xx<=0.5&&yy<=0.5) goto X9;for(int j=1;j<=4;j++){br++,B[br].what=9;B[br].t=11;B[br].x=B[i].x,B[br].y=B[i].y,B[br].vx=xx,B[br].vy=yy;if(j%2==0)swap(B[br].vx,B[br].vy),B[br].vy*=-1;if(j<=2)B[br].vx*=-1,B[br].vy*=-1;B[br].life=1;}B[i].life=0;}}if(B[i].what==8){if(B[i].x>X&&B[i].vx<1.2) B[i].vx+=fmax((float)0,0.2-B[i].t/25);if(B[i].x<X&&B[i].vx>-1.2) B[i].vx-=fmax((float)0,0.2-B[i].t/25);if(B[i].y>Y&&B[i].vy<1.2) B[i].vy+=fmax((float)0,0.2-B[i].t/25);if(B[i].y<Y&&B[i].vy>-1.2) B[i].vy-=fmax((float)0,0.2-B[i].t/25);}}if(B[i].what>=13&&B[i].what<=15&&B[i].How!=0){if(B[i].x==B[i].How)B[i].vx=0,B[i].How=0;}if(B[i].what==16){if(B[i].x<X&&B[i].vx>=-1) B[i].vx-=0.2;else if(B[i].x>X&&B[i].vx<=1) B[i].vx+=0.2;}}if(B[i].life==1&&B[i].a==0&&B[i].what>0){if(B[i].y>Y&&abs(B[i].x-X)<=3&&((B[i].x-X)*(B[i].x-X)+(B[i].y-Y)*(B[i].y-Y))<Dis) Dis=(B[i].x-X)*(B[i].x-X)+(B[i].y-Y)*(B[i].y-Y),Disb=i;else if(((B[i].x-X)*(B[i].x-X)+(B[i].y-Y)*(B[i].y-Y))<Dis1) Dis1=(B[i].x-X)*(B[i].x-X)+(B[i].y-Y)*(B[i].y-Y),Disb1=i;}}
}
void Guai(int R,int r){if(R==-1){br++;B[br].what=-1;B[br].x=X+rand()%3-1;B[br].y=Y+rand()%3-1;B[br].life=1;}if(R<=-2&&R>=-11){br++;B[br].what=R;B[br].x=B[br].a=r;B[br].y=29;if(R<=-3&&R>=-7)B[br].vx=-1;B[br].vy=1;B[br].life=1;}if(R==0){br++;B[br].what=1;B[br].x=r;B[br].y=29;B[br].vy=1;B[br].life=1;}if(R==1){br++;B[br].what=2;B[br].x=r;B[br].y=29;B[br].vy=1;B[br].life=1;}if(R==2||R==3){br++;B[br].what=2*R-1;B[br].x=r;B[br].y=29;B[br].vy=1;B[br].life=1;}if(R==4){br++;B[br].what=6;if(r<5)r=5;if(r>30)r=30;B[br].x=r;if(r==11||r==25) B[br].y=29-(rand()%20);else B[br].y=29;X4:B[br].vx=(rand()%21-10)/30.0;B[br].vy=(rand()%25)/30.0;if(B[br].vx<=0.8&&B[br].vy<=0.8)goto X4;int rx=rand()%50;if(rx==0) B[br].vx=0;B[br].life=1;}if(R==5){br++;B[br].How=r;B[br].what=7;if(B[br].How<0) B[br].x=19;if(B[br].How>0) B[br].x=21;B[br].y=29;B[br].vy=1;B[br].life=1;}
}
void CpGuai(int R,float x,float y,float xx,float yy){if(R==4){br++;B[br].what=6;B[br].x=x;B[br].y=y;B[br].vx=xx;B[br].vy=yy;B[br].life=1;}if(R==6||R==7||R==8){br++;B[br].what=4+R;B[br].x=x;B[br].y=y;B[br].vx=xx;B[br].vy=yy;B[br].life=1;}
}
void MesGuai(int a,int rr){int R=rand()%rr,r=-10086;if(R==0){if(a==1) r=(5+rand()%8)*2;if(a<=3&&a!=1) r=10+rand()%16;if(a==4) r=rand()%75-20;if(a==5) r=2+rand()%4;if(r!=-10086) Guai(a,r);}
}
void NorGuai(int a,int b){	if(a==1) {if(b==1||b==41) Guai(0,15),Guai(0,17),Guai(0,19);if(b==21||b==61) Guai(0,21),Guai(0,23),Guai(0,25);if(b==81) Guai(0,11),Guai(0,13),Guai(0,15),Guai(0,17),Guai(0,19);if(b==101||b==141) Guai(0,17),Guai(0,19),Guai(0,21),Guai(0,23),Guai(0,25);if(b==121) Guai(0,15),Guai(0,17),Guai(0,19),Guai(0,21),Guai(0,23);if(b>=160&&b<=260&&b%10==0) Guai(0,b/10-1);if(b>=270&&b<=370&&b%10==0) Guai(0,52-b/10);if(b>=460&&b<=560&&b%10==0) Guai(0,b/10-37),Guai(0,b/10-36),Guai(0,b/10-35);if(b>=570&&b<=670&&b%10==0) Guai(0,78-b/10),Guai(0,77-b/10),Guai(0,76-b/10);if(b>=760&&b<=960&&b%10==0) Guai(0,b/10-66),Guai(0,b/10-65),Guai(0,103-b/10),Guai(0,104-b/10);if(b>=1000&&b<=1300) MesGuai(0,30-b/50);}if(a==2) {if(b<=200&&b%30==1) {int r=rand()%4;if(r==1) r=0;for(int i=0;i<4;i++) if(i!=r) Guai(1,i*4+9);}if(b>200&&b<=220&&b%5==1) Guai(1,18);if(b>220&&b<=300&&b%7==1) Guai(1,b/5-26);if(b>350&&b<=370&&b%5==1) Guai(1,22);if(b>370&&b<=450&&b%7==1) Guai(1,96-b/5);if(b==461||b==501||b==541) Guai(1,13),Guai(1,17),Guai(1,21);if(b==481||b==521||b==561) Guai(1,17),Guai(1,21),Guai(1,25);if(b>=561&&b<=861&&b%20==1) Guai(1,b/40+5);if(b>=561&&b<=861&&b%20==11) Guai(1,35-b/40);if(b>=801&&b<=961&&b%15==1) Guai(1,20);if(b>=1000&&b<=1300) MesGuai(1,30-b/50);}if(a==3) {if(b==1||b==61) Guai(3,15),Guai(2,17),Guai(2,19);if(b==31||b==91) Guai(2,21),Guai(2,23),Guai(3,25);if(b>=120&&b<=220&&b%10==0) Guai(2,b/10+3);if(b>=240&&b<=340&&b%10==0) Guai(2,49-b/10);if(b>=360&&b<=460&&b%20==0) Guai(2,b/10-21),Guai(2,61-b/10);if(b>=480&&b<=580&&b%20==0) Guai(3,b/10-33),Guai(3,73-b/10);if(b>=600&&b<750&&b%30==0) {for(int i=0;i<5;i++) Guai(3,i*3+10);}if(b>=750&&b<830&&b%10==0) if(b<=200&&b%40==1) Guai(2,X);if(b>=830&&b<910&&b%20==0) Guai(2,X);if(b>=910&&b<980&&b%10==0) Guai(2,X);if(b>=1000&&b<=1300) MesGuai(rand()%2+2,40-b/50);}if(a==4) {if(b==1) CpGuai(4,10,29,-0.4,0.7),CpGuai(4,14,29,-0.2,0.7),CpGuai(4,21,29,0,0.65);if(b==41) CpGuai(4,10,29,-0.2,0.7),CpGuai(4,14,29,-0.1,0.7),CpGuai(4,18,29,0,0.65);if(b==81) CpGuai(4,5,20,-0.4,0.35),CpGuai(4,10,29,-0.4,0.7),CpGuai(4,14,29,-0.2,0.7),CpGuai(4,30,20,0.25,0.4),CpGuai(4,21,29,0,0.65);if(b==121) CpGuai(4,5,20,-0.2,0.35),CpGuai(4,10,29,-0.2,0.7),CpGuai(4,14,29,-0.1,0.7),CpGuai(4,30,20,0.4,0.4),CpGuai(4,18,29,0,0.65);if(b==161) CpGuai(4,10,29,-0.4,0.7),CpGuai(4,14,29,-0.2,0.7),CpGuai(4,21,29,0,0.6),CpGuai(4,10,29,-0.2,0.7),CpGuai(4,14,29,-0.1,0.7),CpGuai(4,18,29,0,0.65);if(b>=200&&b<=500&&b%40==1) {float r=0,rr;for(int i=1;i<=5;i++){X5:rr=0.7+(rand()%5)/10.0;if(rr==r)goto X5;r=rr;CpGuai(4,i*3+7,29,0,0.5+(rand()%50)/80.0);}}if(b>540&&b<=565&&b%5==1) CpGuai(4,5,8,-2,0.2);if(b>590&&b<=615&&b%5==1) CpGuai(4,30,8,1.5,0.2);if(b>640&&b<=665&&b%5==1) CpGuai(4,5,8,-1.5,0.3);if(b>690&&b<=715&&b%5==1) CpGuai(4,30,8,2,0.3);if(b>=750&&b<=950&&b%20==1) {float r=0,rr;for(int i=1;i<=3;i++){X6:rr=0.7+(rand()%5)/10.0;if(rr==r)goto X6;r=rr;CpGuai(4,i*5+7+(rand()%3),29,0,0.5+(rand()%50)/200.0);}}if(b>=1000&&b<=1300) MesGuai(4,5);}
}
void RandGood(){if(Biao>0){Biao--;Guai(-1,0);}if(Gd[1]==0){Gd[1]=rand()%1000+1;if(Win==7)Gd[1]=10086;Gd[3]=rand()%16+8;}else if(Gd[1]<=5){Guai(-2-Gd[1],Gd[3]);memset(Gd,0,sizeof(Gd));}else if(Gd[1]>=20&&Gd[1]<27){Guai(-8,Gd[3]);memset(Gd,0,sizeof(Gd));}else if(Gd[1]>=30&&Gd[1]<37){Guai(-9,Gd[3]);memset(Gd,0,sizeof(Gd));}else if(Gd[1]>=40&&Gd[1]<70){Gd[2]++;if(Gd[2]%2==1)Guai(-10,Gd[3]);if(Gd[2]>=9)memset(Gd,0,sizeof(Gd));}else if(Gd[1]>=70&&Gd[1]<100){Gd[2]++;if(Gd[2]%2==1)Guai(-11,Gd[3]);if(Gd[2]>=9)memset(Gd,0,sizeof(Gd));}else if(Boss!=0&&Gd[1]>=450&&Gd[1]<=500){Guai(-2,Gd[3]);memset(Gd,0,sizeof(Gd));}else Gd[1]=0;for(int i=0;i<20;i++){if(I[i][0]==-1) continue;Setpos(I[i][0],I[i][1]);Color(0);if(I[i][0]==20) cout<<"===";else cout<<"   ";I[i][1]++;if(I[i][0]>=28||I[i][0]<=0||I[i][1]>=29) I[i][0]=I[i][1]=-1;else Color(1),Setpos(I[i][0],I[i][1]),cout<<"■";Color(0);}
}
void Panboss(int bx,int by){float Nox[4],Noy[4];Nox[0]=X,Noy[0]=Y;if(Down==1&&X==22) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;else if(Down==2) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;else if(Down==1||X<18) Nox[1]=X-1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;else Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;for(int i=0;i<3;i++){if((Boss==1||Boss==6)&&Wind==0&&Thun==0&&abs(Nox[i]-bx)<1&&abs(Noy[i]-by)<1&&Bgo1[4]==0) Blo-=20,Bgo1[4]=1,Killb=20,Kill=1;if((Boss==2||Boss==6)&&Wind==0&&Thun==0&&abs(Nox[i]-bx)<1&&abs(Noy[i]-by)<1&&Bgo2[8]==0) Blo-=20,Bgo2[8]=1,Killb=20,Kill=1;}
}
void Boss1(){for(int j=0;j<20;j++)if(abs(Bx1-I[j][0])<2&&By1-I[j][1]<=2){Setpos(I[j][0],I[j][1]);if(I[j][0]==20) cout<<"===";else cout<<"   ";I[j][0]=I[j][1]=-1;Bblo-=8+Lv*2;Exp+=2;}if(Bbr==Bbl&&Bbr!=0) Bbr=Bbl=0;for(int i=1;i<=3+(Bbl-Bbr)/5;i++)if(Bbr<Bbl){Setpos(Bway[Bbr][0],Bway[Bbr][1]);if(Bway[Bbr][0]==20) cout<<"==";else cout<<"  ";Bbr++;}if(Bwhat1==5){int bx,by;Color(5);for(int i=0;i<10;i++){bx=Bx1-i*Bvx1/10.0;by=By1-i*Bvy1/10.0;Setpos(bx,by),cout<<"█";Bbl++;Bway[Bbl][0]=bx;Bway[Bbl][1]=by;}Color(0);}Bx1-=Bvx1;By1-=Bvy1;if(Bwhat1==0){X2:Bwhat1=rand()%7;if(Bwhat1==2||Bwhat1==3){if(By1<=10||By1>25) goto X2;}if(Bwhat1==4){if(By1<=15||Bx1<20) goto X2;Bgo1[2]=Bx1;Bgo1[3]=By1-1;}if(Bwhat1==5) {X0:Bgo1[3]=rand()%4+1;Bvx1=(rand()%101)/20.0;Bvy1=(rand()%101)/20.0;if(Bgo1[3]<=2) Bvx1*=-1;if(Bgo1[3]%2==1) Bvy1*=-1;if(abs(Bvx1)+abs(Bvy1)<=3||Out1)goto X0;}if(Bwhat1==6){if(By1<=17||By1>25) goto X2;}}if(Bwhat1==1){Bgo1[1]++,Bgo1[2]++;int R=rand()%(5-Bgo1[1]),r=rand()%(10-Bgo1[2]);if(Out1) R=0;if(R==0) {int vx=Bvx1,vy=Bvy1;Bgo1[1]=0;Bvx1=(rand()%101-20)/50.0;Bvy1=(rand()%101-20)/50.0;if(Bgo1[3]<=2) Bvx1*=-1;if(Bgo1[3]%2==1) Bvy1*=-1;if(Out1) r=0;} if(r==0) Chang1 }if(Bwhat1==2){Bgo1[1]++;if(Bgo1[1]>6){Bvy1=-0.3;br++;B[br].x=Bx1,B[br].y=By1-1;B[br].what=6;X3:B[br].vx=(rand()%21-10)/40.0;B[br].vy=(rand()%25)/30.0;if(B[br].vx<=0.8&&B[br].vy<=0.8)goto X3;int rx=rand()%50;if(rx==0) B[br].vx=0;B[br].life=1;}if(Bgo1[1]>8) Chang1}if(Bwhat1==3){Bgo1[1]++;if(Bgo1[1]>6&&Bgo1[1]%3==0){Bvy1=-0.3;br++;B[br].x=Bx1,B[br].y=By1-1;B[br].what=8;B[br].life=1;}if(Bgo1[1]>15) Chang1}if(Bwhat1==4){Bgo1[1]++;if(Bgo1[1]<=8){Setpos(Bgo1[2],Bgo1[3]);if(Bgo1[1]==1)cout<<" ";else if(Bgo1[1]>1&&Bgo1[2]==20) cout<<"==";else cout<<"  ";Bgo1[2]--;Setpos(Bgo1[2],Bgo1[3]);int r=rand()%4;if(r%2==0) Color(6);else Color(9);if(r<2) cout<<") ";else cout<<"】";Color(0);}if(Bgo1[1]==6) Bgo1[5]=X,Bgo1[6]=Y;if(Bgo1[1]==11){Map(0,(bool)Kill);Setpos(Bgo1[5],Bgo1[6]+1),cout<<"  ";Setpos(Bgo1[5],Bgo1[6]-1),cout<<"  ";Setpos(Bgo1[5]+1,Bgo1[6]),cout<<"  ";Setpos(Bgo1[5]-1,Bgo1[6]),cout<<"  ";int bx,by,bvx=Bgo1[2]-Bgo1[5],bvy=Bgo1[3]-Bgo1[6];Color(6);int i=0;while(1){bx=Bgo1[2]-i*bvx/30.0;by=Bgo1[3]-i*bvy/30.0;if(bx<=5||bx>=30||by<0||by>=29) break;Panboss(bx,by);Setpos(bx,by),cout<<"█";Bbl++;Bway[Bbl][0]=bx;Bway[Bbl][1]=by;i++;}Color(0);Map(-1,0);Chang1}}if(Bwhat1==5){Bgo1[1]++,Bgo1[2]++;int R=rand()%(5-Bgo1[1]),r=rand()%(10-Bgo1[2]);if(Out1) R=0;if(R==0) {int vx=Bvx1,vy=Bvy1;Bgo1[1]=0;X1:Bvx1=(rand()%101-20)/20.0;Bvy1=(rand()%101-20)/20.0;if(Bgo1[3]<=2) Bvx1*=-1;if(Bgo1[3]%2==1) Bvy1*=-1;if(abs(Bvx1)+abs(Bvy1)<=3||abs(Bvx1-vx)<=1||abs(Bvy1-vy)<=1)goto X1;if(Out1) r=0;} if(r==0) Chang1 }if(Bwhat1==6){Bgo1[1]++;if(Bgo1[1]>6&&Bgo1[1]%10==0){By1-=1;br++;B[br].x=Bx1,B[br].y=By1-1;B[br].what=9;X30:B[br].vy=1;B[br].life=1;}if(Bgo1[1]>31) Chang1}
}
void Boss2(){for(int j=0;j<20;j++)if(abs(Bx2-I[j][0])<2&&By2-I[j][1]<=2){Setpos(I[j][0],I[j][1]);if(I[j][0]==20) cout<<"===";else cout<<"   ";I[j][0]=I[j][1]=-1;Bblo-=8+Lv*2;Exp+=2;}if(Bbr==Bbl&&Bbr!=0) Bbr=Bbl=0;for(int i=1;i<=3+(Bbl-Bbr)/5;i++)if(Bbr<Bbl){Setpos(Bway[Bbr][0],Bway[Bbr][1]);if(Bway[Bbr][0]==20) cout<<"==";else cout<<"  ";Bbr++;}Bx2-=Bvx2;By2-=Bvy2;if(Bwhat2==0){X21:Bwhat2=rand()%7;if(Bwhat2==2){X31:for(int i=1;i<=3;i++){Bgo2[i*2+1]=rand()%28+1,Bgo2[i*2]=rand()%25+5;if((abs(Bgo2[i*2]-Bx2)<=2&&abs(Bgo2[i*2+1]-By2)<=2)||(abs(Bgo2[i*2]-X)<=2&&abs(Bgo2[i*2+1]-Y)<=2))goto X31;}if(Bgo2[2]==Bgo2[4]||Bgo2[2]==Bgo2[6]||Bgo2[6]==Bgo2[4]||Bgo2[5]==Bgo2[3]||Bgo2[3]==Bgo2[7]||Bgo2[5]==Bgo2[7]) goto X31;}if(Bwhat2==3){Bgo2[2]=rand()%2;}if(Bwhat2==4||Bwhat2==5||Bwhat2==6){Bvy2=-1.5;Bvx2=-0.5;}}if(Bwhat2==1){Bgo2[1]++,Bgo2[2]++;int R=rand()%(5-Bgo2[1]),r=rand()%(30-Bgo2[2]);if(Out2) R=0;if(R==0) {int vx=Bvx2,vy=Bvy2;Bgo2[1]=0;Bvx2=(rand()%101-20)/50.0;Bvy2=(rand()%101-20)/50.0;if(Bgo2[3]<=2) Bvx2*=-1;if(Bgo2[3]%2==1) Bvy2*=-1;if(Out2) r=0;} if(r==0) Chang2 }if(Bwhat2==2){Bgo2[1]++;float bx,by,bvx,bvy;if(Bgo2[1]<21){for(int i=1;i<=3;i++){bvx=Bgo2[i*2]-Bx2,bvy=Bgo2[i*2+1]-By2;if(Bgo2[1]<=10){Setpos(Bx2+(Bgo2[1]-1)*bvx/10.0,By2+(Bgo2[1]-1)*bvy/10.0);if(abs(Bx2+(Bgo2[1]-1)*bvx/10.0-20)<0.5)cout<<"==";else cout<<"  ";bx=Bx2+Bgo2[1]*bvx/10.0;by=By2+Bgo2[1]*bvy/10.0;Setpos(bx,by);}else Setpos(Bgo2[i*2],Bgo2[i*2+1]);int r=rand()%4;if(r%2==0) Color(3);else Color(10);if(r<=1) cout<<"×";else cout<<"+";Color(0);}}if(Bgo2[1]==21){Map(0,(bool)Kill);Color(3);int j=0;for(int j=0;j<=30;j++)for(int i=1;i<=3;i++)for(int k=1;k<=4;k++){if(k==1) bvx=j,bvy=0;if(k==2) bvx=-j,bvy=0;if(k==3) bvx=0,bvy=j;if(k==4) bvx=0,bvy=-j;bx=Bgo2[i*2]+bvx,by=Bgo2[i*2+1]+bvy;if(bx<=5||bx>=30||by<0||by>=30) {continue;}Panboss(bx,by);Setpos(bx,by),cout<<"█";Bbl++;Bway[Bbl][0]=bx;Bway[Bbl][1]=by;}Color(0);Map(-1,0);Chang2}}if(Bwhat2==3){Bgo2[1]++;if(Bgo2[1]<=18){if(Bgo2[3]==0) Setpos(Bgo2[4]-3,Bgo2[5]),cout<<"  ",Setpos(Bgo2[4]+3,Bgo2[5]),cout<<"  ",Color(0),Setpos(20,Bgo2[5]),cout<<"==";if(Bgo2[3]==1) Setpos(Bgo2[4],Bgo2[5]-3.5),cout<<"    ",Setpos(Bgo2[4],Bgo2[5]+2.5),cout<<"    ",Color(0),Setpos(20,Bgo2[5]+2.5),cout<<"====",Setpos(20,Bgo2[5]-3.5),cout<<"====";if(Bgo2[1]%4==0)Bgo2[3]=!Bgo2[3];if(Bgo2[1]%6<3)Color(3);else Color(5);if(Bgo2[3]==0) Setpos(X-3,Y),cout<<"▼",Setpos(X+3,Y),cout<<"▲",Bgo2[4]=(int)(X+0.5),Bgo2[5]=(int)(Y+0.5);if(Bgo2[3]==1) Setpos(X,Y-3),cout<<" ",Setpos(X,Y+3),cout<<" ",Bgo2[4]=(int)(X+0.5),Bgo2[5]=(int)(Y+0.5);Color(0);}if(Bgo2[1]==18){if(Bgo2[3]==0) Setpos(Bgo2[4]-3,Bgo2[5]),cout<<"  ",Setpos(Bgo2[4]+3,Bgo2[5]),cout<<"  ",Color(0),Setpos(20,Bgo2[5]),cout<<"==";if(Bgo2[3]==1) Setpos(Bgo2[4],Bgo2[5]-3.5),cout<<"    ",Setpos(Bgo2[4],Bgo2[5]+2.5),cout<<"    ",Color(0),Setpos(20,Bgo2[5]+2.5),cout<<"====",Setpos(20,Bgo2[5]-3.5),cout<<"====";}if(Bgo2[1]>18&&Bgo2[1]<=25){Bgo2[3]=Bgo2[2];if(Bgo2[3]==0) Setpos(Bgo2[4]-3,Bgo2[5]),cout<<"  ",Setpos(Bgo2[4]+3,Bgo2[5]),cout<<"  ",Color(0),Setpos(20,Bgo2[5]),cout<<"==";if(Bgo2[3]==1) Setpos(Bgo2[4],Bgo2[5]-3.5),cout<<"    ",Setpos(Bgo2[4],Bgo2[5]+2.5),cout<<"    ",Color(0),Setpos(20,Bgo2[5]+2.5),cout<<"====",Setpos(20,Bgo2[5]-3.5),cout<<"====";if(Bgo2[1]%4<2)Color(3);else Color(5);if(Bgo2[3]==0) Setpos(Bgo2[4]-3,Bgo2[5]),cout<<"▼",Setpos(Bgo2[4]+3,Bgo2[5]),cout<<"▲";if(Bgo2[3]==1) Setpos(Bgo2[4],Bgo2[5]-3),cout<<" ",Setpos(Bgo2[4],Bgo2[5]+3),cout<<" ";Color(0);}if(Bgo2[1]==25){if(Bgo2[2]==0){Color(3);for(int i=4;i<=29;i++){Setpos(i,Bgo2[5]),cout<<"█";Bbl++;Panboss(i,Bgo2[5]);Bway[Bbl][0]=i;Bway[Bbl][1]=Bgo2[5];}}if(Bgo2[2]==1){Color(3);for(int i=0;i<=28;i++){Setpos(Bgo2[4],i),cout<<"█";Bbl++;Panboss(Bgo2[4],i);Bway[Bbl][0]=Bgo2[4];Bway[Bbl][1]=i;}}Chang2}}if(Bwhat2==4||Bwhat2==5||Bwhat2==6){Bgo2[1]++;if(By2>27)Bvy2=0;if(Bx2>23)Bvx2=0;if(Bgo2[1]>13&&Bgo2[1]%3==0){float t=By2-Y,g=0.35;if(Boss==6) t/=2.0;CpGuai(Bwhat2+2,Bx2,By2,(Bx2-X)/t*1.0+(t-1)*g/2.0,1);}if(Bgo2[1]>20) Chang2}
}
void Boss3(){#define Bean br++;B[br].what=13;B[br].x=Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].life=1;for(int j=0;j<20;j++)if(abs(Bx3-I[j][0])<2&&By3-I[j][1]<=2){Setpos(I[j][0],I[j][1]);if(I[j][0]==20) cout<<"===";else cout<<"   ";I[j][0]=I[j][1]=-1;Bblo-=8+Lv*2;Exp+=2;}Bx3-=Bvx3;By3-=Bvy3;if(Bwhat3<=8){if(Bx3>X&&Bvx3<1.5) Bvx3+=0.3;if(Bx3<X&&Bvx3>-1.5) Bvx3-=0.3;}if(Bwhat3==0){X22:Bwhat3=rand()%12;if(Bwhat3==11&&abs(Bx3-20)<=1)goto X22;if(Bwhat3==11)Bgo3[2]=rand()%5;}if(Bwhat3==1){Bgo3[1]++;if(Bgo3[1]==6){br++;B[br].what=13;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=1;B[br].How=(int)Bx3-4;B[br].life=1;br++;B[br].what=13;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=-1;B[br].How=(int)Bx3+2;B[br].life=1;br++;B[br].what=13;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].life=1;Chang3}}if(Bwhat3>=2&&Bwhat3<=6){Bgo3[1]++;if(Bgo3[1]==6){br++;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].what=11+Bwhat3;B[br].vy=0.5+(rand()%100)/80.0;if(Bwhat3==5)B[br].vy=B[br].vy*3/4.0;B[br].life=1;Chang3}}if(Bwhat3==7){Bgo3[1]++;if(Bgo3[1]==6){br++;B[br].what=14;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=1;B[br].How=(int)Bx3-4;B[br].life=1;br++;B[br].what=14;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=-1;B[br].How=(int)Bx3+2;B[br].life=1;br++;B[br].what=14;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].life=1;Chang3}}if(Bwhat3==8){Bgo3[1]++;if(Bgo3[1]==6){br++;B[br].what=15;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=1;B[br].How=(int)Bx3-4;B[br].life=1;br++;B[br].what=15;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].vx=-1;B[br].How=(int)Bx3+2;B[br].life=1;br++;B[br].what=15;B[br].x=(int)Bx3-1,B[br].y=By3-1;B[br].vy=1;B[br].life=1;Chang3}}if(Bwhat3==9){Bvx3=0;Bgo3[1]++;if(Bgo3[1]==6||Bgo3[1]==8){Bean}if(Bgo3[1]>=8)Chang3}if(Bwhat3==10){Bvx3=0;Bgo3[1]++;if(Bgo3[1]==6||Bgo3[1]==8||Bgo3[1]==10||Bgo3[1]==12){Bean}if(Bgo3[1]>=12)Chang3}if(Bwhat3==11){Bvx3=0;Bgo3[1]++;if(Bgo3[1]>=8)for(int i=1;i<=4;i++){br++;B[br].what=80+100*Bgo3[2]+Bgo3[1]*4+i;B[br].x=Bx3-1,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=99;B[br].x=Bx3,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=99;B[br].x=Bx3-2,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;}if(Bgo3[1]>=20){for(int i=1;i<=4;i++){br++;B[br].what=98;B[br].x=Bx3-1,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=98;B[br].x=Bx3,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=98;B[br].x=Bx3-2,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;}Chang3}}
}
void Ball(int ball){if(ball==1){if(Fir<3&&T%8==0) Fir++;if(Fir>0){br++;B[br].what=-13;B[br].x=X;B[br].y=Y+rand()%3-1;B[br].life=1;if(Dis<=30) B[br].a=Disb,B[Disb].a=1,Fir--;else if(Boss!=0) B[br].a=13880086,Fir--;else if(Dis!=13880087) B[br].a=Disb,B[Disb].a=1,Fir--;else if(Dis1!=13880087) B[br].a=Disb1,B[Disb1].a=1,Fir--;else B[br].life=0;Dis=Dis1=13880087;}}if(ball==2){if(T%4==0)ib=(ib+1)%20,I[ib][1]=Y-2;if(T%16==0)I[ib][0]=X;if(T%16==4)I[ib][0]=X-1;if(T%16==8)I[ib][0]=X+1;if(T%16==12)I[ib][0]=X-2;if(T%12==9)I[ib][0]=X+2;if(Water==1){for(int i=X-6;i<=X+6;i++)ib=(ib+1)%20,I[ib][0]=i,I[ib][1]=Y-2-0.5*abs(i-X);}}if(ball==3){if(Wind>5){if(Y<Ding-1)Vy=5;else Vy=0;if(Up>=1) Vx=-5;if(Down==2) Vx=5;}if(Wind<5){if(Y>Ding-1)Vy=-5;else Vy=0;if(Up>=1) Vx=-5;if(Down==2) Vx=5;}if(Wind==5){if(Boss==2) Ding=12.25;else Ding=6.25;if(Boss!=0) Bblo-=16+Lv*4;if(Boss==1) Chang1 if(Boss==2) Chang2 if(Boss==3) Chang3 system("color 3F");Sleep(20);system("color 6F");Sleep(10);system("color 0F");system("cls");for(int i=bl;i<=br;i++)if(B[i].what>0)B[i].life=0;Setpos(20,0);for(int i=1;i<=60;i++) printf("=");}}if(ball==4){if(Thun==1){if(Boss!=0) Bblo-=16+Lv*4;if(Boss==1) Chang1 if(Boss==2) Chang2 if(Boss==3) Chang3 system("color 9F");Sleep(20);system("color 6F");Sleep(10);system("color 0F");system("cls");for(int i=bl;i<=br;i++)if(B[i].what>0)B[i].life=0;Setpos(20,0);for(int i=1;i<=60;i++) printf("=");}}if(ball==5){system("cls"); Color(5);Setpos(10,10);cout<<"新天赋!";Y:int rr=rand()%4+2;Setpos(12,10);if(rr==Ren) goto Y;if(rr==2)cout<<"瞬跳";if(rr==3)cout<<"空之舞";if(rr==4)cout<<"三段跳";if(rr==5)cout<<"反重力跳跃";Setpos(14,10);cout<<"当前天赋:";if(Ren==1)cout<<"小无敌";if(Ren==2)cout<<"瞬跳";if(Ren==3)cout<<"空之舞";if(Ren==4)cout<<"三段跳";if(Ren==5)cout<<"反重力跳跃";Setpos(16,10);cout<<"换否?(y/n)";G:char g=_getch();if(g=='y')Ren=rr;else if(g!='n')goto G;system("cls");Setpos(20,0);Color(0);for(int i=1;i<=60;i++) printf("=");}if(ball==6){Color(4);for(float i=1;i<=Bblo;i+=Bblomax/20.0)cout<<"▄";Color(0);cout<<' '<<Bblo<<"                              ";Color(0);}if(ball==7){Color(1);if(Win==7&&T%6<3)Color(3);for(float i=1;i<=Blo;i+=Blomax/20.0)cout<<"▄";Color(0);if(Win==7&&T%6<3)Color(3);printf(" %0.1f                              ",Blo);}
}
int main(){system("mode con cols=60 lines=37");CONSOLE_CURSOR_INFO cursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);srand((unsigned)time(NULL));Win=0;Ren=1;Lv=1;Blo=Blomax=100/*这里改变血量*/;Expmax=300;Hui=15;X=18,Y=6;ReStart:system("cls");memset(B,0,sizeof(B));memset(I,-1,sizeof(I));T=0;bl=0;br=-1;Upt=0;Start:Blo=Blomax * 100;Ding=6.25;memset(Bgo1,0,sizeof(Bgo1));memset(Bgo2,0,sizeof(Bgo2));memset(Bgo3,0,sizeof(Bgo3));if(Win%2==0) T=0;if(Win%2==0&&D==0){if(Win>0)Ball(5);Boss=0;lL:L=rand()%4+1;for(int i=0;i<=Win/2-1;i++)if(L==Ll[i]) goto lL;Ll[Win/2]=L;}if(Win%2==1&&D==0){if(Win==7)Boss=6,T=0,Blomax+=100;else{bl:Boss=rand()%3+1;for(int i=0;i<=3;i++)if(Boss==Bl[i]) goto bl;}Bl[Win/2]=Boss;Bwhat1=Bwhat2=Bwhat3=0,Bx1=10,By1=20,Bx2=15,By2=20,Bx3=21,By3=20;system("color 4C");Sleep(20);system("color 0F");Map(0,1);Sleep(1000);}if(Win%2==1){Bblomax=500+(Win/2)*500;Bblo=Bblomax;if(Boss==2) Ding=12.25;}while(1){T++;if(Wind==0){if(GetAsyncKeyState(VK_LEFT)&0x8000) Vy=-(10-abs(Ding-Y)*1.5)/20.0;if(GetAsyncKeyState(VK_RIGHT)&0x8000) Vy=(10-abs(Ding-Y)*1.5)/20.0;}if(GetAsyncKeyState(VK_UP)&0x8000&&u1==0) {u1++;if(Down==1){Down=0;Up=0;if(Ren==2)Map(-1,0),Vx=0,X=18,Li=5;else Vx=7,Vy=0.3;}else if(Up==0&&Wind==0) {Down=0;Up=1;if(Ren==2)Map(-1,0),Vx=1,X=10,Map(0,3),Li=5;else Vx=2,Vy=0.1;}else if(Up==1&&Wind==0) {Down=0;Up=2;if(Ren==2)Map(-1,0),Vx=1,X-=6,Map(0,3),Li=5;else Vx=1.5,Vy=0.1;}else if(Ren==3&&Up==2&&Wind==0) {Down=0;Up=3;Vx=1;Vy=0.5;Upt=30;}else if(Ren==4&&Up==2&&Wind==0) {Down=0;Up=3;Vx=1.8;Vy=0.1;}}if(GetAsyncKeyState(VK_DOWN)&0x8000&&u2==0) {u2++;if(Down==1&&Ren==5){Down=2;Up=0;Vx=-1.7;}else {Down=1;Up=0;if(Ren==2)Map(-1,0),Vx=0,X=22,Map(0,3),Li=5;else {if(Upt!=0) Map(-1,0),Upt=0;Vx=-7;}}}if((GetAsyncKeyState(VK_UP)&0x8000) ?0:1) u1=0;if((GetAsyncKeyState(VK_DOWN)&0x8000) ?0:1) u2=0;if(kbhit()){char g=_getch();if(g==' ') Sleep(100),Setpos(4,1),Sy++,system("pause");}if(Sy==1) Setpos(4,1),printf("                           "),Sy--;if(Drug==0) Blo=fmin((float)Blomax,Blo+Hui/100.0);else if(T%10==0)Blo--;if(T%20==0) {if(Kill!=0) Kill=0;if(Lvl!=0) Lvl=0;}if(Killb>0) Killb--;if(Li>0) Li--;if(Ice>0) Ice--;if(Drug>0) Drug--;if(Magne>0) Magne--;if(Fire>0) Ball(1),Fire--;if(Water>0) Ball(2),Water--;if(Wind>0) Ball(3),Wind--;if(Thun>0) Ball(4),Thun--;if(Boss==0) NorGuai(L,T%1500);RandGood();if(T%20==1)Exp++;if(T%50==1){Exp++;system("cls");Setpos(20,0);Color(0);for(int i=1;i<=60;i++) printf("=");if(Win==0&&T<300){Setpos(4,6);cout<<"↑/↓ 跳跃/下翻,←→ 些微移动(松手即返回)"; Setpos(8,6);cout<<"球可以开启特殊效果,经验积满(300)可提升级别。";Setpos(8,6);cout<<"打败 7 波即胜利,打败 BOSS 有新天赋。";Setpos(10,15);cout<<"空格可以暂停。";}}Map(-1,0);if(Boss==1) Boss1();if(Boss==2) Boss2();if(Boss==3) Boss3();if(Boss==6) Boss1(),Boss2(),Boss3();Move();Map(0,(bool)Kill);Color(0);Setpos(1,1);Blo=fmin(Blo,(float)Blomax);if(Boss==0)cout<<"血量: "<<(int)Blo<<"  ";Color(0);Setpos(1,9),cout<<"死亡次数: "<<D<<"  ";Setpos(2,1);Exp=min(Exp,Expmax);if(Exp>=Expmax)Exp=0,Lv++,Lvl++,Hui++,Blomax+=5;if(Lvl>0)Color(5);cout<<"级别: "<<Lv;Color(0);Setpos(2,9);cout<<"经验: "<<Exp<<"  ";if(Boss>0) Setpos(3,1),cout<<"血量     : ",Ball(7);if(Boss>0&&Boss!=6) Setpos(4,1),cout<<"怪物血量: ",Ball(6);if(Boss==6) Setpos(1,9),printf("时间: %0.1f s  ",T/15.0);if(Win==0) Sleep(55);if(Win==1) Sleep(50);if(Win==2) Sleep(35);if(Win==3) Sleep(40);if(Win==4) Sleep(25);if(Win==5) Sleep(30);if(Win==6) Sleep(20);if(Win>=7) Sleep(17);if(Boss==3&&Bblo<=0){for(int i=1;i<=4;i++){br++;B[br].what=98;B[br].x=Bx3-1,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=98;B[br].x=Bx3,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;br++;B[br].what=98;B[br].x=Bx3-2,B[br].y=By3-1+i;B[br].vy=4;B[br].life=1;}}if((Win%2==0&&T>=1400)||(Win%2==1&&Bblo<=0)||(Win==7&&T>=450)||Blo<=0) {Map(-1,0);break;}}if(Blo<=0){Sleep(1000);D++;system("color 7F");Setpos(15,11);Color(4);cout<<"GAME OVER...";Sleep(2000);goto ReStart;}else if(Win==6){system("color 7F");Setpos(15,11);Color(4);cout<<"坚持30秒 !";Sleep(2000);Setpos(30,0);Win++;D=0;}else if(Win==7){Sleep(1000);system("color 6E");Setpos(15,11);Color(5);cout<<"YOU WIN !";Sleep(2000);Setpos(30,0);return 0;}else Sleep(1000),Win++,D=0;goto Start;
}

4.愤怒的小鸟

#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
using namespace std;
const double pi = 3.1415926536;
int toint (float a) {return ((int) (a * 10 + 5)) / 10;
}
void Color (int a) {if (a == 0 || a == 14 || a == 20) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);} else if (a == 1 || a == 12) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);} else if (a == 2) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);} else if (a == 3) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);} else if (a == 4 || a == 11) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);} else if (a == 5 || a == 13) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);} else if (a == 7) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE);} else if (a == 15) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);} else if (a == 16) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_GREEN);} else if (a == 17) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED);} else if (a == 8) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);} else if (a == 6) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);} else if (a == 9) {SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|BACKGROUND_RED|BACKGROUND_GREEN);}
}
void SetPos (float x, float y) {int xx = toint (x), yy = toint (y);COORD pos;pos.X = yy * 2;pos.Y = xx;SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), pos);
}
struct node {int W, W2, S, mS;float X, Y;float vx, vy;float ax, ay;bool go, boom;
} blt[100001], pig[100001], boo[100001];
int T, yX, yY, Xy, put, K, K2, Sle, What;
int Bot, Pit, Blt, Pig, Sco, pigk, scok;
int m[41][41];
void Cout (int a, int x, int y) {if (a == 1) {SetPos (x, y);Color (5);cout << put << ' ';}if (y == 202) {SetPos (pig[a].X, pig[a].Y);cout << ". ";if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {SetPos (pig[a].X - 2, pig[a].Y);cout << ". ";SetPos (pig[a].X - 1, pig[a].Y);cout << ". ";} else if (pig[a].W == 4) {SetPos (pig[a].X, pig[a].Y - 1);cout << ". ";} else if(pig[a].W == 5) {SetPos (pig[a].X - 1, pig[a].Y);cout << ". ";SetPos (pig[a].X - 1, pig[a].Y - 1);cout << ". ";}}if (a == 2) {for (int i = 0; i <= 40; i++) {for (int j = 0; j <= 40; j++) {if (i <= 18 && m[i][j] == 1) {SetPos (i, j);Color (7);cout << "■";}if (m[i][j] >= 2 && m[i][j] <= 19) {SetPos (i, j);Color (5);cout << "█";m[i][j]++;}if (m[i][j] > 19 && m[i][j] <= 29) {SetPos (i, j);Color (0);cout << "█";m[i][j]++;if (m[i][j] == 30) {SetPos (i, j);Color (0);cout << "  ";m[i][j] = 0;}if (m[i][j] >= 31 && m[i][j] <= 49) {SetPos (i, j);Color (0);cout << "■";m[i][j]++;}if (m[i][j] == 50) {SetPos (i, j);Color (7);cout << "■";m[i][j] = 1;}}}}}if (y == 666) {SetPos (blt[a].X, blt[a].Y);Color (10 + blt[a].W);cout<<"●";}Color (0);
}
void Go (int a) {SetPos (blt[a].X, blt[a].Y);cout << "..";blt[a].X += blt[a].vx / 2;blt[a].Y += blt[a].vy / 2;blt[a].vx += blt[a].ax / 2;blt[a].vy += blt[a].ay / 2;if (blt[a].X >= 20) {blt[a].X = 19;}if (blt[a].X > 20 || blt[a].Y > 38 || blt[a].X < 0 || blt[a].Y <= 0) {blt[a].go = 1;}if (blt[a].W2 == 1 && blt[a].Y >= Xy) {blt[a].go = 1;Sle = 0;//地跑鸟}if (blt[a].W2 == 0) {for (int i = 0; i <= blt[a].vx / 2 + 1; i++) {if (blt[a].vx > 0 && m[toint (blt[a].X) + i][toint (blt[a].Y)] == 1) {if (blt[a].W != 5) {blt[a].boom = 1;}blt[a].X = toint (blt[a].X) + i - 1;blt[a].Y += blt[a].vy / 2;blt[a].vx = -blt[a].vx * 0.4;blt[a].vy = blt[a].vy * 0.8;if (blt[a].W == 3) {blt[a].ax = 0.5;}if (blt[a].W == 7) {blt[a].vx *= 2;}if (blt[a].W == 10) {blt[a].go = 1;Bot++;boo[Bot].X = blt[a].X;boo[Bot].Y = blt[a].Y;boo[Bot].S = 1;boo[Bot].mS = 4;}}if (blt[a].vx < 0 && m[toint (blt[a].X) - i][toint(blt[a].Y)] == 1) {if (blt[a].W != 5) {blt[a].boom = 1;}blt[a].X = toint (blt[a].X) + i + 1;blt[a].Y += blt[a].vy / 2;blt[a].vx = -blt[a].vx;blt[a].vy=blt[a].vy * 0.8;if (blt[a].W == 3) {blt[a].ax = 0.5;}if (blt[a].W == 7) {blt[a].vx *= 2;}if (blt[a].W == 10) {blt[a].go = 1;Bot++;boo[Bot].X = blt[a].X;boo[Bot].Y = blt[a].Y;boo[Bot].S = 1;boo[Bot].mS = 4;}}}if (abs (blt[a].vx) <= 0.1 && abs (blt[a].vy) <= 0.1 && abs (blt[a].ay) <= 0.1) {blt[a].go = 1;if (blt[a].W == 5) {Bot++;boo[Bot].X = blt[a].X;boo[Bot].Y = blt[a].Y;boo[Bot].S = 1;boo[Bot].mS = 4;blt[a].go = 1;}}}if (blt[a].go == 0) {Cout (a, 0, 666);}
}
void Kill (int a) {if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {Cout (a, 202, 202);pig[a].Y = 16;}if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {pig[a].W = 1;}int R = rand () % 50;Cout (a, 202, 202);//清除猪猪pig[a].X += pig[a].vx / 2;pig[a].Y += pig[a].vy / 2;pig[a].vx += pig[a].ax / 2;pig[a].vy += pig[a].ay / 2;for (int i = -2; i <= pig[a].vx / 2 + 1; i++) {if (m[toint (pig[a].X) + i][toint (pig[a].Y)] == 1) {pig[a].X = toint (pig[a].X) + i - 1;pig[a].Y += pig[a].vy / 2;pig[a].vx = -pig[a].vx * 0.5;pig[a].vy = pig[a].vy * 0.8;}}for (int i = Blt - 10; i <= Blt; i++) {if (pig[a].W == 5 && blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1&& abs (pig[a].Y - blt[i].Y) <= 1) {m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;pig[a].W2++;Sco += 2;break;}if (pig[a].W == 5 && m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {m[toint (pig[a].X) - 1][toint (pig[a].Y)] = 2;pig[a].W2++;Sco += 2;break;}if (blt[i].go == 0 && abs (pig[a].X - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {if (pig[a].W == 6) {Bot++;boo[Bot].X = pig[a].X;boo[Bot].Y = pig[a].Y;boo[Bot].S = 1;boo[Bot].mS = 4;blt[i].go = 1;}m[toint (pig[a].X)][toint (pig[a].Y)] = 2;pig[a].go = 1;Pig--;Sco+=10;break;}if (m[toint (pig[a].X)][toint (pig[a].Y)] >= 2 &&m[toint (pig[a].X)][toint (pig[a].Y)] < 30) {if (pig[a].W == 6) {Bot++;boo[Bot].X = pig[a].X;boo[Bot].Y = pig[a].Y;boo[Bot].S = 1;boo[Bot].mS = 4;}pig[a].go = 1;Pig--;Sco += 10;break;}if ((pig[a].W == 2 || pig[a].W == 3) && blt[i].go == 0 &&abs (pig[a].X - 2 - blt[i].X) <= 1 && abs (pig[a].Y - blt[i].Y) <= 1) {m[toint (pig[a].X)][toint (pig[a].Y)] = 2;pig[a].go = 1;Pig--;Sco += 10;break;}if ((pig[a].W == 2 || pig[a].W == 3) &&m[toint (pig[a].X - 2)][toint (pig[a].Y)] >= 2&& m[toint (pig[a].X - 2)][toint (pig[a].Y)] < 30) {pig[a].go = 1;Pig--;Sco += 10;break;}}//弄死猪猪if (pig[a].go == 0) {if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {Cout (a, 202, 202);pig[a].Y = 16;}if (pig[a].go == 0 && pig[a].W == 4 &&pig[a].Y < 20) {pig[a].W = 1;}int Xx = toint (pig[a].X), Xy = toint (pig[a].Y);if (pig[a].W == 6) {SetPos (pig[a].X, pig[a].Y);Color (9);cout << "C4";Color (0);} else {SetPos (pig[a].X, pig[a].Y);Color (2);cout << "●";if ((pig[a].W == 2 || pig[a].W == 3) && pig[a].X >= 2) {SetPos (pig[a].X - 2, pig[a].Y);Color (0);cout << "○";SetPos (pig[a].X - 1, pig[a].Y);cout << "|";} else if (pig[a].W == 4) {SetPos (pig[a].X, pig[a].Y - 1);Color (2);cout << "﹃";} else if (pig[a].W == 5) {SetPos (pig[a].X - 1, pig[a].Y);Color (8);SetPos (pig[a].X - 1, pig[a].Y - 1);cout << "▁";if (pig[a].W2 == 0) {cout << "▅";} else if (pig[a].W2 == 1) {cout << "▃";} else if (pig[a].W2 == 2) {cout << "▂";} else if (pig[a].W2 == 3) {pig[a].W = 1;pig[a].W2 = 0;SetPos (pig[a].X - 1, pig[a].Y - 1);cout << "  ";}}}//输出猪猪if (pig[a].W == 2 && pig[a].X > pig[a].S) {pig[a].W = 3;pig[a].ax = -0.4;pig[a].vx = 1.5;} else if (pig[a].W == 3 && pig[a].X <= pig[a].S) {pig[a].W = 2;pig[a].ax = 0.4;pig[a].vx = -1.5;}if ((pig[a].W == 2 || pig[a].W == 3) && (pig[a].Y <= 10 || pig[a].Y >= 38)) {pig[a].vy *= -1;}if (pig[a].W == 4 && R == 0 && pig[a].X == 20) {pig[a].vx = -((rand () % 40) / 10);}if(pig[a].W == 4) {int r = rand () % 20;for (int i = Blt - 10; i <= Blt; i++) {if (r <= 5 && blt[i].go == 0 && pig[a].Y - blt[i].Y <= 5 &&abs (blt[i].X - pig[a].X) <= 1.5 && r < 5) {r = 0;break;}}if (r == 0) {m[toint (pig[a].X)][toint (pig[a].Y) - 2] = 10;m[toint (pig[a].X)][toint (pig[a].Y) - 3] = 2;for (int j = toint (pig[a].Y) - 1; j >= toint (pig[a].Y) - 5; j--) {for (int i = Blt - 10; i <= Blt; i++) {if (blt[i].go == 0 && !(blt[i].W == 3 && blt[i].boom == 1)&& blt[i].W2 == 0 && toint (blt[i].Y) == j&& abs (blt[i].X - pig[a].X) <= 2) {blt[i].vy = -2;}}for (int i = Pit - 50; i <= Pit; i++) {if (pig[i].go == 0 && toint (pig[i].Y) == j && abs (pig[i].X - pig[a].X) <= 2) {pig[i].vy = -1;}}}}}//移动猪猪if (pig[a].go == 0 && pig[a].W != 2 && pig[a].W != 3 && pig[a].Y < 16) {Cout (a, 202, 202);pig[a].Y = 16;}if (pig[a].go == 0 && pig[a].W == 4 && pig[a].Y < 20) {pig[a].W = 1;}if (pig[a].X > 20 || pig[a].Y > 38 || pig[a].X < 0 || pig[a].Y <= 0) {pig[a].go = 1;Pig--;Cout (a, 202, 202);}//清除猪猪}
}
void Creat (int a, int p) {if (a == -1 && p == -1) {Blt++;blt[Blt].W = What;blt[Blt].W2 = 1;blt[Blt].vy = 1;blt[Blt].X = 19;blt[Blt].Y = 0;blt[Blt].boom = 1;} else if (a == 0 && p == -1) {int u = rand () % 7 + 1, U = rand() % 30;if (u >= 5) {Pit++;pig[Pit].Y = rand () % 15 + 20;pig[Pit].X = 2;pig[Pit].ax = 0.5;pig[Pit].W = 1;} else if (u == 1) {Pit++;pig[Pit].Y = rand () % 15 + 20;pig[Pit].X = 2;pig[Pit].vy = 0.5;pig[Pit].ax = 0.5;pig[Pit].S = rand () % 5 + 7;pig[Pit].W = 2;} else if (u == 2) {Pit++;pig[Pit].Y = rand () % 15 + 20;pig[Pit].X = 2;pig[Pit].ax = 0.5;pig[Pit].W = 4;} else if (u == 3) {Pit++;pig[Pit].Y = rand () % 15 + 20;pig[Pit].X = 2;pig[Pit].ax = 0.5;pig[Pit].W = 5;} else if (u == 4) {Pit++;pig[Pit].Y = rand () % 15 + 20;pig[Pit].X = 2;pig[Pit].ax = 0.5;pig[Pit].W = 6;}if (U == 1) {Bot++;boo[Bot].Y = rand () % 13 + 15;boo[Bot].X = (rand () % 4) * 3 + 8;boo[Bot].S = 0;boo[Bot].mS = rand () % 2 + 2;boo[Bot].W2 = 1;}} else {Blt++;blt[Blt].W = What;if (a == 1) {blt[Blt].X = yX;blt[Blt].Y = yY;blt[Blt].ax = 0.5; //抛物线}blt[Blt].vx = -3.5 * sin (p * pi / 180);blt[Blt].vy = 3 * cos (p * pi / 180);if (p <= 45) {blt[Blt].vy *= 1 + (0.33 - 0.01 * (45 - p));}if (p >= 45) {blt[Blt].vy *= 1 + (0.33 - 0.01 * (p - 45));}if (blt[Blt].W == 6) {blt[Blt].vy *= 1.2;blt[Blt].ax = 0.4;}}
}
void Boom (int a) {if (boo[a].W2 == 0) {int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;if (s == ms) {return ;}for (int i = x - s; i <= x + s; i++) {for (int j = y - s; j <= y + s; j++) {float k = (i - x) * (i - x) + (j - y) * (j - y) - s * s;if (k <= s && k >= -s && i <= 20 && j <= 38 && i >= 0 && j > 0 && m[i][j] != 1) {m[i][j] = 2;}}}boo[a].S++;}if (boo[a].W2 == 1) {int ms = boo[a].mS, s = boo[a].S, x = boo[a].X, y = boo[a].Y;if (s == ms) {return ;}if (y - s > 10) {m[x][y-s] = 31 - 31 * (boo[a].W2 - 1);}if (y + s < 40) {m[x][y+s] = 31 - 31 * (boo[a].W2 - 1);}boo[a].S++;}
}
void Move (int a) {Color (5);if (a == -2) {SetPos (17, Xy);cout << "        ";SetPos (18, Xy);cout << "        ";SetPos (19, Xy);cout << "        ";SetPos (20, Xy);cout << "       ";}if (a == -1) {SetPos (17, Xy);cout << "        ";SetPos (18, Xy);cout << "  ┃  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "     ▏";}if (a == 0) {SetPos (18, Xy);cout << "  ┃";Color (What + 10);cout << "●";Color (5);cout << "┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "     ▏";}if (a == 1) {SetPos (18, Xy);cout << "  ";Color (What + 10);cout << "●";Color (5);cout << "  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "     ▏";}if (a == 2) {SetPos (18, Xy);Color (What + 10);cout << "●";Color (5);cout << "┃  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "     ▏";}if (a == 3) {SetPos (18, Xy);cout << "  ┃  ┃";SetPos (19, Xy);Color (What + 10);cout << "●";Color (5);cout << "╰┳╯";SetPos (20, Xy);cout << "     ▏";}if (a == 4) {SetPos (18, Xy);cout << "  ┃  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);Color (What + 10);cout << "●";Color (5);cout << "   ▏";}if (a == 5) {SetPos (18, Xy);cout << "  ┃  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "  ";Color (What + 10);cout << "●";Color (5);cout << " ▏";}if (a == 6) {SetPos (18, Xy);cout << "  ┃  ┃";SetPos (19, Xy);cout << "  ╰┳╯";SetPos (20, Xy);cout << "    ";Color (What + 10);cout << "●";Color (5);cout << " ";}Color (0);
}
void Start () {char g;Color (5);system ("cls");SetPos (1, 1);cout << "------- 愤 怒 的 小 鸟 -------";Color (0);SetPos (3, 1);cout << "空格瞄准,按X触发小鸟技能,←→移动弹弓";SetPos (5, 1);cout << "猪猪技能自动触发,空中会有墙出现。";SetPos (7, 1);cout << "危险值由命中率,猪的存活时间计算!";SetPos (9, 1);cout << "危险值点满后失败!1500分通关!";SetPos (1, 20);cout << "-------- 小 鸟 技 能 --------";SetPos (3, 20);Color (11);cout << "●";Color (0);cout << ":无技能";SetPos (5, 20);Color (12);cout << "●";Color (0);cout << ":分身!不同分身初速度大小相同,";SetPos(6,20);cout<<"        方向不同。";SetPos (7, 20);Color (13);cout << "●";Color (0);cout << ":加速!以当前速度做匀速直线运动,";SetPos (8, 20);cout << "          且免疫狙击猪的冲击。";SetPos (9, 20);Color (14);cout << "●";Color (0);cout << ":投蛋!并获得向上速度做匀速直线";SetPos (10, 20);cout << "          运动,快达可以穿墙。";SetPos (11, 20);Color (15);cout << "●";Color (0);cout << ":爆炸!";SetPos (13, 20);Color (16);cout << "●";Color (0);cout << ":回旋!开始做向左加速运动!发射";SetPos (14, 20);cout << "          时获得双倍水平速度。";SetPos (15, 20);Color (17);cout << "●";Color (0);cout << ":[被动] 弹跳力为普通鸟三倍。发射";SetPos (16, 20);cout << "          时获得1.5倍水平、竖直速度。";SetPos (11, 1);cout << "-------- 猪 猪 技 能 --------";SetPos (13, 2);Color (2);cout << "●";Color (0);cout << ":无技能";SetPos (14, 1);Color (8);cout << "▁▅";SetPos (15, 2);Color (2);cout << "●";Color (0);cout << ":防御力为普通猪三倍";SetPos (16, 2);cout << "○";SetPos (17, 2);cout << "│:做空中简谐运动,受死范围";SetPos (18, 2);Color (2);cout << "●";Color (0);cout << "  为普通猪两倍。";SetPos (19, 2);cout << "    有几率跳起或发射冲击波,冲";SetPos (20, 1);Color (2);cout << "﹃●";Color (0);cout << ":开小鸟与同类,可以引爆TNT!";SetPos (18, 20);Color (5);cout << "按 y 开始游戏!";
A:if (kbhit ()) {g = _getch ();}if(g != 'y') {goto A;}
}
int main () {system ("mode con cols=79 lines=22");CONSOLE_CURSOR_INFO cursor_info = {1, 0};SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE), &cursor_info);srand ((unsigned)time(NULL));St:Start ();system ("cls");memset (blt, 0, sizeof (blt));memset (pig, 0, sizeof (pig));memset (boo, 0, sizeof (boo));memset (m, 0, sizeof (m));T = put = K = K2 = Sle = What = Pig = Sco = 0;pigk = scok = -1;Xy = 4;yX = 18;yY = 6;Blt = 20;Bot = 20;Pit = 60;Color (7);SetPos (19, 14);cout << "■";SetPos (20, 13);cout << " █▍";m[19][14] = m[20][13] = m[20][14] = 1;SetPos (21, 0);for (int i = 0; i < 39; i++) {cout << "■";m[21][i] = 1;}Color (0);What = rand () % 5 + 1;while (1) {if (Sco >= 1500) {break;}T++;K = 0;Color (0);if (Sco != scok) {SetPos (1, 1);cout << "分数:" << Sco << ' ';}if (Pig != pigk) {SetPos (3, 1);cout << "危险值:";int aa = min (Sco / 100, 10);Pig += aa;SetPos (3, 5);if (Pig <= 2) {Color (2);} else if (Pig <= 4) {Color (16);} else if (Pig <= 6) {Color (7);} else if (Pig <= 9) {Color (6);} else if (Pig <= 12) {Color (3);} else if (Pig <= 15) {Color (17);} else {Color (11);}for (int i = 1; i <= Pig; i++) {cout << "■";}Color (0);cout << ' ' << Pig;for (int i = 1; i <= 5; i++) {cout << "  ";}if (Pig > 18) {break;}Pig -= aa;}scok = Sco;pigk = Pig;if (GetAsyncKeyState (VK_LEFT)&0x8000 && Xy > 0) {Move (-2);Xy--;K = 1;}if (GetAsyncKeyState (VK_RIGHT)&0x8000 && Xy < 10) {Move (-2);Xy++;K = 1;}if (K == 1) {if (put == 0 && Sle == 0) {Move (0);} else {Move (-1);}}if (kbhit ()) {char g = _getch ();if (g == 'x' || g == 'X') {for (int i = Blt - 10; i <= Blt; i++) {if (blt[i].go == 0 && blt[i].boom == 0 && blt[i].W != 1 && blt[i].W != 7) {blt[i].boom = 1;if (blt[i].W == 2) {Blt++;blt[Blt].W = 2;blt[Blt].vy = blt[i].vy * 1.2;blt[Blt].vx = blt[i].vx + 1;blt[Blt].ax = blt[i].ax;blt[Blt].X = blt[i].X;blt[Blt].Y = blt[i].Y;blt[Blt].boom = 1;Blt++;blt[Blt].W = 2;blt[Blt].vy = blt[i].vy * 0.7;blt[Blt].vx = blt[i].vx - 1;blt[Blt].ax = blt[i].ax;blt[Blt].X = blt[i].X;blt[Blt].Y = blt[i].Y;blt[Blt].boom = 1;}if (blt[i].W == 3) {blt[i].vy = fmax (blt[i].vy * 1.5, 2.5);blt[Blt].vx++;blt[i].ax = 0;}if (blt[i].W == 4) {blt[i].vx = -3;blt[i].ax = 0.1;Blt++;blt[Blt].boom = 1;blt[Blt].W = 10;blt[Blt].X = blt[i].X;blt[Blt].Y = blt[i].Y;blt[Blt].ax = blt[i].ax;blt[Blt].vx = 1;}if (blt[i].W == 5) {Bot++;boo[Bot].X = blt[i].X;boo[Bot].Y = blt[i].Y;boo[Bot].S = 1;boo[Bot].mS = 5;blt[i].go = 1;}if (blt[i].W == 6) {blt[i].ay = -1;blt[i].ax = 0.3;blt[i].vx = min (blt[i].vx / 2, (float)0);}break;}}}}if (GetAsyncKeyState (' ')&0x8000 && K == 0 && Sle == 0) {if (put <= 5) {Move (1);yX = 18;yY = Xy + 1;} else if (put <= 20) {Move (2);yX = 18;yY = Xy;} else if (put <= 40) {Move (3);yX = 19;yY = Xy;} else if (put <= 60) {Move (4);yX = 20;yY = Xy;} else if (put <= 80) {Move (5);yX = 20;yY = Xy + 1;} else {Move (6);yX = 20;yY = Xy + 2;}if (put == 0) {K2 = 1;}if (put == 90) {K2 = -1;}if (K2 == 1) {put += min (rand () % 7 + 1, 90 - put);}if (K2 == -1) {put-=min(rand()%7+1,put);}Cout (1, 17, Xy + 2);}if ((!(GetAsyncKeyState (' ')&0x8000) && (put != 0)) || (put != 0 && K == 1)) {Move (-1);Creat (1, put);put = 0;yX = 18;yY = 5;Sle = 1;What = rand () % 7 + 1;Creat (-1, -1);Sco = max (Sco - 5, 0);}for (int i = Blt - 10; i <= Blt; i++) {if (blt[i].go == 0) {Go (i);}}for (int i = Bot - 10; i <= Bot; i++) {if (boo[i].go == 0) {Boom (i);Cout (2, 0, 0);}}for (int i = Pit - 50; i <= Pit; i++) {if (pig[i].go == 0) {Kill (i);}}if (Sle != 0) {Move (-1);} else if (put == 0) {Move (0);}if (T % 300 == 0) {system ("cls");pigk = scok = -1;}if (T % 100 == 0) {Color (7);for (int i = 0; i <= 18; i++) {for (int j = 0; j <= 40; j++) {if (m[i][j] == 1 && T % 100 == 0) {SetPos (i, j);cout << "■";}}}SetPos (19, 14);cout << "■";SetPos (20, 13);cout <<" █▍";SetPos (21, 0);for (int i = 0; i < 39; i++) {cout << "■";Color (0);}}if (T % min (50, (2000 - Sco) / 30) == 0) {Pig++;Creat (0, -1);}Sleep (15);}if (Sco < 500) {if (MessageBox (NULL, "很遗憾,您输了,您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {goto St;} else {return 0;}} else {if (MessageBox (NULL, "恭喜您赢了!您还想再来一次吗?", "温馨提示", MB_YESNO) == IDYES) {goto St;} else {return 0;}}return 0;
}

5.走迷宫

#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <time.h>
#include<bits/stdc++.h>
using namespace std;
#define Wall 1        //用1表示墙 
#define Road 0        //用0表示路 
#define Start 2
#define End 3
#define up 72          
#define down 80
#define left 75
#define right 78
#define flag 5        
int Height=0,Width=0,N; 
int x=2,y=1; //玩家当前位置,刚开始在入口处bool visited[100][100];
class Migong
{
public:int difficulty;int map[100][100];void gotoxy(int x,int y);    //移动坐标的函数声明void shengcheng(int x,int y);   //随机生成迷宫的函数声明void display(int x,int y);    //显示迷宫的函数声明 void chushi();   //初始化迷宫的函数声明void setDifficulty(int diff);void setExit(); // 新增设置出口位置的函数声明
};class Wanjia:public Migong         //玩家类由迷宫类派生来 
{
public:void gonglue(int x,int y); void shang(int x,int y);void xia(int x,int y);void zuo(int x,int y);void you(int x,int y); void game();     //游戏运行包括移动的函数声明 
};
void Migong::setExit() {// 出口默认放置在迷宫的右下角map[Height - 1][Width] = End;// 可以在这里添加逻辑来根据难度或其他因素调整出口的位置
}
void Migong::gotoxy(int x,int y) //移动坐标                         这是使光标 到(x,y)这个位置的函数.调用 COORD 需要#include.
{COORD coord;coord.X=x;coord.Y=y;SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}void Migong::shengcheng(int x,int y) //随机生成迷宫
{int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向                                //数组c 0  1   向右 //      1  0   向下 //     -1  0   向上 //      0 -1   向左 int i,j,t; //将方向打乱for(i=0;i<4;i++){j=rand()%4;                                //随机生成j t=c[i][0];c[i][0]=c[j][0];c[j][0]=t;       //将c[i][0]和c[j][0]交换 t=c[i][1];c[i][1]=c[j][1];c[j][1]=t;       //类似上 }map[x][y]=Road;                                //当前位置设为路for(i=0;i<4;i++)                               //沿四个方向设置if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall)    //沿c[i][0]、c[i][1]方向前2步如果是墙{map[x+c[i][0]][y+c[i][1]]=Road;        //让该方向前一步设为路 shengcheng(x+2*c[i][0],y+2*c[i][1]);   //在该方向前两步继续生成地图        因为这里是递归函数,当执行到最后一点发现都不能走的时候,//会返回到上一个函数,也就是上一个点,再次判断是否可以产生地图 ,知道地图上所有点被遍历完。 }
}
void Migong::setDifficulty(int diff) {// 根据难度设置墙的比例int wallRatio;switch (diff) {case 1: wallRatio = 2; break; // 简单难度case 2: wallRatio = 40; break; // 中等难度case 3: wallRatio = 60; break; // 困难难度default: wallRatio = 20; break;}// 根据墙的比例初始化迷宫for (int i = 1; i <= Height; i++) {for (int j = 1; j <= Width; j++) {if (rand() % 100 < wallRatio) {map[i][j] = Wall;} else {map[i][j] = Road;}}}// 确保入口和出口是路map[1][1] = Start;map[Height - 1][Width] = End;
}void Migong::display(int x,int y) //显示迷宫
{gotoxy(2*y-2,x-1);switch(map[x][y]){case Start:cout<<"入";break; //显示入口case End:cout<<"出";break; //显示出口case Wall:cout<<"■";break; //显示墙case Road:cout<<" ";break; //显示路case up:cout<<"↑";break;  //在攻略中的标记 下同 case down:cout<<"↓";break;case left:cout<<"←";break; case right:cout<<"→";break;case flag:         cout<<" ";break;    //标记,防止攻略遍历时候无线循环 }
}
void shuru()
{cout<<"请输入您想创建的迷宫的N*N大小:"<<endl;cin>>N;
}
void Migong::chushi() {int i, j;srand((unsigned)time(NULL)); // 初始化随机种子for (i = 1; i <= Height + 1; i++)for (j = 1; j <= Width + 1; j++)if (i == 0 || i == Height + 1 || j == 0 || j == Width + 1) // 初始化迷宫       默认四周是路map[i][j] = Road;else map[i][j] = Wall;shengcheng(2 * (rand() % (Height / 2) + 1), 2 * (rand() % (Width / 2) + 1)); // 从随机一个点开始生成迷宫,该点行列都为偶数for (i = 0; i <= Height + 1; i++) // 边界处理      把最开始默认为路的堵上,以免跑出迷宫{map[i][0] = Wall;map[i][Width + 1] = Wall;}for (j = 0; j <= Width + 1; j++) // 边界处理{map[0][j] = Wall;map[Height + 1][j] = Wall;}map[2][1] = Start; // 给定入口setExit(); // 设置出口位置for (i = 1; i <= Height; i++)                // i初始为1,结束为height,以免画出外围{for (j = 1; j <= Width; j++) // 画出迷宫   同上{display(i, j);}}
}
void Wanjia::game()
{int x=2,y=1; //玩家当前位置,刚开始在入口处int c; //用来接收按键int score = 0; // 初始化得分clock_t startTime = clock();while(1){gotoxy(2*y-2,x-1);cout << "☆"; //画出玩家当前位置if(map[x][y] == End) //判断是否到达出口{gotoxy(2*N-2, N-1); //到达此坐标cout << "恭喜你!成功走出迷宫!" << endl;switch(difficulty){case 1: score = 10; break; // 简单难度case 2: score = 20; break; // 中等难度case 3: score = 30; break; // 困难难度}cout << "你的得分是:" << score <<"分!"<< endl;clock_t endTime = clock();double gameDuration = double(endTime - startTime) / CLOCKS_PER_SEC;// 输出游戏用时cout << "游戏用时: " << gameDuration << " 秒" << endl;cout << "是否要打印走过的路径进行复盘?(Y/N): ";char choice;cin >> choice;if(choice == 'Y' || choice == 'y') {// 打印玩家走过的路径for(int i=1;i<=Height;i++)                //i初始为1,结束为height,以免画出外围 {        for(int j=1;j<=Width;j++) //画出迷宫   同上 {if(visited[i][j]) {gotoxy(2*j-2,i-1);cout << "*"; // 打印走过的位置}else{gotoxy(2*j-2,i-1);switch(map[i][j]){case Start:cout<<"入";break; //显示入口case End:cout<<"出";break; //显示出口case Wall:cout<<"■";break; //显示墙case Road:cout<<" ";break; //显示路case up:cout<<"↑";break;  //在攻略中的标记 下同 case down:cout<<"↓";break;case left:cout<<"←";break; case right:cout<<"→";break;case flag:         cout<<" ";break;    //标记,防止攻略遍历时候无线循环 }}}    }}getch();exit(0);break;}if(c != -32){c = getch();switch(c){case 72: // 向上走if(map[x-1][y] != Wall){display(x, y);x--;}break;case 80: // 向下走if(map[x+1][y] != Wall){display(x, y);x++;}break;case 75: // 向左走if(map[x][y-1] != Wall){display(x, y);y--;}break;case 77: // 向右走if(map[x][y+1] != Wall){display(x, y);y++;}break;case 112:    // 按下Pgonglue(2,1);break;           //如果按下P执行攻略函数}}visited[x][y] = 1;}
}
void Wanjia::shang(int x,int y)
{if(map[x][y]==End) //判断是否到达出口{gotoxy(2*N-2,N-1);  //到达此坐标 cout<<"到达终点,按任意键结束";getch();exit(0);}if(map[x-1][y]!=Wall&&map[x-1][y]!=up&&map[x-1][y]!=down&&map[x-1][y]!=left&&map[x-1][y]!=right&&map[x-1][y]!=flag)   {                                           //当移动后的下一个位置没有被走过且不是墙                                                           map[x][y]=up;display(x,y);x--;gonglue(x,y);          //递归,攻略下一个点 }    
}
void Wanjia::xia(int x,int y)
{if(map[x][y]==End) //判断是否到达出口{gotoxy(2*N-2,N-1);  //到达此坐标 getch();exit(0);}if(map[x+1][y]!=Wall&&map[x+1][y]!=up&&map[x+1][y]!=down&&map[x+1][y]!=left&&map[x+1][y]!=right&&map[x+1][y]!=flag) //当移动后的下一个位置没有被走过且不是墙 {map[x][y]=down;display(x,y);x++;gonglue(x,y);            //递归,攻略下一个点}
}
void Wanjia::zuo(int x,int y)
{if(map[x][y]==End) //判断是否到达出口{gotoxy(2*N-2,N-1);  //到达此坐标 cout<<"到达终点,按任意键结束";         getch();exit(0);}if(map[x][y-1]!=Wall&&map[x][y-1]!=up&&map[x][y-1]!=down&&map[x][y-1]!=left&&map[x][y-1]!=right&&map[x][y-1]!=flag) //当移动后的下一个位置没有被走过且不是墙 {map[x][y]=left;display(x,y);y--;gonglue(x,y); //递归,攻略下一个点}
}
void Wanjia::you(int x,int y)
{if(map[x][y]==End) //判断是否到达出口{gotoxy(2*N-2,N-1);  //到达此坐标 cout<<"到达终点,按任意键结束";    getch();exit(0);}if(map[x][y+1]!=Wall&&map[x][y+1]!=up&&map[x][y+1]!=down&&map[x][y+1]!=left&&map[x][y+1]!=right&&map[x][y+1]!=flag) //当移动后的下一个位置没有被走过且不是墙 {map[x][y]=right;display(x,y);y++;gonglue(x,y); //递归,攻略下一个点}
}
void Wanjia::gonglue (int x,int y)
{gotoxy(2*y-2,x-1);cout<<"☆"; //画出玩家当前位置if(map[x][y]==End) //判断是否到达出口{gotoxy(2*N-2,N-1);  //到达此坐标 cout<<"到达终点,按任意键结束";getch();exit(0); }shang(x,y);                 //上下左右 xia(x,y);zuo(x,y);you(x,y);map[x][y]=flag;             //当上下左右都无法走的时候,即为死路,因为递归函数开始向后,所以讲死路点值置为flag,变成无形之墙。 display(x,y);              
}
int main()
{Migong a;cout<<"      移动迷宫      "<<endl;cout<<"--------------------"<<endl; cout<<"欢迎来到移动迷宫游戏"<<endl;cout<<"--------------------"<<endl;cout<<"游戏说明:给定一出口和入口"<<endl;cout<<"玩家控制一个五角星(☆)从入口走到出口"<<endl;cout<<"系统会记录你所走的步数"<<endl;cout<<"按回车进入游戏";cout<<"(按下P键可以获得攻略。)"; getch();system("cls");      //清屏函数 ,清除开始界面 Wanjia w1;cout << "请选择难度等级(1-简单,2-中等,3-困难): ";cin >> w1.difficulty;shuru();Width=N;Height=N;a.map[N][N];system("cls"); // 清屏,清除开始界面w1.chushi();w1.game(); //开始游戏
//    w1.gonglue(2,1);  //功略显示 getch();return 0;
}


http://www.ppmy.cn/news/1556906.html

相关文章

Pytorch | 利用BIM针对CIFAR10上的ResNet分类器进行对抗攻击

Pytorch | 利用BIM针对CIFAR10上的ResNet分类器进行对抗攻击 CIFAR数据集BIM介绍基本原理算法流程特点应用场景 BIM代码实现BIM算法实现攻击效果 代码汇总bim.pytrain.pyadvtest.py 之前已经针对CIFAR10训练了多种分类器&#xff1a; Pytorch | 从零构建AlexNet对CIFAR10进行分…

HTTP接口报错详解与解决 200,500,403,408,404

前言&#xff1a; 仅做学习记录&#xff0c;侵删 背景 当后端编写接口时&#xff0c;经常需要对接口使用ApiFox或者PostMan进行测试&#xff0c;此时就会出现各种各样的报错&#xff0c;一般都会包括报错编码&#xff1a;200,400,401等。这个状态码一般是服务器所返回的包含…

c++ 找第一个只出现一次的字符

【题目描述】 给定一个只包含小写字母的字符串&#xff0c;请你找到第一个仅出现一次的字符。如果没有&#xff0c;输出no。 【输入】 一个字符串&#xff0c;长度小于100000。 【输出】 输出第一个仅出现一次的字符&#xff0c;若没有则输出no。 【输入样例】 abcabd【输出样…

小程序中使用 Vue2 + Vuex 实现数据存储与获取

在小程序开发中&#xff0c;数据的存储与获取是一个非常重要的环节。本文将介绍如何在小程序中使用 Vue2 和 Vuex 实现数据的存储与获取。我们将通过一个具体的例子来展示如何在 Vuex 中管理用户信息和机构信息&#xff0c;并在组件中使用这些数据。 项目结构 首先&#xff0…

scala中正则表达式的使用

正则表达式&#xff1a; 基本概念 在 Scala 中&#xff0c;正则表达式是用于处理文本模式匹配的强大工具。它通过java.util.regex.Pattern和java.util.regex.Matcher这两个 Java 类来实现&#xff08;因为 Scala 运行在 Java 虚拟机上&#xff0c;可以无缝使用 Java 类库&…

STM32-- keil -常用功能

1.修改整个工程名称&#xff08;keil-c51编辑器&#xff09; 要同时修改这三个文件&#xff0c;不然要重新设置。 uvoptx文件 uvoptx文件记录了工程的配置选项&#xff0c;如下载器的类型、变量跟踪配置、断点位置以及当前已打开的文件等等&#xff1b; uvguix文件 uvguix文…

前端TypeScript学习day01-TS介绍与TS部分常用类型

(创作不易&#xff0c;感谢有你&#xff0c;你的支持&#xff0c;就是我前行的最大动力&#xff0c;如果看完对你有帮助&#xff0c;请留下您的足迹&#xff09; 目录 TypeScript 介绍 TypeScript 是什么 TypeScript 为什么要为 JS 添加类型支持&#xff1f;? TypeScript …

拦截器魔法:Spring MVC中的防重放守护者

目录 简介HandlerInterceptorAdapter vs HandlerInterceptor创建一个防重放拦截器注册拦截器路径模式匹配适配器模式的魅力总结 简介 在构建安全可靠的Web应用程序时&#xff0c;防止请求重放攻击是一项关键任务。当用户或系统发出的请求被恶意第三方捕获并重复发送给服务器…