论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

一个小游戏

文章类别:C语言程序设计 | 发表日期:2008-9-24 14:46:53

在迷宫中找出几个数之和是7的数并把它们吃掉后再吃掉7就获胜了。(编得简单了点,但这是我编的第一个游戏请多指教)

#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#include "conio.h"
#include "time.h"
#include "stdlib.h"
int k[17][24]={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,1,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,
               0,1,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,
               0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,
               0,3,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,0,
               0,1,0,0,1,0,1,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,
               0,1,1,1,1,1,6,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,
               0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,0,
               0,1,1,1,1,1,1,1,1,1,1,5,1,1,1,0,1,0,0,1,0,0,0,0,
               0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,4,0,0,1,0,0,0,0,
               0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,1,0,1,1,0,
               0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,
               0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,
               0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,3,1,1,1,1,1,0,0,
               0,2,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
               0,0,1,1,1,1,1,1,1,1,1,1,1,1,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,};
main()
{int i,j,key,num;
aa: clrscr();
num=0;
textcolor(GREEN);
gotoxy(14,1);
cprintf("%c(UP) %c(DOWN) %c(LEFT) %c(RIGHT) ESC(QUIT)\n",24,25,27,26);
textcolor(RED);
for(i=4;i<21;i++)
   for(j=20;j<44;j++)
      if(k[i-4][j-20]==0)
         {gotoxy(j,i);
          cprintf("%c",219);
          }
      else if(k[i-4][j-20]!=1)
           {gotoxy(j,i);
            cprintf("%d",k[i-4][j-20]);
            }
textcolor(YELLOW);
i=5;
j=21;
gotoxy(j,i);
cprintf("\1");
gotoxy(33,5);
cprintf("7");
do
  {key=bioskey(0);
   sound(200);
   delay(1000);
   nosound();
   switch(key)
    {case DOWN:{if(k[i-4+1][j-20]==0)continue;
              if(k[i-4+1][j-20]!=1)num+=k[i-4+1][j-20];
              textcolor(YELLOW);
              gotoxy(j,i++);
              printf(" ");
              gotoxy(j,i);
              cprintf("\1");gotoxy(33,5);
              if(k[i-4][j-20]==7&&num==14)
                 {clrscr();printf("yes\n");exit(0);}
              else if(num!=7&&k[i-4][j-20]==7){clrscr();printf("%d\n",num);delay(1000);goto aa;}
              break; }
     case UP:{if(k[i-4-1][j-20]==0)continue;
              if(k[i-4-1][j-20]!=1)num+=k[i-4-1][j-20];
              textcolor(YELLOW);
              gotoxy(j,i--);
              printf(" ");
              gotoxy(j,i);
              cprintf("\1");gotoxy(33,5);
              if(k[i-4][j-20]==7&&num==14)
                 {clrscr();printf("yes\n");exit(0);}
              else if(num!=7&&k[i-4][j-20]==7){clrscr();printf("%d\n",num);delay(100000);goto aa;}
              break; }
     case LEFT:{if(k[i-4][j-20-1]==0)continue;
              if(k[i-4][j-20-1]!=1)num+=k[i-4][j-20-1];
              textcolor(YELLOW);
              gotoxy(j--,i);
              printf(" ");
              gotoxy(j,i);
              cprintf("\1");gotoxy(33,5);
              if(k[i-4][j-20]==7&&num==14)
                 {clrscr();printf("yes\n");exit(0);}
              else if(num!=7&&k[i-4][j-20]==7){clrscr();printf("%d\n",num);delay(1000);goto aa;}
              break; }
     case RIGHT:{if(k[i-4][j-20+1]==0)continue;
              if(k[i-4][j-20+1]!=1)num+=k[i-4][j-20+1];
              textcolor(YELLOW);
              gotoxy(j++,i);
              printf(" ");
              gotoxy(j,i);
              cprintf("\1");gotoxy(33,5);
              if(k[i-4][j-20]==7&&num==14)
                 {clrscr();printf("yes\n");exit(0);}
              else if(num!=7&&k[i-4][j-20]==7){clrscr();printf("%d\n",num);delay(1000);goto aa;}
              break; }
     default :exit(0);
     }
  }while(1);
}

上一篇:{应用}菜鸟的找救老婆游戏 人气:4648
下一篇:{应用}俄罗斯方块大全 人气:5201
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058