游戏模板C++(控制台)

37 篇文章 2 订阅
#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 bukakeqingping(){
    gotoxy(0,0);
    for (int i = 0; i < 70; i++) {
        cout << "                                                                                                        " << endl;
    }
    gotoxy(0,0);
}
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);
}
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 = 1,bool truefalse3 = 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(truefalse0 ==100){
            Sleep(1);
        }
    }
    if(truefalse1!=false){
        cout << endl;
    }
    if(truefalse3!=false){
        getch();
        bukakeqingping();
    }
}
void ksjm()
{
	system("color f0");
	cout<<"按任意键开始游戏";
	getch();
	system("cls"); 
	for(long long i=1;i<=3;i++)
	{
		system("color 07");
		system("color 10");
		system("color 20");
		system("color 30");
		system("color 40");
		system("color 50");
		system("color 60");
		system("color 70");
		system("color 80");
		system("color 90");
		system("color a0");
		system("color b0");
		system("color c0");
		system("color d0");
		system("color e0");
		system("color f0");
	}
	cout<<"\n\n\n\n\n\n\n\n\n\n\n                                                      ";
	coutAIO("游戏名",2);
	cout<<"\n";
	cout<<"                                                   ";
	coutAIO("出品:imX2G",5);
	Sleep(1500);
} 
int start()
{
	system("cls");
	cout << "□□□□□□■□□□□□□□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□■■□□□□□□□□□□□□□□□□□■□□" << endl;
	cout << "□□□□□□■■■□□□□□□□□□□□□□□□■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■□□□□■■■■□□" << endl;
	cout << "□□■□■□■□■□■□■□■□■□■■■■■■■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■■■■■■■■□□□" << endl;
	cout << "□□□□□□□□■■■■■□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□■■■□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□□■■■□□□□□□□□□□□□" << endl;
	coutAIO("一天,你坐着飞机,正打算去美国...",3);
	Sleep(1000);
	bukakeqingping();
	cout << "□□□□□□■□□□□□□□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□■■□□□□□□□□□□□□□□□□□■□□" << endl;
	cout << "□□□□□□■■■□□□□□□□□□□□□□□□■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■□□□□■■■■□□" << endl;
	cout << "□□■□■□■□■□■□■□■□■□■■■■■■■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■■■■■■■■□□□" << endl;
	cout << "□□□□□□□□■■■■■□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□■■■□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□□■■■□□□□□□□□□□□□" << endl;
	coutAIO("一边看着电影,一边喝着饮料",3);
	Sleep(1000);
	bukakeqingping();
	cout << "□□□□□□■□□□□□□□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□■■□□□□□□□□□□□□□□□□□■□□" << endl;
	cout << "□□□□□□■■■□□□□□□□□□□□□□□□■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■□□□□■■■■□□" << endl;
	cout << "□□■□■□■□■□■□■□■□■□■■■■■■■■□□" << endl;
	cout << "□□□■■■■■■■■■■■■■■■■■■■■■■□□□" << endl;
	cout << "□□□□□□□□■■■■■□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□■■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□■■■□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□□■■■□□□□□□□□□□□□" << endl;
	coutAIO("突然,飞机开始颠簸,你手中饮料摔到了地上,洒了一地",3);
	Sleep(1000);
	system("cls");
	cout << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□■■■■□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■■■■□□□□□□□□□□□" << endl;
	cout << "□□□□■■■■■■□□■■□□■■■■■■□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■■■■□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□■■■■■■□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□" << endl;
	coutAIO("一秒钟后,飞机开始往下坠落",3);
	Sleep(1000);
	bukakeqingping();
	cout << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□■■■■□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■■■■□□□□□□□□□□□" << endl;
	cout << "□□□□■■■■■■□□■■□□■■■■■■□□□□□□" << endl;
	cout << "□□□□□□□□□■■■■■■■■□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□■■■■■■□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□■■□□□□□□□□□□□□□□" << endl;
	cout << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□" << endl;
	coutAIO("行李架上的行李掉了下来,砸中了你,你眼前一黑,昏了过去...",3);
	Sleep(1000);
	bukakeqingping();
	Sleep(3000);
	cout<<"                                                                         ";
	coutAIO("醒来后,",5,0);
	coutAIO("你发现你穿越了,进入了未知地域。",2);
	getch();
	return 0;
}
void start(int n)
{
    int g=n;
	system("cls");
    Sleep(1000);
    gotoxy(0,0);
	for (int i=1;i<=n; i++)
	{
		for (int i=1;i<=g; i++)
	    {
		    coutAIO("▓▓▓",0,0);
	    }
	    cout<<endl;
	}
	coutAIO("华丽!!",4);
    Sleep(5000);
    system("cls");
    Sleep(5000);
    ksjm();
    start();
}
void welcome()
{
	color(6);
	gotoxy(20,40);
	coutAIO("      游     戏     名 ",3);
	gotoxy(21,40);
	coutAIO("     you     xi    ming",3);
	Sleep(2000);
	gotoxy(23,40);
	coutAIO("H E P P Y",3);
	Sleep(200);
	gotoxy(24,40);
	coutAIO("    i m X 2 G",3);
	Sleep(1000);
	color(3);
	gotoxy(25,45);
	cout<<"imX2G出品,必是精品!\n";
	Sleep(2000);
	color(2);
	system("cls");
	start(60);
	gotoxy(0,60);
	system("cls");
	cout<<"\t\t\t\t\t\tv.1.0.0"; 
	gotoxy(0,0);
	printf("    WELCOME                                                        WELCOME    \n");
	printf("┌──────────────────────────────────────────────────────────────────────────────────────────┐\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│                                                                                          │\n");
	printf("│卍                                                                                      卐│\n");
	printf("│卍卍                                                                                  卐卐│\n");
	printf("│卍卍卍                                                                              卐卐卐│\n");
	printf("│卍卍卍卍                                                                          卐卐卐卐│\n");
	printf("└──────────────────────────────────────────────────────────────────────────────────────────┘\n");
	gotoxy(2,2);
	coutAIO("欢迎来到游戏                    欢迎来到游戏                     欢迎来到游戏    ");
	gotoxy(3,2);
	coutAIO("作者:imX2G                      作者:imX2G                      作者:imX2G    ");
	gotoxy(4,2);
	coutAIO("祝您游戏愉快                    祝您游戏愉快                     祝您游戏愉快    ");
	gotoxy(5,2);
	coutAIO("(*^_^*)                         (*^_^*)                          (*^_^*)         ");
	gotoxy(6,2);
	coutAIO("欢迎来到游戏                    欢迎来到游戏                     欢迎来到游戏    ");
	gotoxy(7,2);
	coutAIO("作者:imX2G                      作者:imX2G                      作者:imX2G    ");
	gotoxy(8,2);
	coutAIO("祝您游戏愉快                    祝您游戏愉快                     祝您游戏愉快    ");
	gotoxy(9,2);
	coutAIO("(*^_^*)                         (*^_^*)                          (*^_^*)         ");
	gotoxy(10,2);
	coutAIO("欢迎来到游戏                    欢迎来到游戏                     欢迎来到游戏    ");
	gotoxy(11,2);
	coutAIO("作者:imX2G                      作者:imX2G                      作者:imX2G    ");
	gotoxy(12,2);
	coutAIO("祝您游戏愉快                    祝您游戏愉快                     祝您游戏愉快    ");
	gotoxy(13,2);
	coutAIO("(*^_^*)                         (*^_^*)                          (*^_^*)         ");
	getch();
}
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);
}
int main()
{
    //full_screen();
    welcome();
    gotoxy(27,2);
    return 0;
}


祝您游戏愉快!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值