小游戏“盗宝奇侠”

来源:互联网 发布:mac硬盘新建文件夹 编辑:程序博客网 时间:2024/06/07 06:07
//今天去学校看舞林大会了~~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