我回来了欧

我又回来了我要给大家发一个经典游戏代码

1.马里奥

#include

#include

#include

using namespace std;

#define Y 20

#define X 80

#define K 17

short Map[Y][X]={

{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},

{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7},

{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7},

{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7},

{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7},

{7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,9,6,4,7},

{7,7,7,7,7,7,7,7,7,7,7,4,4,4,7,7,7,7,7,4,4,4,4,4,4,4,4,4,4,4,4,4,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},

};

int px,py,ps;

char c;

void color(int a);

void gotoxy(int i,int j);

void start();

void csh();

void drawmap(int k);

void draw_player();

void cls_player();

void _cin();

void _k(int x,int y);

int main(){

    start();csh();drawmap(px-5);draw_player();

    while(true){

        _cin();

        if(ps==K&&Map[py][px]==9){system("cls");gotoxy(9,38);color(14);printf("Win!\n");break;}

        if(Map[py][px]==4||Map[py+1][px]==4){system("cls");gotoxy(9,35);color(4);printf("Game over!\n");break;}

        _sleep(10);

    }

    while(c=getch()){}

    return 0;

}

void color(int a){

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);

    return;

}

void gotoxy(int i,int j){

    COORD position={j,i};SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),position);

    return;

}

void start(){

    CONSOLE_CURSOR_INFO cursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

    color(1);gotoxy(8,36);printf("超");_sleep(250);color(4);gotoxy(8,38);printf("级");_sleep(250);color(3);gotoxy(8,40);printf("马");_sleep(250);color(14);gotoxy(8,42);printf("丽");_sleep(250);

    color(7);gotoxy(10,31);printf("游戏加载中…");_sleep(500);for(int q=0;q<3;q++)for(int w=0;w<4;w++){gotoxy(10,41+w*2);printf("…      ");_sleep(500);}

    system("cls");string s="游戏规则:\n\nw,a,s,d控制小人移动(跳跃时先按w,再按a或d)\n\n碰到尖刺死亡\n\n捡到所有金币并且走到终点获胜"; for(int i=0;i

#include

#include

#include

using namespace std;

#define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0,0,0,0,0,0,0,0,0,0,0,7,9,6,4,7},

{7,7,7,7,7,7,7,7,7,7,7,4,4,4,7,7,7,7,7,4,4,4,4,4,4,4,4,4,4,4,4,4,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},

};

int px,py,ps;

char c;

void color(int a);

void gotoxy(int i,int j);

void start();

void csh();

void drawmap(int k);

void draw_player();

void cls_player();

void _cin();

void _k(int x,int y);

int main(){

    start();csh();drawmap(px-5);draw_player();

    while(true){

        _cin();

        if(ps==K&&Map[py][px]==9){system("cls");gotoxy(9,38);color(14);printf("Win!\n");break;}

        if(Map[py][px]==4||Map[py+1][px]==4){system("cls");gotoxy(9,35);color(4);printf("Game over!\n");break;}

        _sleep(10);

    }

    while(c=getch()){}

    return 0;

}

void color(int a){

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);

    return;

}

void gotoxy(int i,int j){

    COORD position={j,i};SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),position);

    return;

}

void start(){

    CONSOLE_CURSOR_INFO cursor_info={1,0};SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);

    color(1);gotoxy(8,36);printf("超");_sleep(250);color(4);gotoxy(8,38);printf("级");_sleep(250);color(3);gotoxy(8,40);printf("马");_sleep(250);color(14);gotoxy(8,42);printf("丽");_sleep(250);

    color(7);gotoxy(10,31);printf("游戏加载中…");_sleep(500);for(int q=0;q<3;q++)for(int w=0;w<4;w++){gotoxy(10,41+w*2);printf("…      ");_sleep(500);}

    system("cls");string s="游戏规则:\n\nw,a,s,d控制小人移动(跳跃时先按w,再按a或d)\n\n碰到尖刺死亡\n\n捡到所有金币并且走到终点获胜"; for(int i=0;i

    return;

}

void csh(){

    px=5;py=18;ps=0;

    return;

}

void drawmap(int k){

    if(k<0)k=0;

    for(int y=0;y

        for(int x=0;x<40;x++){

            if(x+k<80){

                gotoxy(y,x*2);

                switch(Map[y][x+k]){ 

                    case 9:color(3);printf("终");break; 

                    case 7:color(7);printf("■");break;

                    case 6:color(14);printf("●");break;

                    case 4:color(4);printf("▲");break;

                    case 0:printf("  ");break;

                }

            }

        }

    }

    return;

}

void draw_player(){

    if(px<=5)gotoxy(py,px*2);else gotoxy(py,10);color(14);printf("♀");

    return;

}

void cls_player(){

    if(px<=5)gotoxy(py,px*2);else gotoxy(py,10);printf("  ");

    return;

}

void _cin(){

    if(kbhit()!=0){

        while(kbhit()!=0)c=getch();

        switch(c){

            case 'a':case 'A':{if(Map[py][px-1]!=7)px--;_k(px,py);break;}

            case 'd':case 'D':{if(Map[py][px+1]!=7)px++;_k(px,py);break;}

            case 'w':case 'W':{int l=0;for(int i=0;i<5&&Map[py-1][px]!=7&&Map[py-1][px]!=4;i++){l++;cls_player();py--;_k(px,py);draw_player();_cin();_sleep(50);}for(int i=0;i

            case 's':case 'S':{px=5;py=18;break;}

        }

        drawmap(px-5);draw_player();while(Map[py+1][px]!=7&&Map[py+1][px]!=4){cls_player();py++;_k(px,py);draw_player();_cin();_sleep(50);}    

    }

    return;

}

void _k(int x,int y){

    if(Map[y][x]==6){ps++;Map[y][x]=0;}

    return;

}

没登录的也能玩

你可能感兴趣的:(c++,开发语言)