听dj战歌,就上傲气战歌网!2015年传奇家族玩家最喜爱的家族战歌网
战歌推荐:战歌网 战歌网dj Mc战歌网 DJ战歌网下载 激情战歌-冰雪战歌网 客服Q:350317
新闻搜索:

利用C++实现的贪吃蛇游戏(2)

作者:     来源:    发表时间:2011-04-16 16:59


  while(overlap==true);
  randomNode.x=randx;
  randomNode.y=randy;
  randomNode.next=NULL;
  setfillstyle(SOLID_FILL,RED);
  bar(randomNode.x+1,randomNode.y+1,randomNode.x+BlockWidth-1,randomNode.y+BlockHeight-1);
  neednode=false;
  }
  if((key=bioskey(1))!=0)
  {
  switch(key)
  {
  case ESC:  return false;
  case UP:
  if(CurrentDirection!=down)
  CurrentDirection=up;
  ClearKeyBuf();
  break;
  case DOWN:
  if(CurrentDirection!=up)
  CurrentDirection=down;
  ClearKeyBuf();
  break;
  case LEFT:
  if(CurrentDirection!=right)
  CurrentDirection=left;
  ClearKeyBuf();
  break;
  case RIGHT:
  if(CurrentDirection!=left)
  CurrentDirection=right;
  ClearKeyBuf();
  break;
  case PAGEUP:speed=speed-100;
  if(speed<100)
  speed=100;
  ClearKeyBuf();

本文来自数据大全网


  break;
  case PAGEDOWN:speed=speed+100;
  if(speed>500)
  speed=500;
  ClearKeyBuf();
  break;
  default :break;
  }
  }
  int headx=snake.tail->x;
  int heady=snake.tail->y;
  switch(CurrentDirection)
  {
  case up: heady-=BlockHeight;break;
  case down: heady+=BlockHeight;break;
  case left: headx-=BlockWidth;break;
  case right: headx+=BlockWidth;break;
  }
  if(Hit(headx,heady))    //whether the snake hit the wall or itself
  return GameOver();
 更多内容请看C/C++技术专题  网络游戏攻略  游戏开发专题,或 


  else
  {       //eat
  if(headx==randomNode.x&&heady==randomNode.y)
  {
  Enqueue(randomNode);
  setfillstyle(SOLID_FILL,BLUE);
  bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight);

内容来自sql163


  neednode=true;
  }
  else     //no eat
  {
  newNode.x=headx;
  newNode.y=heady;
  newNode.next=NULL;
  Enqueue(newNode);
  outNode=Dequeue();
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1);
  setfillstyle(SOLID_FILL,BLUE);
  bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight);
  }
  }
  delay(speed);
  }
  }
  void ClearKeyBuf()
  {
  do
  bioskey(0);
  while(bioskey(1));
  }   void Foot(int x,int y)
  {
  setcolor(BLUE);
  outtextxy(x,y,"writer:[T]RealXL E-MAIL:realgeneral@hotmail.com");
  }
  void Head(int x,int y)
  {
  setcolor(RED);

  outtextxy(x,y,"GREEDY SNAKE");
  }
  void Enqueue(Node inNode)
  {
  Node *p=new Node; 内容来自sql163
  p->x=inNode.x;
  p->y=inNode.y;
  p->next=inNode.next;
  snake.tail->next=p;
  snake.tail=p;
  snake.length++;
  }

 更多内容请看C/C++技术专题  网络游戏攻略  游戏开发专题,或 


  Node Dequeue()
  {
  Node *p=snake.head;
  Node outNode=*p;
  snake.head=p->next;
  snake.length--;
  delete p;
  return outNode;
  }   int Hit(int x,int y)
  {
  if(x<frame.leftx>=frame.righty<frame.topy>=frame.bottom)//hit the wall
  return 1;
  Node *p=snake.head->next;
  for(int i=snake.length-1;i>3;i--,p=p->next)//hit itself
  if(x==p->x&&y==p->y)
  return 1;
  return 0;
  }   bool GameOver()
  {
  int x=getmaxx()/2-50;
  int y=getmaxy()/2-20;
  setfillstyle(SOLID_FILL,DARKGRAY); 本文来自数据大全网
  bar(x+3,y+3,x+103,y+43);
  setfillstyle(SOLID_FILL,MAGENTA);
  bar(x,y,x+100,y+40);
  setlinestyle(0,3,1);
  setcolor(RED);
  rectangle(x,y,x+100,y+40);
  outtextxy(x+20,y+10,"GAGE OVER!");
  char c;
  while(true)                                        //按q或Q表示退出程序,按r或R表示重新开始游戏
  {
  c=getch();
  if(c==’q’c==’Q’)
  return false;
  else if(c==’r’c==’R’)
  return true;
  }
  }
  //conf.h                                                            本文来自数据大全网
  #ifndef _conf_h
  #define _conf_h
  #define RowOfFrame    20         //主框架的行数
  #define ColumnOfFrame 20         //主框架的列数
  #define BlockWidth    15        //每个蛇节点的宽度
  #define BlockHeight   15        //每个蛇节点的高度
  #define UP   18432
  #define DOWN  20480
  #define LEFT  19200
  #define RIGHT  19712
  #define ESC   283
  #define ENTER  7181
  #define PAGEUP  18688
  #define PAGEDOWN 20736
  #endif

sql163.com

( 来源:www.sql163.com) ( 责任编辑:一铭 ) 【网站首页】 【关于我们】 【合作说明】 【广告指南】 【联系方式】 【版权声明】 【网站地图】 【收藏本站】 【设为首页】

数据大全网、数据联盟网:www.sql163.com    E-Mail:oksql@126.com    备案号:皖ICP备06001263号        点击这里给我发消息

Powered by SQL163.COM © 2004-2009 数据大全 版权所有 推荐使用分辨率1024*768

数据统计中!!

最新评论共有  位网友发表了评论
发表评论(评论内容:请文明参与评论,禁止谩骂攻击!)
不能超过250字节,请自觉遵守互联网相关政策法规.
昵称:    发表评论 (Ctrl+Enter快速回复)

关于本站 | 合作加盟 | 合作说明 | 免责声明 | 广告服务 | 网站地图

健康游戏忠告:抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活

如有意见和建议,请惠赐E-mail至350317@qq.com 联系QQ:350317

Copyright © 2010-2013 Www.27zG.CoM
苏ICP备11049833号