Dev-c++跑酷小游戏 1.0.0

本人六年级小学生第一次发博客,不太好请原谅,程序中会有一些变量没用到,可以删除,会有一些报错不影响运行,部分功能还在学习,暂时没写,以后肯定是会写的

#include
#include
#include
#include
using namespace std;
int a,a1,b,b1,gb,c,d;
int cd1,cd2,tc;
int ax,x1,yy1;
//1.新手教程  2.蹦床世界   3.明枪易躲,暗箭难防   4.明枪易躲,暗箭难防(2)   5.简简单单(隐藏关卡解锁关)  6.刺刺世界(隐藏) 
string mapp1[2][26]={
	{
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"         -----  --  -- - -----                    ",
		"    -                                             ",
		"---- --                                           ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"----^--=                                          ",
		"                                   ---=           ",
		"                                                  ",
		"                                              |-  ",	
		"                                               $  ",
		"                                             ---- ",
		"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
	},
	{
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                               ==^                ",
		"                                      -  --^      ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                                                  ",
		"                              ==^                 ",
		"              --- <                               ",
		"               <                                  ",
		"            ---                                   ", 
		"          --                                      ",
		"        --                                      ^ ",
		"--^ ----               -                      ^ $ ", 
		"                         ----=                >-- ",
		"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
	}  
	};
void sb_ycksbj();

void sb_yd(int x,int y);

void sb_yc();

void g1();

void g2();

void sb_ycksbj()
{
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hStdin,&mode);
	mode&=~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式
	mode&=~ENABLE_INSERT_MODE; //移除插入模式
	mode&=~ENABLE_MOUSE_INPUT;
	SetConsoleMode(hStdin, mode);
}
void sb_yd(int x,int y)  //光标移动到x,y
{
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos;
	pos.X=x;
	pos.Y=y;
	SetConsoleCursorPosition(handle,pos);
}
void sb_yc()
{
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle,&CursorInfo);//获取控制台光标信息
	CursorInfo.bVisible=false; //隐藏控制台光标
	SetConsoleCursorInfo(handle,&CursorInfo);//设置控制台光标状态
}
void g1()
{
	x1=0;yy1=16;
	cout<')
		{
			sb_yd(x1,yy1);
			cout<<" ";
			x1=0;
			yy1=16;
			sb_yd(x1,yy1);
			cout<<"@";
		}
		if(mapp1[0][yy1][x1]=='$')
		{
			_sleep(10);
			system("cls");
			sb_yd(0,0);
			cout<<"你赢了!"<')
		{
			sb_yd(x1,yy1);
			cout<<" ";
			x1=0;
			yy1=21;
			sb_yd(x1,yy1);
			cout<<"@";
		}
		if(mapp1[1][yy1][x1]=='$')
		{
			_sleep(10);
			system("cls");
			sb_yd(0,0);
			cout<<"你赢了!"<

#include
#include
#include
#include
using namespace std;
int a,a1,b,b1,gb,c,d;
int cd1,cd2,tc;
int ax,x1,yy1;
//1.新手教程  2.蹦床世界   3.明枪易躲,暗箭难防   4.明枪易躲,暗箭难防(2)   5.简简单单(隐藏关卡解锁关)  6.刺刺世界(隐藏) 
string mapp1[2][26]={
    {
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "         -----  --  -- - -----                    ",
        "    -                                             ",
        "---- --                                           ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "----^--=                                          ",
        "                                   ---=           ",
        "                                                  ",
        "                                              |-  ",    
        "                                               $  ",
        "                                             ---- ",
        "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    },
    {
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                               ==^                ",
        "                                      -  --^      ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                                                  ",
        "                              ==^                 ",
        "              --- <                               ",
        "               <                                  ",
        "            ---                                   ", 
        "          --                                      ",
        "        --                                      ^ ",
        "--^ ----               -                      ^ $ ", 
        "                         ----=                >-- ",
        "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    }  
    };
void sb_ycksbj();

void sb_yd(int x,int y);

void sb_yc();

void g1();

void g2();

void sb_ycksbj()
{
    HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
    DWORD mode;
    GetConsoleMode(hStdin,&mode);
    mode&=~ENABLE_QUICK_EDIT_MODE; //移除快速编辑模式
    mode&=~ENABLE_INSERT_MODE; //移除插入模式
    mode&=~ENABLE_MOUSE_INPUT;
    SetConsoleMode(hStdin, mode);
}
void sb_yd(int x,int y)  //光标移动到x,y
{
    HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X=x;
    pos.Y=y;
    SetConsoleCursorPosition(handle,pos);
}
void sb_yc()
{
    HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursorInfo;
    GetConsoleCursorInfo(handle,&CursorInfo);//获取控制台光标信息
    CursorInfo.bVisible=false; //隐藏控制台光标
    SetConsoleCursorInfo(handle,&CursorInfo);//设置控制台光标状态
}
void g1()
{
    x1=0;yy1=16;
    cout<     cout<<"\n\n\n\n\n\n\n\n\n                第一关:新手教程。";
    cout<     _sleep(500);
    system("cls");
    for(int i=0;i<24;i++)
    {
        cout<     }
    cout<     sb_yd(x1,yy1);
    cout<<"@";
    for(;;)
    {
        if(kbhit()!=0)
        {
            ax=getch();
            if(ax==224)
            {
                ax=getch();
                if(ax==72)
                {
                    for(int j=1;j<=4;j++)
                    {
                        _sleep(100);
                        if(yy1!=0&&mapp1[0][yy1-1][x1]==' '||mapp1[0][yy1-1][x1]=='$'&&mapp1[0][yy1-1][x1]!='|')
                        {
                            sb_yd(x1,yy1);
                            cout<<" ";
                            yy1--;
                            sb_yd(x1,yy1);
                            cout<<"@";
                            if(kbhit()!=0)
                            {
                                ax=getch();
                                if(ax==224)
                                {
                                    ax=getch();
                                    if(ax==75)
                                    {
                                        if(x1!=0&&mapp1[0][yy1][x1-1]==' '||mapp1[0][yy1][x1-1]=='$'&&mapp1[0][yy1][x1-1]!='|')
                                        {
                                            x1--;
                                            sb_yd(x1,yy1);
                                            cout<<"@ ";
                                        }
                                    }
                                    if(ax==77)
                                    {
                                        if(x1!=49&&mapp1[0][yy1][x1+1]==' '||mapp1[0][yy1][x1+1]=='$'&&mapp1[0][yy1][x1+1]!='|')
                                        {
                                            sb_yd(x1,yy1);
                                            cout<<" @";
                                            x1++;
                                        }
                                    }
                                }
                                if(ax==122||ax==90)
                                {
                                    system("cls");
                                    sb_yd(0,0);
                                    for(int i=0;i<24;i++)
                                    {
                                        cout<                                     }
                                    cout<                                     x1=0;yy1=16;
                                    sb_yd(x1,yy1);
                                    cout<<"@";
                                }
                                
                            } 
                        }
                    }
                }
                if(ax==75)
                {
                    if(x1!=0&&mapp1[0][yy1][x1-1]==' '||mapp1[0][yy1][x1-1]=='$'&&mapp1[0][yy1][x1-1]!='|')
                    {
                        x1--;
                        sb_yd(x1,yy1);
                        cout<<"@ ";
                    }
                }
                if(ax==77)
                {
                    if(x1!=49&&mapp1[0][yy1][x1+1]==' '||mapp1[0][yy1][x1+1]=='$'&&mapp1[0][yy1][x1+1]!='|')
                    {
                        sb_yd(x1,yy1);
                        cout<<" @";
                        x1++;
                    }
                }
            }
            if(ax==122||ax==90)
            {
                system("cls");
                sb_yd(0,0);
                for(int i=0;i<24;i++)
                {
                    cout<                 }
                cout<                 x1=0;yy1=16;
                sb_yd(x1,yy1);
                cout<<"@";
            }
        }
         while(mapp1[0][yy1+1][x1]==' '||mapp1[0][yy1+1][x1]=='$')
        {
            _sleep(100);
             sb_yd(x1,yy1);
            cout<<" ";
            yy1+=1;
             sb_yd(x1,yy1);
             cout<<"@";
             if(kbhit()!=0)
            {
                ax=getch();
                if(ax==224)
                {
                    ax=getch();
                    if(ax==75)
                    {
                        if(x1!=0&&mapp1[0][yy1][x1-1]==' '||mapp1[0][yy1][x1-1]=='$'&&mapp1[0][yy1][x1-1]!='|')
                        {
                            x1--;
                            sb_yd(x1,yy1);
                            cout<<"@ ";
                        }
                    }
                    if(ax==77)
                    {
                        if(x1!=49&&mapp1[0][yy1][x1+1]==' '||mapp1[0][yy1][x1+1]=='$'&&mapp1[0][yy1][x1+1]!='|')
                        {
                            sb_yd(x1,yy1);
                            cout<<" @";
                            x1++;
                        }
                    }
                }
                if(ax==122||ax==90)
                {
                    system("cls");
                    sb_yd(0,0);
                    for(int i=0;i<24;i++)
                    {
                        cout<                     }
                    cout<                     x1=0;yy1=16;
                    sb_yd(x1,yy1);
                    cout<<"@";
                }
            } 
        } 
        if(mapp1[0][yy1+1][x1]=='=')
         {
             int jc=1;
            for(int j=1;j<=8;j++)
             {
                 if(mapp1[0][yy1-1][x1]==' ')
                 {
                     _sleep(10);
                    sb_yd(x1,yy1);
                    cout<<" ";
                    yy1--;
                    sb_yd(x1,yy1);
                    cout<<"@";
                    if(kbhit()!=0)
                    {
                        ax=getch();
                        if(ax==224)
                        {
                            ax=getch();
                            if(ax==75)
                            {
                                if(x1!=0&&mapp1[0][yy1][x1-1]==' '||mapp1[0][yy1][x1-1]=='$'&&mapp1[0][yy1][x1-1]!='|')
                                {
                                    x1--;
                                    sb_yd(x1,yy1);
                                    cout<<"@ ";
                                }
                            }
                            if(ax==77)
                            {
                                if(x1!=49&&mapp1[0][yy1][x1+1]==' '||mapp1[0][yy1][x1+1]=='$'&&mapp1[0][yy1][x1+1]!='|')
                                {
                                    sb_yd(x1,yy1);
                                    cout<<" @";
                                    x1++;
                                }
                            }
                        }
                        if(ax==122||ax==90)
                        {
                            system("cls");
                            sb_yd(0,0);
                            for(int i=0;i<24;i++)
                            {
                                cout<                             }
                            cout<                             x1=0;yy1=16;
                            sb_yd(x1,yy1);
                            cout<<"@";
                        }
                    } 
                }
            } 
        }    
        if(mapp1[0][yy1+1][x1]=='^'||mapp1[0][yy1][x1+1]=='<'||mapp1[0][yy1][x1-1]=='>')
        {
            sb_yd(x1,yy1);
            cout<<" ";
            x1=0;
            yy1=16;
            sb_yd(x1,yy1);
            cout<<"@";
        }
        if(mapp1[0][yy1][x1]=='$')
        {
            _sleep(10);
            system("cls");
            sb_yd(0,0);
            cout<<"你赢了!"<             cout<<"按空格返回。";
            if(getch()==' ')
            {
                system("cls");
                sb_yd(0,0);
                return;
            }
        }
    }
}
void g2()
{
    x1=0;yy1=21;
    cout<     cout<<"\n\n\n\n\n\n\n\n\n                第二关:蹦床世界。"<     cout<     _sleep(500);
    system("cls");
    for(int i=0;i<24;i++)
    {
        cout<     }
    cout<     sb_yd(x1,yy1);
    cout<<"@";
    for(;;)
    {
        if(kbhit()!=0)
        {
            ax=getch();
            if(ax==224)
            {
                ax=getch();
                if(ax==72)
                {
                    for(int j=1;j<=4;j++)
                    {
                        _sleep(100);
                        if(yy1!=0&&mapp1[1][yy1-1][x1]==' '||mapp1[1][yy1-1][x1]=='$'&&mapp1[1][yy1-1][x1]!='|')
                        {
                            sb_yd(x1,yy1);
                            cout<<" ";
                            yy1--;
                            sb_yd(x1,yy1);
                            cout<<"@";
                            if(kbhit()!=0)
                            {
                                ax=getch();
                                if(ax==224)
                                {
                                    ax=getch();
                                    if(ax==75)
                                    {
                                        if(x1!=0&&mapp1[1][yy1][x1-1]==' '||mapp1[1][yy1][x1-1]=='$'&&mapp1[1][yy1][x1-1]!='|')
                                        {
                                            x1--;
                                            sb_yd(x1,yy1);
                                            cout<<"@ ";
                                        }
                                    }
                                    if(ax==77)
                                    {
                                        if(x1!=49&&mapp1[1][yy1][x1+1]==' '||mapp1[1][yy1][x1+1]=='$'&&mapp1[1][yy1][x1+1]!='|')
                                        {
                                            sb_yd(x1,yy1);
                                            cout<<" @";
                                            x1++;
                                        }
                                    }
                                }
                                if(ax==122||ax==90)
                                {
                                    system("cls");
                                    sb_yd(0,0);
                                    for(int i=0;i<24;i++)
                                    {
                                        cout<                                     }
                                    cout<                                     x1=0;yy1=21;
                                    sb_yd(x1,yy1);
                                    cout<<"@";
                                }
                            } 
                        }
                    }
                }
                if(ax==75)
                {
                    if(x1!=0&&mapp1[1][yy1][x1-1]==' '||mapp1[1][yy1][x1-1]=='$'&&mapp1[1][yy1][x1-1]!='|')
                    {
                        x1--;
                        sb_yd(x1,yy1);
                        cout<<"@ ";
                    }
                }
                if(ax==77)
                {
                    if(x1!=49&&mapp1[1][yy1][x1+1]==' '||mapp1[1][yy1][x1+1]=='$'&&mapp1[1][yy1][x1+1]!='|')
                    {
                        sb_yd(x1,yy1);
                        cout<<" @";
                        x1++;
                    }
                }
            }
            if(ax==122||ax==90)
            {
                system("cls");
                sb_yd(0,0);
                for(int i=0;i<24;i++)
                {
                    cout<                 }
                cout<                 x1=0;yy1=21;
                sb_yd(x1,yy1);
                cout<<"@";
            }
        }
         while(mapp1[1][yy1+1][x1]==' '||mapp1[1][yy1+1][x1]=='&')
        {
            _sleep(100);
             sb_yd(x1,yy1);
            cout<<" ";
            yy1+=1;
             sb_yd(x1,yy1);
             cout<<"@";
             if(kbhit()!=0)
            {
                ax=getch();
                if(ax==224)
                {
                    ax=getch();
                    if(ax==75)
                    {
                        if(x1!=0&&mapp1[1][yy1][x1-1]==' '||mapp1[1][yy1][x1-1]=='$'&&mapp1[1][yy1][x1-1]!='|')
                        {
                            x1--;
                            sb_yd(x1,yy1);
                            cout<<"@ ";
                        }
                    }
                    if(ax==77)
                    {
                        if(x1!=49&&mapp1[1][yy1][x1+1]==' '||mapp1[1][yy1][x1+1]=='$'&&mapp1[1][yy1][x1+1]!='|')
                        {
                            sb_yd(x1,yy1);
                            cout<<" @";
                            x1++;
                        }
                    }
                }
                if(ax==122||ax==90)
                {
                    system("cls");
                    sb_yd(0,0);
                    for(int i=0;i<24;i++)
                    {
                        cout<                     }
                    cout<                     x1=0;yy1=21;
                    sb_yd(x1,yy1);
                    cout<<"@";
                }
            } 
        } 
        if(mapp1[1][yy1+1][x1]=='=')
         {
            for(int j=1;j<=8;j++)
             {
                 if(mapp1[1][yy1-1][x1]==' ')
                 {
                     _sleep(10);
                    sb_yd(x1,yy1);
                    cout<<" ";
                    yy1--;
                    sb_yd(x1,yy1);
                    cout<<"@";
                    if(kbhit()!=0)
                    {
                        ax=getch();
                        if(ax==224)
                        {
                            ax=getch();
                            if(ax==75)
                            {
                                if(x1!=0&&mapp1[1][yy1][x1-1]==' '||mapp1[1][yy1][x1-1]=='$'&&mapp1[1][yy1][x1-1]!='|')
                                {
                                    x1--;
                                    sb_yd(x1,yy1);
                                    cout<<"@ ";
                                }
                            }
                            if(ax==77)
                            {
                                if(x1!=49&&mapp1[1][yy1][x1+1]==' '||mapp1[1][yy1][x1+1]=='$'&&mapp1[1][yy1][x1+1]!='|')
                                {
                                    sb_yd(x1,yy1);
                                    cout<<" @";
                                    x1++;
                                }
                            }
                        }
                        if(ax==122||ax==90)
                        {
                            system("cls");
                            sb_yd(0,0);
                            for(int i=0;i<24;i++)
                            {
                                cout<                             }
                            cout<                             x1=0;yy1=21;
                            sb_yd(x1,yy1);
                            cout<<"@";
                        }
                    } 
                }
            } 
        }    
        if(mapp1[1][yy1+1][x1]=='^'||mapp1[1][yy1][x1+1]=='<'||mapp1[1][yy1][x1-1]=='>')
        {
            sb_yd(x1,yy1);
            cout<<" ";
            x1=0;
            yy1=21;
            sb_yd(x1,yy1);
            cout<<"@";
        }
        if(mapp1[1][yy1][x1]=='$')
        {
            _sleep(10);
            system("cls");
            sb_yd(0,0);
            cout<<"你赢了!"<             cout<<"按空格返回。";
            if(getch()==' ')
            {
                system("cls");
                sb_yd(0,0);
                return;
            }
        }
    }
}
int hy()
{
    if(c==0)
    {
        cout<<"\n\n\n\n\n\n\n\n\n\n\n\n=======================欢迎======================="<         c++;
        _sleep(1000);
        system("cls");
    }
    cout<<"\n\n\n\n\n\n\n                       首页\n\n\n\n\n";
    cout<<"                     1.开始游戏\n\n\n\n";
    cout<<"                      2.退出";
    a=0;
    a=getch()-'0';
    return a;
}
void gq()

    for(;;) 
    {
        cout<<"\n\n\n\n\n\n                        关卡\n\n\n\n\n"<         cout<<"              1.新手教程   2.蹦床世界\n\n\n\n"<         cout<<"                      3.退出";
        a=getch()-'0';
        switch(a)
        {
            case 1 :
            {
                system("cls");
                g1();    
                break;    
            }
            case 2 :
            {
                system("cls");
                g2();    
                break;    
            }
            case 3 :
            {
                system("cls");
                tc=1;
                break;    
            }
        }
        if(tc==1)
        {
            tc=0;
            break;
        }
    }
    system("cls");
    return ;
}
int main()
{
    sb_ycksbj();
    sb_yc();
    system("title 跑酷游戏");
    system("mode con cols=50 lines=25");
    for(;;)
    {
        hy();
        if(a==1||a==2)
        {
        if(a==1)
        {
            system("cls");
            gq();
        }
        if(a==2)
        {
                system("cls");
                cout<                 _sleep(750);
                system("cls");
                exit(0);
        }
        }
        else
        {
            system("cls");
            cout<<"\n\n\n\n\n\n\n\n\n\n\n\n             请输入正确的字符!!!";
            system("cls");
            continue;
        }
    }
}

你可能感兴趣的:(c++,单片机,stm32)