我看了饼干的b_game.h感觉很棒,于是我爆肝写出了这个代码:
#ifndef coutAIO_H
#define coutAIO_H
#include <iostream>
#include<windows.h>
#include<conio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<fstream>
using namespace std;
void gotoxy(int y, int x)
{
COORD coord;
coord.X = x;
coord.Y = y;
HANDLE a = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a, coord);
}
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);
/*土黄色or金黄色*/ if (a == 7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN);
/*灰色接近白*/ if (a == 8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
void bukakeqingping(){
gotoxy(0, 0);
for (int i = 0; i < 70; i++) {
cout << " " << endl;
}
gotoxy(0, 0);
}
template<typename o>
void swap(o &a, o &b){
o temp = a;
a = b;
b = temp;
}
long long numberaio(string n){
for (int i = 0; i < 100000; i++) {
if (n[i] == '\0')
{
return i;
}
}
}
void coutAIO(string b, int truefalse0 = 1, bool truefalse1 = 0){
int i = 0, s = 0;
long long a = numberaio(b);
while (a != 0){
s = rand() % 9;
if (a != 0 && s == 0)
{
color(0);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 1)
{
color(1);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 2)
{
color(2);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 3)
{
color(3);
cout << b[i];
a--;
i++;
if (truefalse0 != false){
Sleep(20);
}
}
if (a != 0 && s == 4)
{
color(4);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 5)
{
color(5);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 6)
{
color(6);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 7)
{
color(7);
cout << b[i];
a--;
i++;
}
if (a != 0 && s == 8)
{
color(8);
cout << b[i];
a--;
i++;
}
if (truefalse0 == 1){
Sleep(10);
}
if (truefalse0 == 2){
Sleep(20);
}
if (truefalse0 == 3){
Sleep(40);
}
if (truefalse0 == 4){
Sleep(100);
}
if (truefalse0 == 5){
Sleep(300);
}
if (truefalse0 == 6){
Sleep(1000);
}
}
if (truefalse1 == 0){
cout << endl;
}
}
void full_screen()
{
HWND hwnd = GetForegroundWindow();
int cx = GetSystemMetrics(SM_CXSCREEN); /* 屏幕宽度 像素 */
int cy = GetSystemMetrics(SM_CYSCREEN); /* 屏幕高度 像素 */
LONG l_WinStyle = GetWindowLong(hwnd, GWL_STYLE); /* 获取窗口信息 */
/* 设置窗口信息 最大化 取消标题栏及边框 */
//SetWindowLong(hwnd,GWL_STYLE,( l_WinStyle |WS_MAXIMIZE| WS_POPUP) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER);//
SetWindowPos(hwnd, HWND_TOP, 0, 0, cx, cy, 0);
}
#endif