加入收藏 收藏网站 设为首页 设为首页
招生考试网
学历类| 阳光高考 研 究 生 自学考试 成人高考 专 升 本 中考会考 外语类| 四 六 级 职称英语 商务英语 公共英语 日语能力
资格类| 公 务 员 报 关 员 银行从业 司法考试 导 游 证 教师资格 财会类| 会 计 证 经 济 师 会计职称 注册会计 税 务 师
工程类| 一级建造 二级建造 造 价 师 造 价 员 咨 询 师 监 理 师 医学类| 卫生资格 执业医师 执业药师 执业护士 国际护士
计算机| 等级考试 软件水平 应用能力 其它类| 书画等级 美国高考 驾 驶 员 书法等级 少儿英语 报 检 员 单 证 员 出国留学
 招生考试网 - 计算机等级考试 - 考试辅导 - 计算机二级 - 正文

 
C语言教你如何打蜜蜂
来源:fjzsksw.com 2010-7-28 编辑:zhanghaifeng 【字体:小 大】
C语言教你如何打蜜蜂

 

 

#include"stdio.h"

  #include"graphics.h"

  int tanke_size=30,star_size=30;

  int guan_ka=1;

  /*1:blue 2:green 3:light blue 4:red 5:fen red 6:zong 7:white 8:light white*/

  int tanke_current_x,tanke_current_y;

  int tanke_left=20,tanke_right=620,tanke_top=20,tanke_bottom=450;

  int fist_star_x,fist_star_y;

  int zidan_current_x=-1,zidan_current_y=-1,zidan_color=4;

  int mifeng_x[6][18],mifeng_y[6][18];

  int mifeng_count=0;

  void main()

  {

  int i,j,k;

  int first_star_x=50;

  int first_star_y=50;

  ChuShiHuaGraphics();

  rectangle(tanke_left-1,tanke_top-1,tanke_right+1,tanke_bottom);

  tanke_current_x=290; tanke_current_y=410;

  CreateTanke(tanke_current_x,tanke_current_y);

  /*CreateStar(100,100); */

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

  {

  for(j=0;j<18;j++)

  {

  CreateStar(first_star_x,first_star_y,-1);

  mifeng_x[i][j]=first_star_x;

  mifeng_y[i][j]=first_star_y;

  /* printf("(%d,%d)",mifeng_x[i][j],mifeng_y[i][j]);*/

  first_star_x+= star_size;

  mifeng_count++;

  }

  first_star_x=50;

  first_star_y+=star_size;

  }

  /*printf("%d",mifeng_count);*/

  StartGame();

  getchar();

  }

  CreateStar(int x,int y,int color)

  {

  int A_x=x+15,A_y=y;

  int B_x=x+2,B_y=y+10;

  int C_x=x+7,C_y=y+30;

  int D_x=x+22,D_y=y+30;

  int E_x=x+28,E_y=y+10;

  int temp_color;

  temp_color=getcolor();

  if (color==-1)

  {

  setcolor(x%8==0?x+1:x%8);

  }

  else

  {

  setcolor(color);

  }

  line(A_x,A_y,C_x,C_y);

  line(A_x,A_y,D_x,D_y);

  line(B_x,B_y,D_x,D_y);

  line(B_x,B_y,E_x,E_y);

  line(C_x,C_y,E_x,E_y);

  setcolor(temp_color);

  }

  CreateTanke(int x,int y)

  {

  int twidth=4,tem_color;

  tem_color=getcolor();

  if(getcolor()!=getbkcolor())

  {

  setcolor(2);

  }

  rectangle(x,y+10,x+tanke_size,y+tanke_size);

  circle(x+tanke_size/2,y+10+tanke_size/2-5,tanke_size/2-7);

  rectangle(x+tanke_size/2-twidth/2,y,x+tanke_size/2+twidth/2,y+10+tanke_size/2-5-(tanke_size/2-7)-2+10);

  setcolor(tem_color);

  }

  /*CreateZidan(5,5,getbkcolor()) ;*/

  /*CreateZidan(5,5,6) ;*/

  CreateZidan(int x ,int y,int color)

  {

  int temcolor=getcolor();

  setcolor(color);

  circle(x+15,y+15,tanke_size/2);

  setcolor(temcolor);

  }

  StartGame()

  {

  char sign='';

  while(1)

  {

  while(!kbhit())

  {

  AUTO();

  }

  sign=getch();

  switch(sign)

  {

  case'a':turn_left();break;

  case'd':turn_right();break;

  case 'p': exit(0);break;

  }

  }

  }

  turn_left()

  {

  int x=tanke_current_x,y=tanke_current_y;/*dang qian wei zhi*/

  int temcolor;

  if(x==tanke_left)

  {

  return;

  }

  temcolor=getcolor();

  setcolor(getbkcolor());

  CreateTanke(x,y);

  setcolor(2);

  x=x-tanke_size;

  CreateTanke(x,y);

  tanke_current_x=x;

  setcolor(temcolor);

  }

  turn_right()

  {

  int x=tanke_current_x,y=tanke_current_y;

  int temcolor;

  if(x==tanke_right-tanke_size)

  {

  return;

  }

  temcolor=getcolor();

  setcolor(0);

  CreateTanke(x,y);

  setcolor(2);

  x=x+tanke_size;

  CreateTanke(x,y);

  tanke_current_x=x;

  setcolor(temcolor);

  }

 AUTO()

  {

  /* int delaytime=1000,tanke_top=20;

  int temcolor=getcolor();

  setcolor(0);

  CreateZidan(x,y);

  setcolor(2);

  y=y-tanke_size;

  CreateZidan

  (x,y);

  tanke_current_y=y;

  setcolor(temcolor);*/

  if(zidan_current_y==tanke_top)

  {

  CreateZidan(zidan_current_x,zidan_current_y,getbkcolor());

  zidan_current_x = -1;

  }

  if(zidan_current_x==-1)

  {

  CreateZidan(tanke_current_x,tanke_current_y-tanke_size,zidan_color);

  zidan_current_x=tanke_current_x;

  zidan_current_y=tanke_current_y-tanke_size;

  time_delay();

  }

  else

  {

  CreateZidan(zidan_current_x,zidan_current_y,getbkcolor());

  zidan_current_y -= tanke_size;

  CreateZidan(zidan_current_x,zidan_current_y,zidan_color);

  time_delay();

  }

  IfEat();

  }

  IfEat()

  {

  /*zidan_current_x,zidan_current_y,mifeng_x[][],mifeng_y[][]*/

  int i,j;

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

  {

  for(j=0;j<18;j++)

  {

  if (zidan_current_x==mifeng_x[i][j]&&zidan_current_y==mifeng_y[i][j])

  {

  CreateStar(mifeng_x[i][j],mifeng_y[i][j],getbkcolor());

  CreateZidan(zidan_current_x,zidan_current_y,getbkcolor());

  zidan_current_x=-1;

  mifeng_count--;

  mifeng_x[i][j]=-1,mifeng_y[i][j]=-1;

  }

  }

  }

  }

  time_delay()

  {

  sound(200);

  delay(10000);

  nosound();

  delay(10000);

  }

  ChuShiHuaGraphics()

  {

  int graphdriver=DETECT;

  int graphmode=4;

  initgraph(&graphdriver,&graphmode," ");

  }

 

 



 
网站版权与免责声明
①由于各方面情况的不断调整与变化,本网所提供的相关信息请以权威部门公布的正式信息为准.
②本网转载的文/图等稿件出于非商业性目的,如转载稿涉及版权等问题,请在两周内来电联系.
推荐文章
  • 此栏目下没有推荐文章
  • 热门文章

    报名考试
    全国 | 黑龙江 | 吉林 | 辽宁 | 内蒙古
    青海 | 宁夏 | 甘肃 | 新疆 | 陕西
    西藏 | 北京 | 天津 | 河北 | 山东
    江苏 | 安徽 | 河南 | 上海 | 浙江
    福建 | 广东 | 山西 | 湖南 | 湖北
    江西 | 广西 | 海南 | 云南 | 贵州
    四川 | 重庆
    分省高校计算机考试
    黑龙江 | 吉林 | 辽宁 | 内蒙古 | 河北
    北京 | 天津 | 新疆 | 甘肃 | 宁夏
    青海 | 陕西 | 山西 | 河南 | 山东
    江苏 | 安徽 | 浙江 | 福建 | 广东
    海南 | 广西 | 江西 | 湖北 | 湖南
    四川 | 上海 | 重庆 | 贵州 | 云南
    西藏
    成绩查询
    报考指南
    试题答案
    模拟试题
    考试辅导
    计算机一级 | 计算机二级 | 计算机三级 | 计算机四级
    经验交流
    高校计算机