小游戏“盗宝奇侠”

//今天去学校看舞林大会了~~HB组合的哥哥们好妖娆好帅!~~沫沫打~~~~~~~~~~
//编写小游戏"盗宝奇侠"程序,2.在藏宝区入口处有一"奇侠"@。按键可操作@的移动。按键功能如下:
// l右移
// j左移
// i爬梯
// k向下打洞、下跳
// p向右平跳
// 注:当@踩空时会掉到地面上。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <windows.h>
void gotoxy(int x, int y);
char b[25][60]={ 
 {"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"},
 {"┃                                                          "},
 {"┃                                       ┏┓****    *****┃"},
 {"┃                                       ┣┫***      ****┃"},
 {"┃                                       ┣┫***      ****┃"},
 {"┃                                       ┣┫***      ****┃"},
 {"┃                                       ┣┫***      ****┃"},
 {"┃                     ┏┳     **************************┃"},
 {"┃                 ****┣┫       ************************┃"},
 {"┃                 ****┣┫              ****          ***┃"},
 {"┃                 ****┣┫              ****          ***┃"},
 {"┃                 ****┣┫              ****          ***┃"},
 {"┃                 ****┣┫              ****   $      ***┃"},
 {"┃                 ************* ┳┳  *******************┃"},
 {"┃       ┏┓******************* ┣┫  *******************┃"},
 {"┃       ┣┫*********           ┣┫                  ***┃"},
 {"┃       ┣┫****                ┣┫                  ***┃"},
 {"┃       ┣┫****                ┣┫                  ***┃"},
 {"         ┣┫****      $         ┣┫       $          ***┃"},
 {"┃********************************************************┃"},
 {"┃********************************************************┃"},
 {"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"}};
void  main()
{
   int x, y, k;
   int bi=0, bj=0, i, j;
   int px=0, py=18;
   char ch;
   for(i=0; i<25; i++)
   {
      gotoxy(bi, bj++);
   for(j=0; j<60; j++)
    printf("%c", b[i][j]);
   }
   gotoxy(px,py);
   printf("@");
   while(1)
   {    
    k=_kbhit();
    if(k)
    {
        ch=_getch();
     if(ch=='j'&&px>0)
     {
      if(b[py][px-1]==' '||b[py][px-1]=='$')
      {
      gotoxy(px, py);
      printf(" ");
      px--;
      gotoxy(px, py);
      printf("@");    
      }
      while(b[py+1][px]==' ')
      {
         gotoxy(px,py);
      printf(" ");
      py++;
      gotoxy(px,py);
      printf("@");
      Sleep(50);
      }
      continue;
     }
     if(ch=='l'&&px<57)
     {
      if(b[py][px+1]==' '||b[py][px+1]=='$')
      {
         gotoxy(px, py);
      printf(" ");
      px++;
      gotoxy(px, py);
      printf("@");
      }
      while(b[py+1][px]==' ')
      {
         gotoxy(px,py);
      printf(" ");
      py++;
      gotoxy(px,py);
      printf("@");
      Sleep(50);
      }
      continue;
     }
     if(ch=='p')
     {
         while(b[py][px+1]==' ')
      {
         gotoxy(px,py);
      printf(" ");
      px++;
      gotoxy(px,py);
      printf("@");
      Sleep(50);
      }
      continue;
     }
     if(ch=='k'&&py<20)
     {
        gotoxy(px, py);
     printf(" ");
     py++;
     gotoxy(px, py);
     printf("@");
     while(b[py+1][px]==' ')
      {
         gotoxy(px,py);
      printf(" ");
      py++;
      gotoxy(px,py);
      printf("@");
      Sleep(50);
      }
     continue;
     }
     if(ch=='i')
     {
      if(b[py-1][px]==' '&&((b[py][px+1]!=' '&&b[py][px+1]!='*'&&b[py][px+1]!='$')||(b[py][px-1]!=' '&&b[py][px-1]!='*'&&b[py][px-1]!='$')))
      {
          gotoxy(px,py);
       printf(" ");
       py--;
       gotoxy(px, py);
       printf("@");
      }
      continue;
     }
    break;
    }
   }
   system("cls");
   gotoxy(40, 12);
   printf("you lost\n");
   getchar();
}
void gotoxy(int x, int y) //定位到第y行的第x列
{    
 int xx=0x0b;    
 HANDLE hOutput;    
 COORD loc;    
 loc.X=x;    
 loc.Y=y;    
 hOutput = GetStdHandle(STD_OUTPUT_HANDLE);    
 SetConsoleCursorPosition(hOutput, loc);    
 return;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值