当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
打蜜蜂(C语言)
发布时间:2010/7/28 11:45:25 来源:城市学习网 编辑:ziteng
  #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," ");
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved