• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

C++结构体数组实现贪吃蛇

c++ 搞代码 4年前 (2022-01-06) 30次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了C++结构体数组实现贪吃蛇,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C++结构体数组实现贪吃蛇的具体代码,供大家参考,具体内容如下

代码:

 #include #include #include using namespace std; const int h=50,w=50,MaxLen=400; void gotoxy(short y,short x)//光标移动函数 { COORD pos={x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); } struct node { int x,y; }; node s[MaxLen]; node food; int dir,len; int Map[h+5][w+5]; int Time[7]={0},level;//building。。。 void FoodCreate() { srand ((unsigned)time(NULL));//时间作随机数种子,避免伪随机 while(1) { food.x=rand()%h,food.y=rand()%w; if(food.x>0&&food.y>0&&Map[food.x][food.y]==0)break; } gotoxy(food.x,food.y),printf("@"); gotoxy(h+1,0); } void init() { system("cls"); for(int i=0;i<=h;i++)//画图 { for(int j=0;j1;i--)s[i]=s[i-1]; s[1]=next; Sleep(100);  //Sleep放在最后比较顺滑//速度在这儿调 return 1; } void GameOver() { for(int i=1;i属性->字体 选择点阵字体并调整字体大小为8×8\n"); printf("再选择布局设置窗口大小,推荐60×60\n\n"); printf("WASD控制方向\n"); printf("\n任意键进入贪吃蛇皮..."); getch(); } int main() { Welcome(); init(); while(1) { if(kbhit()) { char ch=getch(); int temp=dir; switch(ch) { case 'd':temp=0;break; case '<strong style="color:transparent">来源gaodaima#com搞(代@码网</strong>w':temp=1;break; case 'a':temp=2;break; case 's':temp=3;break; } if((temp+dir)%2)dir=temp;//如果方向不冲突 } if(move()==0) { GameOver(); getch(); init(); } } }

运行

关于C++小游戏的更多精彩内容请点击专题: 《C++经典小游戏》 学习了解

以上就是C++结构体数组实现贪吃蛇的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:C++结构体数组实现贪吃蛇
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址