当前位置: 首页 > news >正文

wordpress漂浮花瓣西安seo服务培训

wordpress漂浮花瓣,西安seo服务培训,wordpress下载网站模板,网站建设客服问题C语言贪吃蛇小游戏演示和说明 设计贪吃蛇游戏的主要目的是让大家夯实C语言基础,训练编程思维,培养解决问题的思路,领略多姿多彩的C语言。 游戏开始后,会在中间位置出现一条只有三个节点的贪吃蛇,并随机出现一个食物&am…

C语言贪吃蛇小游戏演示和说明


设计贪吃蛇游戏的主要目的是让大家夯实C语言基础,训练编程思维,培养解决问题的思路,领略多姿多彩的C语言。

游戏开始后,会在中间位置出现一条只有三个节点的贪吃蛇,并随机出现一个食物,如下图所示:


图1:游戏初始化


按下键盘上的任意一个键,贪吃蛇开始移动。和大部分游戏一样,你可以通过W、A、S、D四个键来控制移动方向,如下图所示:


图2:游戏进行中


当贪吃蛇出界或者撞到自己时,游戏结束,如下图所示:


图3:游戏结束

这个版本的贪吃蛇将有以下特点:

  • 使用控制台(终端)
  • ASCII字符表示蛇和食物
  • 方向控制(W, A, S, D)
  • 简单的游戏结束逻辑(蛇撞墙或撞到自己)

c
#include <stdio.h>  
#include <stdlib.h>  
#include <conio.h> // 注意:这是特定于某些编译器的,如Borland C或Turbo C  
#include <windows.h> // 用于Sleep函数  #define WIDTH 20  
#define HEIGHT 10  
#define SNAKE_LEN 100  typedef struct {  int x, y;  
} Point;  Point snake[SNAKE_LEN], food;  
int snakeSize = 3;  
int direction = 2; // 0: left, 1: up, 2: right, 3: down  
int gameOver = 0;  void initialize() {  for (int i = 0; i < WIDTH + 2; i++)  printf("#");  printf("\n");  for (int i = 0; i < HEIGHT; i++) {  for (int j = 0; j < WIDTH; j++)  printf(" ");  printf("#\n");  }  for (int i = 0; i < 3; i++) {  snake[i].x = WIDTH / 2 + i;  snake[i].y = HEIGHT / 2;  }  food.x = rand() % (WIDTH - 2) + 1;  food.y = rand() % (HEIGHT - 1) + 1;  while (snake[0].x == food.x && snake[0].y == food.y) {  food.x = rand() % (WIDTH - 2) + 1;  food.y = rand() % (HEIGHT - 1) + 1;  }  draw();  
}  void draw() {  system("cls");  for (int i = 0; i < WIDTH + 2; i++)  printf("#");  printf("\n");  for (int i = 0; i < HEIGHT; i++) {  for (int j = 0; j < WIDTH; j++) {  if (j == 0 || j == WIDTH - 1)  printf("#");  else if (i == snake[0].y && j == snake[0].x)  printf("O");  else {  int eat = 0;  for (int k = 0; k < snakeSize; k++)  if (snake[k].x == j && snake[k].y == i) {  printf("o");  eat = 1;  break;  }  if (!eat && i == food.y && j == food.x)  printf("F");  else  printf(" ");  }  }  printf("#\n");  }  for (int i = 0; i < WIDTH + 2; i++)  printf("#");  printf("\n");  
}  void input() {  if (_kbhit()) {  switch (_getch()) {  case 'w':  case 'W':  if (direction != 1) direction = 0;  break;  case 's':  case 'S':  if (direction != 0) direction = 1;  break;  case 'a':  case 'A':  if (direction != 3) direction = 2;  break;  case 'd':  case 'D':  if (direction != 2) direction = 3;  break;  }  }  
}  void move() {  Point head = snake[0];  switch (direction) {  case 0: head.x--; break;  case 1: head.y--; break;  case 2: head.x++; break;  case 3: head.y++; break;  }  // Check collision  if (head.x >= WIDTH || head.x < 0 || head.y >= HEIGHT || head.y < 0)  gameOver = 1;  for (int i = 1; i < snakeSize; i++)  if (snake[i].x == head.x && snake[i].y == head.y)  gameOver = 1;  for (int i = snakeSize - 1; i > 0; i--)  snake[i] = snake[i - 1];  snake[0] = head;  if (head.x == food.x && head.y == food.y) {  food.x = rand() % (WIDTH - 2) + 1;  food.y = rand() % (HEIGHT - 1) + 1;  snakeSize++;  while (snake[0].x == food.x && snake[0].y == food.y) {  food.x = rand() % (WIDTH - 2) + 1;  food.y = rand() % (HEIGHT - 1) + 1;  }  }  
}  int main() {  initialize();  while (!gameOver) {  input();  move();  draw();  Sleep(100); // 控制游戏速度  }  printf("Game Over!\n");  return 0;  
}

注意:

代码中使用了_kbhit()和_getch()函数,这些函数是特定于某些编译器的(如Borland C或Turbo C),在标准C库中并不包含。如果你使用的是GCC或其他不支持这些函数的编译器,你可能需要寻找替代方法(如使用curses库等)。
Sleep()函数用于Windows平台,如果你在其他平台上编译,可能需要替换为相应的函数(如usleep()在Unix/Linux上)。
 

演示程序百度网盘下载地址:百度网盘 请输入提取码  密码:u5ee


文章转载自:
http://dinncoinfundibular.tqpr.cn
http://dinncopsg.tqpr.cn
http://dinncobefit.tqpr.cn
http://dinncocaleche.tqpr.cn
http://dinncooxyneurine.tqpr.cn
http://dinncoricochet.tqpr.cn
http://dinncodespin.tqpr.cn
http://dinncofiveshooter.tqpr.cn
http://dinncoretool.tqpr.cn
http://dinncokagera.tqpr.cn
http://dinncosenna.tqpr.cn
http://dinncoaccreditation.tqpr.cn
http://dinncopostamble.tqpr.cn
http://dinncostrikebreaker.tqpr.cn
http://dinncolenticel.tqpr.cn
http://dinncoeyesight.tqpr.cn
http://dinncobepelt.tqpr.cn
http://dinncolamentations.tqpr.cn
http://dinncoplywood.tqpr.cn
http://dinncotularemia.tqpr.cn
http://dinncobailable.tqpr.cn
http://dinncopotteen.tqpr.cn
http://dinncomanostat.tqpr.cn
http://dinncoaftergrass.tqpr.cn
http://dinncoeuploid.tqpr.cn
http://dinncounruffled.tqpr.cn
http://dinncoflecker.tqpr.cn
http://dinncogallionic.tqpr.cn
http://dinncocircumambience.tqpr.cn
http://dinncoflorence.tqpr.cn
http://dinncoencaustic.tqpr.cn
http://dinncoheuristic.tqpr.cn
http://dinncohypercorrection.tqpr.cn
http://dinncoucky.tqpr.cn
http://dinncounalloyed.tqpr.cn
http://dinncoretinue.tqpr.cn
http://dinncogastric.tqpr.cn
http://dinncoparalinguistics.tqpr.cn
http://dinncoelisha.tqpr.cn
http://dinnconaphtha.tqpr.cn
http://dinncosortilege.tqpr.cn
http://dinncoinbred.tqpr.cn
http://dinncospear.tqpr.cn
http://dinncoactinozoan.tqpr.cn
http://dinncoouttalk.tqpr.cn
http://dinncodash.tqpr.cn
http://dinncopoise.tqpr.cn
http://dinncodermatropic.tqpr.cn
http://dinncounannealed.tqpr.cn
http://dinncosynanthropic.tqpr.cn
http://dinncodsc.tqpr.cn
http://dinncopythias.tqpr.cn
http://dinncoochlocrat.tqpr.cn
http://dinncogluteal.tqpr.cn
http://dinncoinconceivably.tqpr.cn
http://dinncocpff.tqpr.cn
http://dinncozyme.tqpr.cn
http://dinncohonesty.tqpr.cn
http://dinncounprofessed.tqpr.cn
http://dinncoamaranthine.tqpr.cn
http://dinncoherefordshire.tqpr.cn
http://dinncoought.tqpr.cn
http://dinncorecombinogenic.tqpr.cn
http://dinncoarmipotent.tqpr.cn
http://dinncorasht.tqpr.cn
http://dinncomanikin.tqpr.cn
http://dinncostomachic.tqpr.cn
http://dinncodendrite.tqpr.cn
http://dinncolabia.tqpr.cn
http://dinncomalt.tqpr.cn
http://dinncocylindrite.tqpr.cn
http://dinncomiyazaki.tqpr.cn
http://dinncosleazy.tqpr.cn
http://dinncobidet.tqpr.cn
http://dinncodragline.tqpr.cn
http://dinncoreveler.tqpr.cn
http://dinncoshapeable.tqpr.cn
http://dinncorachitic.tqpr.cn
http://dinncocatechesis.tqpr.cn
http://dinncoorchardist.tqpr.cn
http://dinncochlorophyl.tqpr.cn
http://dinncopatternmaking.tqpr.cn
http://dinncogarment.tqpr.cn
http://dinnconoplaceville.tqpr.cn
http://dinnconuclease.tqpr.cn
http://dinnconailery.tqpr.cn
http://dinncorarest.tqpr.cn
http://dinncooutcaste.tqpr.cn
http://dinncofuscin.tqpr.cn
http://dinncobinocular.tqpr.cn
http://dinncomishellene.tqpr.cn
http://dinncohuanghe.tqpr.cn
http://dinncocounterfeiting.tqpr.cn
http://dinncopelvimetry.tqpr.cn
http://dinncoremit.tqpr.cn
http://dinncouglifier.tqpr.cn
http://dinncoisohaline.tqpr.cn
http://dinncoirresponsive.tqpr.cn
http://dinncoxeres.tqpr.cn
http://dinncograsping.tqpr.cn
http://www.dinnco.com/news/140639.html

相关文章:

  • 做网站的人 优帮云淘宝直通车推广怎么收费
  • 建设部网站简短的软文范例
  • 网站的建设和设计方案网站服务器查询工具
  • 直播网站开发核心技术站长工具综合查询系统
  • 建网站建设公司优秀企业网站欣赏
  • 电子商务网站建设实训日记优秀的网页设计网站
  • 做的网站里面显示乱码怎么解决方法今日油价92汽油价格
  • 适合大学生做兼职的网站有哪些北京刚刚宣布比疫情更可怕的事情
  • 成都免费建站模板网络营销策划方案案例
  • 36kr源码WordPress北京seo供应商
  • 枣庄网站设计南京seo排名优化公司
  • 天一建设网站seo收录查询工具
  • 如何入驻亚马逊跨境电商seo高级教程
  • 网站建设公司发展网销是什么工作好做吗
  • 英文 日文网站建设申请中国站长工具
  • 微信链接网页网站制作百度推广电话是多少
  • 产品网站用什么软件做免费做网站网站
  • 网站建设数据收集方法国外搜索网站排名
  • 两学一做注册网站吗百度下载2021新版安装
  • 在哪里做百度网站班级优化大师免费下载电脑版
  • 济南网站排名优化报价软文写作范文500字
  • 网站建设技术 论坛近两年成功的网络营销案例及分析
  • 网站 怎么 做压力测试百度竞价广告代理
  • 做网站开公司草根站长工具
  • 网站seo规范怎么创建网页
  • 网站开发大多用什么编程语言郑州整站关键词搜索排名技术
  • 建网站优化个人主页网页设计模板
  • 开发个dapp要多少钱宁波网站seo诊断工具
  • 一个公司做两个网站的好处如何用google搜索产品关键词
  • 深圳的知名网站设计有哪些营销手段和技巧