存一下

`#include

include<stdio.h>

include<graphics.h>

include<conio.h>

include<stdlib.h>

include<Windows.h>

include

include

define REP(i, x, y) for(int i = (x);i <= (y);i++)

using namespace std;

int dialogX, dialogY;//记录对话框的左上角位置

struct Player {
int x, y, preX, preY;
int anim;
}plane;//控制台小飞机

void Handle(bool flag) {
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = flag;
SetConsoleCursorInfo(hOut, &cci);
}
//隐藏控制台光标

void SetConsole(int x, int y)

{

COORD position;
position.X = y;//坐标轴与行列不同
position.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);

}

//建立函数 移动光标 第一个参数为行

void Clear(int x, int y, int lenth) {
SetConsole(x, y);
REP(i, 1, lenth)
printf(" ");
}
//清除第x行y列开始的控制台输出 注:清除完后需要重定向

void Print(string s, int t) {
for (int i = 0; i < s.size(); i++) { //使用UNICODE
if (s[i] < 0) { //汉字
cout << s[i] << s[i + 1];
i++;
}
else cout << s[i];//字母
Sleep(t);
}
}
//实现间隔一定时间输出一个字

void Loading() {
for (int i = 1; i <= 5; i++) {
printf("/ ");
Sleep(200); printf("\b\b");
printf("- ");
Sleep(200); printf("\b\b");
printf("\ ");
Sleep(200); printf("\b\b");
printf("| ");
Sleep(200); printf("\b\b");
}
printf(" ");
}
//转圈圈

void DrawDialogBox(int x, int y, int numLine) {
SetConsole(x, y);
printf(" ————————");
for (int i = 1; i <= numLine - 2; i++) {
SetConsole(x + i, y);
if (i == 1) {
printf("| ");
cout << std::left << setw(15) << "";
printf("\___________________________________________");
}
else if (i == 2) {
printf("| ");
cout << std::left << setw(16) << " ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
| FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED);
printf(" ");//输出背景色为黄色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
else if (i == 8) {
printf("| ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
| FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
printf(" ///G&K MWCS V1.28 ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
printf("|");
}
else printf("| |");
}
SetConsole(x + numLine - 1, y);
printf(" ——————————————————————————————");
}
//从第x行y列开始绘制一个高度为numLine的对话框

void AnimDialogue(int x, int y) {
dialogX = x, dialogY = y;
SetConsole(x + 5, y);
Print(" ——————————————————————————————", 10);
Clear(x + 5, y, 80);
SetConsole(x + 4, y);
printf(" ——————————————————————————————");
SetConsole(x + 5, y);
printf("| |");
SetConsole(x + 6, y);
printf(" ——————————————————————————————");

Sleep(60);
for(int i = 4;i <= 6;i++)Clear(x + i, y, 80);
DrawDialogBox(x + 3, y, 5);

Sleep(60);
for (int i = 3; i <= 7; i++)Clear(x + i, y, 80);
DrawDialogBox(x + 2, y, 7);

Sleep(60);
for (int i = 2; i <= 8; i++)Clear(x + i, y, 80);
DrawDialogBox(x + 1, y, 9);

Sleep(60);
for (int i = 1; i <= 9; i++)Clear(x + i, y, 80);
DrawDialogBox(x, y, 10);
}

//从第x行开始模拟动画并绘制对话窗口

void DrawMap(int x1, int x2, int y, int lenth) {
SetConsole(x1, y);
printf(" ");
REP(i, 1, lenth)
printf("—");
REP(i, x1 + 1, x2 - 1) {
SetConsole(i, y);
printf("|");
REP(j, 1, lenth * 2)
printf(" ");
printf("|");
}
SetConsole(x2, y);
printf(" ");
REP(i, 1, lenth)
printf("—");
}
//绘制从x1到x2的控制台操作窗口

void AnimMap(int x1, int x2, int y, int lenth) {
int mid = (x1 + x2) / 2;
SetConsole(mid, y);
Print(" ", 3);
REP(i, 1, lenth)
Print("—", 3);
REP(i, 1, (x2 - x1) / 2) {
DrawMap(mid - i, mid + i, y, lenth);
Sleep(10);
}
}
//绘制控制台操控窗口(x2 - x1 + 1是奇数才行)

void BackgroundWhite() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY
| FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED
| BACKGROUND_BLUE);
}
void BackgroundBlack() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
| FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
void ForeGreen() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
| FOREGROUND_GREEN);
}
void ForeYellow() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY
| FOREGROUND_RED | FOREGROUND_GREEN);
}

void DrawG(int x, int y) {
SetConsole(x, y); BackgroundWhite();
printf(" "); SetConsole(x + 1, y);
printf(" "); SetConsole(x + 2, y);
printf(" "); SetConsole(x + 3, y);
printf(" "); BackgroundBlack(); printf(" "); BackgroundWhite(); printf(" "); SetConsole(x + 4, y);
printf(" "); BackgroundBlack(); printf(" "); BackgroundWhite(); printf(" "); SetConsole(x + 5, y);
printf(" "); BackgroundBlack(); printf(" "); BackgroundWhite(); printf(" "); SetConsole(x + 6, y);
printf(" ");
BackgroundBlack();
}
void Drawand(int x, int y) {
x++;//比其他两个字母少一行
y -= 2;//画的时候多了两格出来
SetConsole(x, y + 5); BackgroundWhite();
printf(" ");
SetConsole(x + 1, y + 4); printf(" ");
SetConsole(x + 1, y + 8); printf(" ");
SetConsole(x + 2, y + 5); printf(" ");
SetConsole(x + 3, y + 3); printf(" "); SetConsole(x + 3, y + 7); printf(" ");
SetConsole(x + 3, y + 9); printf(" ");
SetConsole(x + 4, y + 2); printf(" "); SetConsole(x + 4, y + 8); printf(" ");
SetConsole(x + 5, y + 3); printf(" "); SetConsole(x + 5, y + 9); printf(" ");
BackgroundBlack();
}
void DrawK(int x, int y) {
BackgroundWhite();
SetConsole(x, y);printf(" "); SetConsole(x, y + 8); printf(" ");
SetConsole(x + 1, y); printf(" "); SetConsole(x + 1, y + 6); printf(" ");
SetConsole(x + 2, y); printf(" "); SetConsole(x + 2, y + 4); printf(" ");
SetConsole(x + 3, y); printf(" ");
SetConsole(x + 4, y); printf(" "); SetConsole(x + 4, y + 4); printf(" ");
SetConsole(x + 5, y); printf(" "); SetConsole(x + 5, y + 6); printf(" ");
SetConsole(x + 6, y); printf(" "); SetConsole(x + 6, y + 8); printf(" ");
BackgroundBlack();
}
void DrawGandK(int x, int y) {
DrawG(x, y);
Drawand(x, y + 14);
DrawK(x, y + 26);
}
//绘制格里芬

void PrintDialogue(string speaker, string dialogue, int speed) {
int x = dialogX, y = dialogY;
SetConsole(x + 1, y + 6);
printf(" ");
SetConsole(x + 1, y + 6);
cout << speaker;
Clear(x + 5, y + 4, 57);
SetConsole(x + 5, y + 4);
Print(dialogue, speed);
//SetConsole(x + 10, y);
GetAsyncKeyState(VK_SPACE);//得先把缓存区的东西吃掉
while (!GetAsyncKeyState(VK_SPACE));
}
//输出对话,定位跟随对话框

int consoleX, consoleY;
void PrintConsole(int x, string content, int speed, bool stop) {
SetConsole(consoleX + x, consoleY);
cout << " ";
SetConsole(consoleX + x, consoleY);
Print(content, speed);
if (stop) {
GetAsyncKeyState(VK_SPACE);//得先把缓存区的东西吃掉
while (!GetAsyncKeyState(VK_SPACE));
}
}
//从控制台第x行输出控制台内容(从0开始)

void PrintPlane() {
//(x, y)为机头坐标 所以-2
switch (plane.anim) { //先写绘制
case 0 :
SetConsole(plane.x, plane.y - 2);
printf(" |");
SetConsole(plane.x + 1, plane.y - 2);
printf("———");
SetConsole(plane.x + 2, plane.y - 2);
printf(" | |");
break;
case 1 :
SetConsole(plane.x, plane.y - 2);
printf(" |/");
SetConsole(plane.x + 1, plane.y - 2);
printf(" /|");
SetConsole(plane.x + 2, plane.y - 2);
printf(" /|");
break;
case 2 :
SetConsole(plane.x, plane.y - 2);
printf(" \|");
SetConsole(plane.x + 1, plane.y - 2);
printf(" |\");
SetConsole(plane.x + 2, plane.y - 2);
printf(" |\");
break;
}
}
//每循环擦除上一次动画并绘制本次动画

void PositionJudge() {
if (plane.x < 1)plane.x = 1;
if (plane.x > 37)plane.x = 37;
if (plane.y < 3)plane.y = 3;
if (plane.y > 61)plane.y = 61;
}

void MovePlane(int speed) {
plane.preX = plane.x, plane.preY = plane.y;
Clear(plane.preX, plane.preY - 2, 6);
Clear(plane.preX + 1, plane.preY - 2, 6);
Clear(plane.preX + 2, plane.preY - 2, 6);
if (GetAsyncKeyState('W'))plane.x -= speed;
if (GetAsyncKeyState('S'))plane.x += speed;
if (GetAsyncKeyState('A'))plane.y -= speed;
if (GetAsyncKeyState('D'))plane.y += speed;
PositionJudge();
if (plane.y == plane.preY)plane.anim = 0;
else if(plane.y < plane.preY)plane.anim = 1;
else plane.anim = 2;
PrintPlane();
}

void Init() {
system("mode con cols=130 lines=45");//修改控制台大小防bug
plane.x = plane.preX = 37;
plane.y = plane.preY = 33;
plane.anim = 0;

consoleX = 21, consoleY = 68;//初始化输出控制台位置(对话框单独函数初始化过位置了
}

int consolePlaneLeftTime = 10000;
bool ConsolePlane() {
MovePlane(1);
Sleep(100);
consolePlaneLeftTime -= 100;
if (consolePlaneLeftTime < 0)return 0;
if (consolePlaneLeftTime < 7000) {
SetConsole(consoleX + 1, consoleY);
cout << "通讯记录云同步信号: ";
ForeYellow(); cout << "一般"; BackgroundBlack();

	}
if (consolePlaneLeftTime < 6400) {
	SetConsole(consoleX + 1, consoleY);
	cout << "通讯记录云同步信号: ";
	ForeGreen(); cout << "良好"; BackgroundBlack();
	}
return 1;
}

void Chapter1() {
puts("GRIFFIN & KRYUGER Combat Operation System[版本 10.0.19042.1348]");
puts("(c) GRIFFIN & KRYUGER Corporation。保留所有权利。\n");
printf("C:\Users\Commander>");
Sleep(3000);
Print("-", 1000);
Print("init", 150);
Print(" ", 1500);
Print("-MWCS", 150);
Print(" ", 600);
Print("access_416", 100);
Sleep(2500);
Handle(FALSE);
Print("\n通讯模块初始化", 60);
Sleep(500);
Loading();
puts("");
Print("通讯模块加载完毕", 60);
Print("...", 500);
Sleep(1000);
for (int i = 0; i < 6; i++)Clear(i, 0, 80);
SetConsole(0, 0);
Handle(TRUE);
Sleep(3000);
Handle(FALSE);
DrawGandK(1, 79);
Sleep(1000);
AnimDialogue(10, 66);
AnimMap(20, 40, 66, 30);
SetConsole(20, 66); printf("|");
BackgroundWhite();
printf(" ▅ C:\COS\system32\cmd.exe ");
BackgroundBlack();
printf("|");
PrintDialogue("格琳娜", "微波通讯系统(MWCS)启动,在你的系统上按下空格进行通讯。", 60);
//没写分行 这句差不多是单句最长了
PrintConsole(1, "通讯记录云同步信号: 测速中", 60, false);
Sleep(1000);
PrintConsole(1, "通讯记录云同步信号: ", 0, false);
ForeGreen(); cout << "良好"; BackgroundBlack();
Sleep(400);
PrintDialogue("格琳娜", "进行身份认证,", 60);
PrintDialogue("格琳娜", "格里芬直属404小队通讯员,格琳娜。", 60);
PrintDialogue("指挥官", "404小队飞行系统操作员,代号“指挥官”。", 60);
PrintConsole(2, " >声纹代码认证成功", 60, true);
SetConsole(consoleX + 1, consoleY);
cout << "通讯记录云同步信号: ";
ForeYellow(); cout << "一般"; BackgroundBlack();
Sleep(600);
SetConsole(consoleX + 1, consoleY);
cout << "通讯记录云同步信号: ";
ForeGreen(); cout << "良好"; BackgroundBlack();
Sleep(400);
PrintConsole(2, " >飞行系统接入中", 60, true);
PrintDialogue("指挥官", "正在接入飞行系统。", 60);
PrintDialogue("指挥官", "怎么样小格,休息够了么?", 60);
PrintConsole(2, " >飞行系统连接成功", 60, true);
PrintDialogue("格琳娜", "接入成功,各模块开始自检。", 60);
PrintConsole(2, " >模块自检中", 60, false);

PrintDialogue("格琳娜", "完 全 没 有 休 息 够 !", 100);
SetConsole(consoleX + 1, consoleY);
cout << "通讯记录云同步信号: ";
ForeYellow(); cout << "一般"; BackgroundBlack();
Sleep(600);
SetConsole(consoleX + 1, consoleY);
cout << "通讯记录云同步信号: ";
ForeGreen(); cout << "良好"; BackgroundBlack();
Sleep(400);
PrintDialogue("格琳娜", "天天加班演习演习演习,然后还得熬夜写报告书。", 60);
PrintDialogue("格琳娜", "老板也不发点加班费意思一下。", 60);
PrintDialogue("格琳娜", "再这么下去我要离职了啊,天天都掉头发。", 60);
PrintDialogue("指挥官", "好啦好啦,现在军方和铁血的局势很紧张。", 60);
PrintDialogue("指挥官", "格里芬又一直和军方有合作,咱任务总会变多的。", 60);
PrintDialogue("格琳娜", "这我当然知道!", 60);
PrintDialogue("指挥官", "(苦笑)", 60);
PrintDialogue("格琳娜", "...希望能和平解决吧。铁血那边也有我很好的朋友。", 60);
PrintDialogue("指挥官", "......嗯。", 60);
PrintConsole(2, " >模块自检完成", 60, true);
PrintConsole(3, " >正在初始化", 60, true);
PrintDialogue("格琳娜", "各模块自检完毕,开始初始化。现在颁布演习任务,", 60);

PrintDialogue("格琳娜", "404小队将在演习中对抗敌机以测试格里芬最新原型机的性能,", 60);
PrintDialogue("格琳娜", "敌机为军方制造的一批仿真铁血机型,", 60);
PrintDialogue("格琳娜", "以下为敌机清单...", 60);
PrintConsole(5, "任务目标:歼灭敌机", 60, false);
PrintConsole(6, "敌方机型:", 30, false);
PrintConsole(7, "Scarecrow", 30, false);
PrintConsole(8, "Executioner", 30, false);
PrintConsole(9, "Hunter", 30, false);
PrintConsole(10, "Disruptor", 30, false);
PrintConsole(11, "Destroyer", 30, false);
PrintConsole(12, "Alchemist", 30, true);

PrintDialogue("指挥官", "收到。", 60);
PrintDialogue("格琳娜", "格里芬的新原型机啊...", 60);
PrintDialogue("格琳娜", "再不加工资的话,咱给它开走拿去卖了。", 60);
PrintDialogue("指挥官", "哈小格,你知道通讯记录是会实时同步到格里芬云端的吧。", 60);
PrintDialogue("格琳娜", "我当然知道。", 60);
PrintDialogue("格琳娜", "嘿嘿老板不给加班费拿人手短,他不会说我什么的。", 60);
PrintDialogue("格琳娜", "不开玩笑了,我看了下清单,这批铁血机型做得很逼真啊。", 60);
PrintDialogue("指挥官", "是的。", 60);

PrintConsole(12, " ", 60, false);
PrintConsole(11, " ", 60, false);
PrintConsole(10, " ", 60, false);
PrintConsole(9, " ", 60, false);
PrintConsole(8, " ", 60, false);
PrintConsole(7, " ", 60, false);
PrintConsole(6, " ", 60, false);
PrintConsole(5, " ", 60, true);
PrintConsole(3, " >初始化完成", 60, true);
PrintConsole(4, " >加载操作模块", 60, true);
PrintDialogue("格琳娜", "好,初始化完成,正在加载操作模块。", 60);
PrintConsole(4, " >操作模块加载完成", 60, true);
PrintDialogue("格琳娜", "加载完成,映射到你的系统上,使用WASD控制原型机。", 60);
SetConsole(0, 0);
AnimMap(0, 40, 0, 32);//行0-19 20 21-40

while (ConsolePlane());
plane.anim = 0;//最后把飞机姿态摆正
plane.preX = plane.x, plane.preY = plane.y;
Clear(plane.preX, plane.preY - 2, 6);
Clear(plane.preX + 1, plane.preY - 2, 6);
Clear(plane.preX + 2, plane.preY - 2, 6);
PrintPlane();

PrintDialogue("格琳娜", "操作模块工作正常,即将载入视觉模块。", 60);
PrintConsole(5, " >加载视觉模块", 60, true);
PrintDialogue("格琳娜", "指挥官,准备好了吗?", 60);
PrintDialogue("指挥官", "呼,", 120);
Print("准备好了。", 60);
Sleep(1000);
PrintConsole(5, " >视觉模块加载完成", 60, false);
BackgroundWhite();
REP(i, 0, 45) {
	SetConsole(i, 0);
	REP(j, 0, 129) {
		cout << " ";
		}
	Sleep(20);
	}
}

///


/// 下面是图形界面部分
///

int runTime;//异步计时器

IMAGE background;//背景图
IMAGE player;
void LoadResource() {
loadimage(&background, _T("./image/background/Background.jpg"));
loadimage(&player, _T("./image/player/Player_Idle.png"));
}

int lastUpdateBackground, backgroundY = 981;
void PrintBackground(int t) {
if (runTime - lastUpdateBackground > t && backgroundY > 0) {
backgroundY--;
lastUpdateBackground = runTime;
}
putimage(0, 0, 1280, 720, &background, 0, backgroundY);
}
//每隔t ms刷新一次

struct

void DrawPlayer(){

}

void InitGraph() {
initgraph(1280, 720, EW_SHOWCONSOLE);
LoadResource();
}
//图形界面(第二章以后)的初始化

void Chapter2() {
InitGraph();
while (1) {
PrintBackground(30);
runTime++;
//printf("%d\n", runTime);
Sleep(1);
}
}

int main() {
Init();
//_getch();

//Chapter1();
Chapter2();


//Handle(FALSE);
//test1();


getchar();
return 0;
}`
posted @ 2021-11-29 19:21  Tony_Double_Sky  阅读(42)  评论(0编辑  收藏  举报