| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2292 人关注过本帖
标题:爱心吃豆-源码
只看楼主 加入收藏
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
结帖率:100%
收藏
 问题点数:0 回复次数:7 
爱心吃豆-源码
程序代码:
#include <graphics.h>
#include <math.h>
#include "myinclude.h"
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define HOME 0x4700
#define END 0x4f00
#define SPACE 0x3920
#define ESC 0x011b
#define ENTER 0x1c0d
#define N 6/*敌人的数量*/
struct PLay
{

 double x;/*图形模式下的具体坐标*/

 double y;

 int i,j;/*转化后的坐标*/

 int life;/*生命*/

 int mode;/*判断8种样子*/

 int move;/*判断是否按键移动*/

 int flag;/*当跟踪性的敌人只有一个方向可走时,调用chang时需要变下方向*/
}play,amy[N];
char str[10];
int tbfPLAY[30][30];/*显示玩家*/
int tbfAMY[30][30];/*敌人1*/
int tbfAMY1[30][30];/*敌人2*/
int tbfFOOD[30][30];/*食物*/
int tbfWALL[30][30];/*墙壁*/
int score;/*得分*/
int WINNUM;/*要多少分才过关的标志*/
int GUAN;/*第几关的标志*/
double SPEED=9.0;/*地图中,0是食物,2是墙壁,-1空地*/
int MAP2[14][20]={2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
   2,-1,0,0,0,0,0,0,-1,0,0,0,0,-1,-1,-1,0,0,0,2,
   2,0,0,2,2,2,2,2,2,-1,-1,2,2,2,2,2,2,0,0,2,
   2,0,-1,0,0,-1,-1,0,0,-1,0,-1,0,-1,0,-1,-1,0,0,2,
   2,0,2,2,2,0,0,-1,0,2,0,0,-1,-1,0,2,2,2,0,2,
   2,-1,-1,0,-1,-1,0,2,0,-1,0,0,2,-1,0,0,-1,-1,-1,2,
   2,-1,-1,0,0,2,0,2,0,-1,-1,0,2,0,0,2,-1,2,0,2,
   2,-1,-1,0,-1,2,0,2,2,2,0,-1,2,0,0,2,-1,2,0,2,
   2,2,2,0,-1,2,0,2,-1,-1,0,-1,2,-1,-1,2,-1,-1,0,2,
   2,0,-1,0,0,2,0,2,2,2,2,2,2,0,-1,2,0,2,0,2,
   2,-1,2,0,0,2,0,0,-1,-1,-1,0,-1,-1,0,2,0,2,0,2,
   2,0,-1,-1,-1,2,0,0,-1,-1,-1,0,0,-1,-1,2,0,-1,0,2,
   2,-1,-1,-1,-1,-1,-1,2,-1,0,-1,-1,-1,-1,-1,0,0,-1,0,2,
   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};/*第一关的地图*/
int MAP3[14][20]={2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
   2,-1,0,0,-1,-1,-1,0,0,-1,0,-1,-1,-1,-1,0,0,0,0,2,
   2,0,2,0,2,2,0,2,0,2,-1,2,2,0,0,2,2,0,0,2,
   2,-1,0,0,-1,-1,-1,0,0,0,-1,-1,0,-1,-1,-1,0,2,0,2,
   2,-1,2,-1,2,0,-1,-1,0,0,-1,0,-1,-1,0,2,0,0,0,2,
   2,0,2,0,2,-1,0,2,0,0,-1,0,2,0,0,2,0,0,0,2,
   2,0,2,0,2,-1,0,0,-1,-1,-1,0,2,-1,0,2,0,2,0,2,
   2,0,0,0,2,-1,0,2,0,0,-1,0,2,0,-1,2,0,-1,0,2,
   2,-1,2,0,2,-1,0,2,0,0,-1,0,2,0,0,2,0,2,0,2,
   2,-1,2,0,2,0,0,2,2,2,0,0,2,0,0,2,0,2,0,2,
   2,-1,0,0,0,0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,0,2,0,2,
   2,0,2,2,0,2,0,2,0,2,0,2,2,2,0,0,2,2,0,2,
   2,0,-1,-1,-1,0,0,-1,-1,0,0,-1,-1,0,0,0,-1,-1,-1,2,
   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};/*第二关的地图*/
int MAP[14][20]={2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
   2,-1,-1,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,
   2,-1,2,0,-1,-1,0,0,0,2,0,0,0,0,0,0,0,0,2,2,
   2,-1,-1,0,0,0,2,-1,-1,0,0,0,2,2,2,0,0,0,-1,2,
   2,-1,-1,0,0,0,-1,-1,2,2,0,2,2,2,2,2,0,0,-1,2,
   2,-1,-1,0,2,0,-1,-1,2,2,-1,2,2,2,2,2,2,0,-1,2,
   2,-1,2,0,2,2,2,2,2,2,2,-1,2,2,2,2,2,0,-1,2,
   2,-1,-1,0,0,2,2,2,2,2,2,2,2,2,2,2,0,0,-1,2,
   2,-1,-1,0,0,0,0,2,2,2,-1,-1,-1,-1,0,2,2,0,-1,2,
   2,-1,-1,2,0,0,0,0,0,2,2,2,0,0,0,0,0,0,-1,2,
   2,-1,-1,0,2,2,0,0,0,0,2,0,0,2,0,2,0,0,-1,2,
   2,-1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,-1,-1,2,-1,-1,2,
   2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,
   2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};/*第三关的地图*/
void Init();/*图形驱动*/
void Close();/*图形驱动*/
void GameBegain();/*开始选择画面*/
void DrawBrick(int,int);/*画砖*/
void DrawFirst();/*开始画面*/
void GamePlay();/*游戏具体函数*/
void DrawFood(int,int);/*画食物*/
void ClrPlay();/*去掉玩家或敌人原来的地方*/
void AmyClr(int n);/*去掉敌人原来的地方*/
void TbfMode();/*玩家的变化*/
void AmyMode(int n);/*敌人的变化*/
void AmyMode1(int n);/*跟踪性敌人的变化*/
void AmyClockTime(int);/*控制时间间断*/
void AmyModeChange(int);/*敌人移动*/
void AmyModeChange1(int);/*敌人跟踪移动*/
void PlayModeChange();/*玩家自动变化*/
int UMove(int);/*四个方向单独判断是否敌人可以移动*/
int DMove(int);
int RMove(int);
int LMove(int);
void Ugo(int);/*四发方向敌人的直线移动*/
void Dgo(int);
void Rgo(int);
void Lgo(int);
int AmyRight(int);/*判断敌人是否碰到死路*/
int PUMove();/*四个方向判断玩家是否可以走路*/
int PDMove();
int PRMove();
int PLMove();
void PUgo();/*四发方向玩家的直线移动*/
void PDgo();
void PRgo();
void PLgo();
int PlayRight();/*判断玩家是否碰到死路*/
void GameWin();/*胜利*/
void GameOver();/*游戏失败*/
void PrintScore();
void Chinese();/*显示中文*/
void MapCopy(int (*a)[20],int (*b)[20]);/*转换地图*/
void TongJi();/*计算要多少分才可以过关*/
void main()
{

 Init();

 GameBegain();

 GamePlay();

 Close();
}
void Chinese()/*显示中文*/
{

 int i;

 char str[]={

 /* 以下是 '吃' 的 48点阵宋体 字模,288 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,
0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x00,
0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x70,
0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,
0x00,0x01,0x00,0xE0,0x00,0x00,0x0C,0x03,
0x80,0xE0,0x00,0x00,0x0F,0xFF,0xC0,0xC0,
0x00,0x40,0x0E,0x03,0x81,0x80,0x00,0xE0,
0x0E,0x03,0x81,0xFF,0xFF,0xF0,0x0E,0x03,
0x83,0x00,0x00,0x00,0x0E,0x03,0x83,0x00,
0x00,0x00,0x0E,0x03,0x86,0x00,0x00,0x00,
0x0E,0x03,0x84,0x00,0x00,0x00,0x0E,0x03,
0x8C,0x00,0x00,0x00,0x0E,0x03,0x98,0x00,
0x00,0x00,0x0E,0x03,0x90,0x00,0x18,0x00,
0x0E,0x03,0xA0,0x00,0x3C,0x00,0x0E,0x03,
0xC7,0xFF,0xFE,0x00,0x0E,0x03,0x80,0x00,
0x78,0x00,0x0E,0x03,0x80,0x00,0xF0,0x00,
0x0E,0x03,0x80,0x00,0xE0,0x00,0x0E,0x03,
0x80,0x01,0xC0,0x00,0x0E,0x03,0x80,0x03,
0x80,0x00,0x0E,0x03,0x80,0x07,0x00,0x00,
0x0E,0x03,0x80,0x0F,0x00,0x00,0x0F,0xFF,
0x80,0x1E,0x00,0x00,0x0E,0x03,0x80,0x1C,
0x00,0x00,0x0E,0x03,0x80,0x38,0x00,0x00,
0x0E,0x03,0x80,0x70,0x00,0x40,0x0E,0x03,
0x00,0xE0,0x00,0x40,0x0E,0x00,0x01,0xE0,
0x00,0x60,0x0C,0x00,0x01,0xC0,0x00,0x60,
0x00,0x00,0x03,0x80,0x00,0x60,0x00,0x00,
0x07,0x00,0x00,0x60,0x00,0x00,0x07,0x00,
0x00,0x60,0x00,0x00,0x07,0x00,0x00,0x60,
0x00,0x00,0x07,0x00,0x00,0x70,0x00,0x00,
0x07,0x00,0x00,0xF8,0x00,0x00,0x03,0xFF,
0xFF,0xF0,0x00,0x00,0x01,0xFF,0xFF,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* 以下是 '豆' 的 48点阵宋体 字模,288 byte */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,
0x07,0x80,0x03,0xFF,0xFF,0xFF,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
0x00,0x00,0x08,0x00,0x00,0x30,0x00,0x00,
0x1C,0x00,0x00,0x3F,0xFF,0xFF,0xFE,0x00,
0x00,0x38,0x00,0x00,0x1C,0x00,0x00,0x38,
0x00,0x00,0x18,0x00,0x00,0x38,0x00,0x00,
0x18,0x00,0x00,0x38,0x00,0x00,0x18,0x00,
0x00,0x38,0x00,0x00,0x18,0x00,0x00,0x38,
0x00,0x00,0x18,0x00,0x00,0x38,0x00,0x00,
0x18,0x00,0x00,0x38,0x00,0x00,0x18,0x00,
0x00,0x38,0x00,0x00,0x18,0x00,0x00,0x3F,
0xFF,0xFF,0xF8,0x00,0x00,0x38,0x00,0x00,
0x18,0x00,0x00,0x38,0x00,0x00,0x18,0x00,
0x00,0x38,0x00,0x01,0x00,0x00,0x00,0x04,
0x00,0x01,0x80,0x00,0x00,0x03,0x00,0x01,
0xE0,0x00,0x00,0x03,0x80,0x03,0xE0,0x00,
0x00,0x01,0xC0,0x03,0xC0,0x00,0x00,0x00,
0xC0,0x03,0x80,0x00,0x00,0x00,0xE0,0x07,
0x00,0x00,0x00,0x00,0xF0,0x07,0x00,0x00,
0x00,0x00,0x70,0x06,0x00,0x00,0x00,0x00,
0x70,0x0C,0x00,0x00,0x00,0x00,0x70,0x0C,
0x00,0x00,0x00,0x00,0x60,0x18,0x00,0x60,
0x00,0x00,0x00,0x10,0x00,0xF0,0x3F,0xFF,
0xFF,0xFF,0xFF,0xF8,0x10,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
2016-04-27 10:32
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
程序代码:
 for(i=0;i<576;i+=288)

 HZ48(260+i/4,100,48,48,0,str+i);

 for(i=0;i<576;i+=288)

 HZ48(258+i/4,100,48,48,RED,str+i);
}
void GameBegain()/*开始选择画面*/
{

 int flag=0;

 int s=0;

 int key;

 int namex,namey;

 GUAN=1;/*一开始先玩第一关*/

 InputTbf("heart.tbf",tbfFOOD);

 namex=5;namey=440;

 setfillstyle(SOLID_FILL,7);

 bar(0,0,640,480);

 Chinese();

 play.x=10;play.y=220;

 HZ12(150,300,15,0,"请先调整游戏速度,左键为减速,右键为加速,回车游戏开始");

 while(1)

 {
  while(!kbhit())
  {
  if(s==3)
  {
  sound(250);
  bar(play.x-30,play.y-30,play.x+30,play.y+30);
  if(flag==1)
  {InputTbf("r1.tbf",tbfPLAY);flag=0;}
  else
  {InputTbf("r2.tbf",tbfPLAY);flag=1;}
  PrintTbf(play.x,play.y,tbfPLAY,15);
  play.x+=30;
  if(play.x>640)
  play.x=10;
  s=0;
  }
  HZ12(namex,namey,17,BLACK,"唯c联盟 朱昀");
  AmyClockTime(0);/*测试时间间隔*/
  if(s==1)
  {
  HZ12(namex,namey,17,7,"唯c联盟 朱昀");
  namex+=20;
  }
  if(namex>640&&s==1)
  namex=10;
  nosound();
  s++;
  }
  key=bioskey(0);
  if(key==RIGHT&&SPEED>2)
  SPEED-=1;
  else if(key==LEFT&&SPEED<50)
  SPEED+=1;
  else if(key==ENTER)
  break;

 }
}
void Init()
{

 int gd=DETECT,gm;

 registerbgidriver(EGAVGA_driver);/*独立模式*/

 initgraph(&gd,&gm,"d:\\tc\\tc");

 randomize();
}
int timeflag=0;/*移动间隔的判断变量*/
void AmyClockTime(int n)/*时间间隔*/
{

 clock_t old,new;

 if(n==0)

 timeflag++;

 old=clock();

 while(1)

 {

 new=clock();

 if(n==0)
  {
  if((fabs(new-old)/SPEED)>=0.15)
  break;
  }

 else
  {
  if((fabs(new-old)/SPEED)>=0.05)
   break;
  }

 }
}
void ClrPlay()/*去掉玩家原来的地方*/
{

 setfillstyle(SOLID_FILL,7);

 setcolor(7);

 bar(30+play.x*30-9,40+play.y*30-9,30+play.x*30+9,40+play.y*30+9);

 setcolor(GREEN);
}
void AmyClr(int n)/*去掉敌人原来的地方*/
{
setfillstyle(SOLID_FILL,7);

 setcolor(7);

 bar(30+amy[n].x*30-9,40+amy[n].y*30-9,30+amy[n].x*30+9,40+amy[n].y*30+9);
}
void TbfMode()/*玩家的变化*/
{

 switch(play.mode)

 {

 case 1:InputTbf("r1.tbf",tbfPLAY);break;

 case 2:InputTbf("r2.tbf",tbfPLAY);break;

 case 3:InputTbf("d1.tbf",tbfPLAY);break;

 case 4:InputTbf("d2.tbf",tbfPLAY);break;

 case 5:InputTbf("l1.tbf",tbfPLAY);break;

 case 6:InputTbf("l2.tbf",tbfPLAY);break;

 case 7:InputTbf("u1.tbf",tbfPLAY);break;

 case 8:InputTbf("u2.tbf",tbfPLAY);break;

 }

 PrintTbf((int)(30+play.x*30-14),(int)(40+play.y*30-14),tbfPLAY,7);
}
void AmyMode(int n)/*敌人的变化*/
{ switch(amy[n].mode)

 {

 case 1:InputTbf("ar1.tbf",tbfAMY);break;

 case 2:InputTbf("ar2.tbf",tbfAMY);break;

 case 3:InputTbf("ad1.tbf",tbfAMY);break;

 case 4:InputTbf("ad2.tbf",tbfAMY);break;

 case 5:InputTbf("al1.tbf",tbfAMY);break;

 case 6:InputTbf("al2.tbf",tbfAMY);break;

 case 7:InputTbf("au1.tbf",tbfAMY);break;

 case 8:InputTbf("au2.tbf",tbfAMY);break;

 }

 PrintTbf((int)(30+amy[n].x*30-14),(int)(40+amy[n].y*30-14),tbfAMY,7);
}
void AmyMode1(int n)/*敌人的变化*/
{ switch(amy[n].mode)

 {

 case 1:InputTbf("aar1.tbf",tbfAMY1);break;

 case 2:InputTbf("aar2.tbf",tbfAMY1);break;

 case 3:InputTbf("aad1.tbf",tbfAMY1);break;

 case 4:InputTbf("aad2.tbf",tbfAMY1);break;

 case 5:InputTbf("aal1.tbf",tbfAMY1);break;

 case 6:InputTbf("aal2.tbf",tbfAMY1);break;

 case 7:InputTbf("aau1.tbf",tbfAMY1);break;

 case 8:InputTbf("aau2.tbf",tbfAMY1);break;

 }

 PrintTbf((int)(30+amy[n].x*30-14),(int)(40+amy[n].y*30-14),tbfAMY1,7);
}
int UMove(int i)
{

 int flag=0;

 if(MAP[amy[i].i-1][amy[i].j]==2&&amy[i].y-amy[i].i<0.1)

 flag++;

 if(amy[i].y-amy[i].i<0.1&&amy[i].x-amy[i].j>0.1&&MAP[amy[i].i-1][amy[i].j+1]==2)

 flag++;

 return flag;
}
int PUMove()
{

 int flag=0;

 if(MAP[play.i-1][play.j]==2&&play.y-play.i<0.1)

 flag++;

 if(play.y-play.i<0.1&&play.x-play.j>0.1&&MAP[play.i-1][play.j+1]==2)

 flag++;

 return flag;
}
int DMove(int i)
{

 int flag=0;

 if(MAP[amy[i].i+1][amy[i].j]==2)

 flag++;

 if(amy[i].y-amy[i].i<0.1&&amy[i].x-amy[i].j>0.1&&MAP[amy[i].i+1][amy[i].j+1]==2)

 flag++;

 return flag;
}
int PDMove()
{

 int flag=0;

 if(MAP[play.i+1][play.j]==2)

 flag++;

 if(play.y-play.i<0.1&&play.x-play.j>0.1&&MAP[play.i+1][play.j+1]==2)

 flag++;

 return flag;
}
int RMove(int i)
{

 int flag=0;

 if(MAP[amy[i].i][amy[i].j+1]==2)/*右边不能走的情况*/

 flag++;

 if(amy[i].y-amy[i].i>0&&amy[i].x-amy[i].j<0.1&&MAP[amy[i].i+1][amy[i].j+1]==2)

 flag++;

 return flag;
}
int PRMove()
{

 int flag=0;

 if(MAP[play.i][play.j+1]==2)/*右边不能走的情况*/

 flag++;

 if(play.y-play.i>0&&play.x-play.j<0.1&&MAP[play.i+1][play.j+1]==2)

 flag++;

 return flag;
}
int LMove(int i)
{

 int flag=0;
  if(amy[i].x-amy[i].j<0.1&&amy[i].y-amy[i].i<0.1&&MAP[amy[i].i][amy[i].j-1]==2)

 flag++;

 if(amy[i].x-amy[i].j<0.1&&amy[i].y-amy[i].i>0.1&&MAP[amy[i].i+1][amy[i].j-1]==2)

 flag++;

 if(amy[i].x-amy[i].j<0.1&&amy[i].y-amy[i].i>0.1&&MAP[amy[i].i][amy[i].j-1]==2)

 flag++;

 return flag;
}
int PLMove()
{

 int flag=0;
  if(play.x-play.j<0.1&&play.y-play.i<0.1&&MAP[play.i][play.j-1]==2)

 flag++;

 if(play.x-play.j<0.1&&play.y-play.i>0.1&&MAP[play.i+1][play.j-1]==2)

 flag++;

 if(play.x-play.j<0.1&&play.y-play.i>0.1&&MAP[play.i][play.j-1]==2)

 flag++;

 return flag;
}
int AmyRight(int i)/*判断敌人是否碰到死路*/
{

 int flag=0;

 flag+=UMove(i);

 flag+=RMove(i);

 flag+=DMove(i);

 flag+=LMove(i);

 return flag;
}
int PlayRight()/*判断me是否碰到死路*/
{

 int flag=0;

 flag+=PUMove();

 flag+=PRMove();

 flag+=PDMove();

 flag+=PLMove();

 return flag;
}

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-04-27 10:33
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
程序代码:
void Rgo(int i)/*让敌人笔直往右边移动*/
{
  amy[i].x+=0.5;
  if(amy[i].mode==2)
  amy[i].mode=1;
  else if(amy[i].mode==1)
  amy[i].mode=2;
}
void PRgo()
{
  play.x+=0.5;
  if(play.mode==2)
  play.mode=1;
  else if(play.mode==1)
  play.mode=2;
  else play.mode=2;
}
void Dgo(int i)
{
   amy[i].y+=0.5;
  if(amy[i].mode==3)
  amy[i].mode=4;
  else if(amy[i].mode==4)
  amy[i].mode=3;
}
void PDgo()
{
  play.y+=0.5;
  if(play.mode==3)

 play.mode=4;
  else if(play.mode==4)
  play.mode=3;
  else play.mode=4;
}
void Lgo(int i)
{
   amy[i].x-=0.5;
   if(amy[i].mode==5)
   amy[i].mode=6;
   else if(amy[i].mode==6)
   amy[i].mode=5;
}
void PLgo()
{
    play.x-=0.5;
   if(play.mode==5)
   play.mode=6;
   else if(play.mode==6)
   play.mode=5;
   else play.mode=6;
}
void Ugo(int i)
{
  amy[i].y-=0.5;
  if(amy[i].mode==7)
  amy[i].mode=8;
  else if(amy[i].mode==8)
  amy[i].mode=7;
}
void PUgo()
{
  play.y-=0.5;
  if(play.mode==7)
  play.mode=8;
  else if(play.mode==8)
  play.mode=7;
  else play.mode=8;
}
void AmyModeChange1(int i)/*敌人跟踪移动*/
{
  int flag;
  /*往右跟踪*/
  if(amy[i].i==play.i&&amy[i].y==play.y)
  {
   flag=1;
   if(amy[i].j<=16&&MAP[i][amy[i].j+1]==2&&play.j>amy[i].j)
    flag=0;
   if(amy[i].j>=3&&MAP[i][amy[i].j-1]==2&&play.j<amy[i].j)
    flag=0;
   if(flag)
   {
   if(amy[i].x>play.x&&LMove(i)==0)
    {
      if(amy[i].mode==5||amy[i].mode==6)
      Lgo(i);
      else
      {amy[i].x-=0.5;amy[i].mode=6;}
      return;
    }
  else if(RMove(i)==0)
    {
      if(amy[i].mode==1||amy[i].mode==2)
      Rgo(i);
      else
      {amy[i].x+=0.5;amy[i].mode=2;}
      return;
    }
   }
  }
  if(amy[i].j==play.j&&amy[i].x==play.x)/*上下跟踪*/
  {
   flag=1;
   if(amy[i].i>2&&MAP[amy[i].i-1][amy[i].j]==2&&amy[i].i>play.i)
    flag=0;
   if(amy[i].i<11&&MAP[amy[i].i+1][amy[i].j]==2&&amy[i].i<play.i)
    flag=0;
   if(flag)
   {
   if(UMove(i)==0&&amy[i].y>play.y)
   {
    if(amy[i].mode>6)
    Ugo(i);
    else
    {amy[i].y-=0.5;amy[i].mode=8;}
    return;
   }
   else if(DMove(i)==0)
   {
    if(amy[i].mode==3||amy[i].mode==4)
    Dgo(i);
    else
    {amy[i].y+=0.5;amy[i].mode=4;}
    return;
   }
   }
  }
  amy[i].flag=1;
  AmyModeChange(i);/*没办法跟踪就让敌人乱走*/
  amy[i].flag=0;
}
void PlayModeChange()/*玩家自动变化*/
{int randflag,flag;

 if(play.mode<3&&PRMove()==0)/*右边笔直走*/

 {
  PRgo();
  return;

 }

 else if((play.mode==3||play.mode==4)&&PDMove()==0)/*下不变化*/

 {
  PDgo();
  return;

 }

 else if((play.mode==5||play.mode==6)&&PLMove()==0)/*左不变*/

 {
   PLgo();
   return;

 }

 else if(play.mode>6&&PUMove()==0)/*上不变*/

 {
  PUgo();
  return;

 }

 flag=1;

 while(flag)

 {

 randflag=random(4)+1;

 if(randflag==1)/*右边*/
  {
  if(PRMove()!=0)
   continue;
  PRgo();
  flag=0;
  }

 else if(randflag==2)/*下方*/
  {
  if(PDMove()!=0)
   continue;
  PDgo();
  flag=0;
  }

 else if(randflag==3)/*左边走*/
  {
   if(PLMove()!=0)
    continue;
   PLgo();
   flag=0;
  }

 else if(randflag==4)/*往上走*/

 {
  if(PUMove()!=0)
   continue;
  PUgo();
  flag=0;
  }

 }
}

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-04-27 10:33
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
程序代码:
void AmyModeChange(int i)/*敌人的变化*/
{

 int randflag,flag;

 if(amy[i].mode<3&&RMove(i)==0)/*右边笔直走*/

 {
  Rgo(i);
  return;

 }

 else if((amy[i].mode==3||amy[i].mode==4)&&DMove(i)==0)/*下不变化*/

 {
  Dgo(i);
  return;

 }

 else if((amy[i].mode==5||amy[i].mode==6)&&LMove(i)==0)/*左不变*/

 {
   Lgo(i);
   return;

 }

 else if(amy[i].mode>6&&UMove(i)==0)/*上不变*/

 {
  Ugo(i);
  return;

 }
  if(amy[i].flag==1)
  {
   switch(amy[i].mode)
  {
  case 1:
  case 2:amy[i].mode=6;break;
  case 3:
  case 4:amy[i].mode=8;break;
  case 5:
  case 6:amy[i].mode=2;break;
  case 7:
  case 8:amy[i].mode=4;break;
  }
  amy[i].flag=0;
  }

 flag=1;

 while(flag)

 {

 randflag=random(4)+1;

 if(randflag==1)/*右边*/
  {
  if(AmyRight(i)<8)
   {
   if(amy[i].mode==5||amy[i].mode==6)
   continue;
   }
  if(RMove(i)!=0)
   continue;
  amy[i].x+=0.5;
  if(amy[i].mode==2)
  amy[i].mode=1;
  else if(amy[i].mode==1)
  amy[i].mode=2;
  else
  amy[i].mode=2;
  flag=0;
  }

 else if(randflag==2)/*下方*/
  {
  if(AmyRight(i)<8)
   {
   if(amy[i].mode>6)
    continue;
   }
  if(DMove(i)!=0)
   continue;
  amy[i].y+=0.5;
  if(amy[i].mode==3)
  amy[i].mode=4;
  else if(amy[i].mode==4)
  amy[i].mode=3;
  else
  amy[i].mode=4;
  flag=0;
  }

 else if(randflag==3)/*左边走*/
  {
   if(LMove(i)!=0)
    continue;
   amy[i].x-=0.5;
   if(amy[i].mode==5)
   amy[i].mode=6;
   else if(amy[i].mode==6)
   amy[i].mode=5;
   else amy[i].mode=6;
   flag=0;
  }

 else if(randflag==4)/*往上走*/

 {
  if(UMove(i)!=0)
   continue;
  amy[i].y-=0.5;
  if(amy[i].mode==7)
  amy[i].mode=8;
  else if(amy[i].mode==8)
  amy[i].mode=7;
  else
  amy[i].mode=8;
  flag=0;
  }

 }
}
void DrawBrick(int x,int y)/*画砖*/
{
setfillstyle(SOLID_FILL,6);
bar(30+x*30-14,40+y*30-14,30+x*30+14,40+y*30+14);
setcolor(15);
line(30+x*30-9-5,40+y*30-4-1,30+x*30+9+5,40+y*30-4-1);
line(30+x*30-9-5,40+y*30+4+1,30+x*30+9+5,40+y*30+4+1);
line(30+x*30-4-1,40+y*30-9-5,30+x*30-4-1,40+y*30+9+5);
line(30+x*30+4+1,40+y*30-9-5,30+x*30+4+1,40+y*30+9+5);
}
void DrawFood(int x,int y)/*画食物*/
{


 PrintTbf(30+x*30-14,40+y*30-14,tbfFOOD,7);
}
void DrawFirst()/*开始画面*/
{

 int i,j;

 setfillstyle(SOLID_FILL,7);

 bar(0,0,640,480);

 for(i=0;i<14;i++)
  for(j=0;j<20;j++)
   if(MAP[i][j]==2)/*砖头*/
    DrawBrick(j,i);
   else if(MAP[i][j]==0)
    DrawFood(j,i);/*画心,这里作为食物处理*/
}
void GameWin()/*胜利*/
{
  int key;
  TbfMode();
  InputTbf("esmile.tbf",tbfAMY);
  DrawFrame(220,190,420,250,7);
  HZ12(280,195,19,0,"你胜利了!");
  PrintTbf(300,215,tbfAMY,RED);
  while(1)
  {
  key=bioskey(0);
  if(key==ENTER)
   break;
  }
}
void GameOver()/*游戏失败*/
{
  int key,i,j;
  for(i=1;i<=16;i+=2)
  {
  if(i>7)
   j=i-9+1;
  else
   j=i;
  ClrPlay();
  play.mode=j;
  TbfMode();
  for(j=0;j<N;j++)
  {
   if(amy[j].x==play.x&&amy[j].y==play.y)/*与玩家碰在一起的敌人不显示出来*/
    continue;
   else if(j<3)
   AmyMode(j);
   else
   AmyMode1(j);
  }
  for(j=0;j<4;j++)
  {
  if(j!=0)
   sound(50*(16-i));
  AmyClockTime(0);
  }
  nosound();
  }
  InputTbf("ecry.tbf",tbfAMY);
  DrawFrame(220,190,420,250,7);
  HZ12(280,195,19,0,"你失败了!");
  PrintTbf(300,215,tbfAMY,RED);
  while(1)
  {
  key=bioskey(0);
  if(key==ENTER)
   break;
  }
}

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-04-27 10:33
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
程序代码:
void MapCopy(int (*a)[20],int (*b)[20])/*转换地图*/
{

 int i,j;

 for(i=0;i<14;i++)/*交换地图*/

 {
  for(j=0;j<20;j++)
   a[i][j]=b[i][j];

 }
}
void PrintScore()
{

 setfillstyle(SOLID_FILL,7);

 bar(140,0,200,25);

 HZ12(80,8,20,0,"得分:");

 sprintf(str,"%d",score);

 setcolor(0);

 outtextxy(150,10,str);/*显示得分*/
}
void TongJi()/*计算要多少分才可以过关*/
{

 int i,j;

 WINNUM=0;/*统计需要多少分数才过关*/

 for(i=0;i<14;i++)
  for(j=0;j<20;j++)
   if(MAP[i][j]==0)
   WINNUM++;
}
void GamePlay()/*游戏的具体过程*/
{

 int key;

 int i;

 int foodi,foodj,foodflag;/*判断是敌人走过的地方是否要重新显示心*/

 DrawFirst();/*显示当前地图*/

 TongJi();/*统计要多少分才及格*/

 timeflag=0;

 play.x=1;/*玩家初值*/

 play.y=1;

 play.life=1;

 play.mode=2;

 play.move=0;

 amy[0].y=1;/*敌人的初始坐标以及方向*/

 amy[0].x=18;

 amy[0].mode=6;

 amy[1].y=12;

 amy[1].x=1;

 amy[1].mode=2;

 amy[2].y=12;

 amy[2].x=18;

 amy[2].mode=6;

 amy[3].y=8;

 amy[3].x=10;

 amy[3].mode=8;

 amy[4].y=5;

 amy[4].x=5;

 amy[4].mode=6;

 amy[5].y=8;

 amy[5].x=13;

 amy[5].mode=8;

 for(i=0;i<N;i++)

 amy[i].flag=0;

 score=0;/*一开始的分数*/

 while(1)

 {
  for(i=0;i<N;i++)/*玩家撞敌人*/
  {
  if(play.x==amy[i].x&&play.y==amy[i].y)
  {play.life=0;break;}
  }

 if(play.life==0)/*玩家移动后碰到敌人死去*/

 {
  GameOver();
  break;

 }

 play.j=play.x;/*玩家计算i,j坐标*/

 play.i=play.y;

 if(MAP[play.i][play.j]==0&&play.x-play.j<0.1&&play.y-play.i<0.1)/*吃到一个食物*/

 {

 score++;

 PrintScore();

 TbfMode();

 for(i=0;i<N;i++)

 {

 if(i<3) AmyMode(i);

 else AmyMode1(i);

 }

 MAP[play.i][play.j]=-1;/*吃到食物后变为空地*/

 }
  if(score==WINNUM)/*玩家胜利*/

 {
  GameWin();
  break;

 }

 if(play.move==0)/*如果有变化就重新显示*/

 {

 PrintScore();

 TbfMode();

 play.move=1;

 }

 while(1)/*敌人自动移动*/

 {
  for(i=0;i<N;i++)/*amy meet player*/
  {
   if(play.x==amy[i].x&&play.y==amy[i].y)
    {play.life=0;break;}
  }
  if(play.life==0)/*敌人自动的过程中碰到玩家*/
   break;
  if(timeflag==3)/*敌人和玩家都改自动移动的时候*/
  {
    sound(250);/*敌人移动的时候有声音*/
    for(i=0;i<N;i++)/*first must clear*/
    AmyClr(i);
    for(i=0;i<N;i++)/*显示所有敌人*/
    {
    foodflag=0;/*表示没食物*/
    amy[i].j=amy[i].x;
    amy[i].i=amy[i].y;
    foodi=amy[i].i;/*food x,y*/
    foodj=amy[i].j;
    if(MAP[amy[i].i][amy[i].j]==0)
    foodflag=1;
    if(foodflag)
    DrawFood(foodj,foodi);
    if(i<3)
    AmyModeChange(i);/*这里是没跟踪功能的敌人*/
    else
    AmyModeChange1(i);/*厉害的敌人*/
    if(i<3)
    AmyMode(i);/*普通的敌人*/
    else
    AmyMode1(i);/*厉害的敌人*/
    }
    TbfMode();
    timeflag=0;
    for(i=0;i<N;i++)/*敌人碰到玩家*/
   {
   if(play.x==amy[i].x&&play.y==amy[i].y)
    {play.life=0;break;}
   }
   if(play.life==0)/*敌人自动的过程中碰到玩家*/
    break;
    if(kbhit())/*按键盘跳出循环*/
    {
     key=bioskey(0);
     AmyClockTime(0);
     nosound();/*取消声音*/
     break;
    }
     ClrPlay();
     PlayModeChange();/*玩家自动变化*/
     TbfMode();
     for(i=0;i<N;i++)
     {
     if(i<3)
     AmyMode(i);
     else
     AmyMode1(i);
     }
     play.j=play.x;/*玩家计算i,j坐标*/
     play.i=play.y;
      for(i=0;i<N;i++)/*amy meet player*/
     {
     if(play.x==amy[i].x&&play.y==amy[i].y)
      {
      play.life=0;break;
      }
     }
     if(i<N)
      break;
     if(MAP[play.i][play.j]==0&&play.x-play.j<0.1&&play.y-play.i<0.1)/*吃到一个食物*/
     {
     score++;
     PrintScore();
     TbfMode();
     MAP[play.i][play.j]=-1;/*吃到食物后变为空地*/
     for(i=0;i<N;i++)
     {
     if(i<3)
     AmyMode(i);
     else
     AmyMode1(i);
     }
    }
    if(score==WINNUM)/*自动移动过程中胜利*/
     break;
  }
  AmyClockTime(0);
  nosound();/*取消声音*/

 }

 nosound();
  if(score==WINNUM)/*玩家胜利*/

 {
  GameWin();
  break;

 }

 if(play.life==0)/*游戏失败*/

 {
  GameOver();
  break;

 }

 if(key==ESC)
  break;

 else if(key==RIGHT)/*右边移动*/

 {
  if(PRMove()!=0)
  continue;
  ClrPlay();
  PRgo();
  play.move=0;

 }

 else if(key==LEFT)/*左边移动*/

 {

 if(PLMove()!=0)
  continue;

 ClrPlay();

 play.move=0;

 PLgo();

 }

 else if(key==UP)/*上键盘移动*/

 {

 if(PUMove()!=0)
  continue;

 ClrPlay();

 play.move=0;

 PUgo();

 }

 else if(key==DOWN)/*下键盘移动*/

 {
  if(PDMove()!=0)
   continue;
  ClrPlay();
  play.move=0;
  PDgo();
  }

 }
  if(GUAN==1&&score==WINNUM)/*过了第一关继续过第二关*/
  {
   GUAN++;
   MapCopy(MAP,MAP2);
   score=0;
   timeflag=0;
   GamePlay();
  }
   if(GUAN==2&&score==WINNUM)/*过了第二关继续过第三关*/
  {
   GUAN++;
   MapCopy(MAP,MAP3);
   score=0;
   timeflag=0;
   GamePlay();
  }
}
void Close()
{

 closegraph();
}


其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-04-27 10:34
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
源码:
968959chidou.zip.rar (163.59 KB)

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-04-27 10:35
gongteng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-3-8
收藏
得分:0 
66666
2018-03-08 08:53
gongteng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-3-8
收藏
得分:0 
66666
2018-03-08 08:53
快速回复:爱心吃豆-源码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048350 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved