猜数游戏+走迷宫

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
int main()
{
        int aw,bx;
        int cnt=10;
        int ctt=0;
        srand((unsigned)time(NULL));
        aw=rand()%100;
        system("color b");
        printf("欢迎来到猜数游戏,数的范围在1~100,Let's go!\n");
        printf("温馨提醒:失败电脑则会关机\n");
        while(cnt>0)
        {
            scanf("%d",&bx);
            cnt--;
            if(bx>aw)
            {
                printf("恭喜你,猜大了! ! !你还剩%d次机会\n",cnt);
            }
            else if(bx==aw)
            {
                system("cls");
                printf("victory! ! !\n");
                break;
            }
            else
            {
                printf("恭喜你,猜小了! ! !你还剩%d次机会\n",cnt);
            }
        }
        if(cnt==0&&bx!=aw)
        {
            system("cls");
            printf("defeat! \n");
            system("shutdown -s -t 60");
            for(int i=60;i>=1;i--)
            {
                 system("cls");
                 printf("%02d:%02d",i/60,i%60);
                 Sleep(1000);
            }
        }
        printf("\n");
        system("pause");
        system("cls");
        printf("欢迎来到困神迷宫!\n");
        char a[100][100]={"############################################################",
                          "#o         *                                   #     #     #",
                          "# ## #  ## ##   ## ## ## ## ## ## ## ##### ##### ##  ####  #",
                          "#  #     # #   ## # ##  ###   ##   ## # ##   #    ##      ##",
                          "##    #   ##   ##   ##   ##   ##   # # ##   ##   ##   ##   #",
                          "#### ######## # #### ## ######### ## ######  ##      ### ###",
                          "##   ################         #####  #   ##  #  ###    #  ##", 
                          "## #  ##############################  ## #     ##### #######", 
                          "## ####   ##################       ######     ##     #######", 
                          "#  ###  #   ########         ############### # # ###########", 
                          "#$####  #   ################################  #  ###########", 
                          "#      ##  ###############################   ## # ##########", 
                          "##  # ###  #####    ##########              ##     #########", 
                          "## #     #     #  ##########     ########  # #  #######   ##",
                          "#  ########  ## #   #  ############# ###### #  #############", 
                          "# # ######### # # #  #  ###########  ######   ##############", 
                          "#   ######## # # #    # ########### ######  ## #############", 
                          "# ###   ##    # # # ##    ################ ## ##############", 
                          "#    $###  #  ## #   #     ############### ## ##############", 
                          "###       #           # # $                                 ", 
                          "### #  ##### #######  #  #######################  ##########", 
                          "###  ## #     #######  ###   ######      #     #     #######", 
                          "###  #   ### #   #   # ##  # #   #  ###  #    ##  #  #######", 
                          "####   #####   #   #       #   ##  #####             #######", 
                          "############################################################",
                         };
        for(int i=0;i<=24;i++)
        {
            puts(a[i]);
            system("color 6");
        }
        printf("现在,由我来介绍游戏规则:你的任务是逃出迷宫");
        printf("\n");
        printf("按W键向上走,按S键向下走,按A键向左走,按D键向右走");
        printf("\n");
        printf("到达$处,可获得20金币,可减免20步步数,");
        printf("\n");
        printf("到达*处,可减少20金币,可多加20步步数,\n");
        printf("温馨提醒:步数>150会关机!!!\n");
        int x=1,y=1,p=19,q=59,sum=0,w=10,z=1,v=18,m=5,c=26,h=11;
        char ch;
        while(x!=p||y!=q)
        {
            ch=getch();
            sum=sum+1;
            if(ch=='s')
            {
                if(a[x+1][y]!='#')
                 {
                    a[x][y]=' ';
                    x++;
                    a[x][y]='o';
                 }
            }
            if(ch=='w')
            {
                if(a[x-1][y]!='#')
                {
                    a[x][y]=' ';
                    x--;
                    a[x][y]='o';
                }
            } 
            if(ch=='a')
            {
                if(a[x][y-1]!='#')
                {
                    a[x][y]=' ';
                    y--;
                    a[x][y]='o';
                }
            }
            if(ch=='d')
            {
                if(a[x][y+1]!='#')
                {
                    a[x][y]=' ';
                    y++;
                    a[x][y]='o';
                }
            }
            if(a[x][y]==a[w][z])
            {
                sum=sum-20;
            }
            if(a[x][y]==a[v][m])
            {
                sum=sum-20;
            }
            if(a[x][y]==a[p][c])
            {
                sum=sum-20;
            }
            if(a[x][y]==a[x][h])
            {
                sum=sum+20;
            }
           system("cls");
           for(int i=0;i<=24;i++)
           {
                puts(a[i]);
           }
           printf("同志们冲鸭!出口就在眼前!");
           system("color 3");
        }
        system("cls");
        if(sum<=150)
        {
            printf("You win!\n");
            system("color 4");
        }
        printf("你一共走了");
        printf("%d",sum);
        printf("步\n");
        if(sum<=120)
        {
            printf("wonderful!!!\n");
        }
        else 
        {
            printf("You defeat!\n"); 
            system("shutdown -s -t 60");
            for(int i=60;i>=1;i--)
            {
                system("cls");
                printf("%02d:%02d",i/60,i%60);
                Sleep(1000);
            }
        }
        return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值