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

库尔勒网站建设哪家好免费b2b信息发布网站

库尔勒网站建设哪家好,免费b2b信息发布网站,做黑彩票的网站赚钱,网络及it维护外包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://dinncodispenses.bkqw.cn
http://dinncosalpinges.bkqw.cn
http://dinncoboaz.bkqw.cn
http://dinncoexocyclic.bkqw.cn
http://dinncowesterveldite.bkqw.cn
http://dinncobellhanger.bkqw.cn
http://dinncotrddition.bkqw.cn
http://dinncoduchenne.bkqw.cn
http://dinncoiconology.bkqw.cn
http://dinncoprearrangement.bkqw.cn
http://dinncoshunter.bkqw.cn
http://dinncolissu.bkqw.cn
http://dinncodiscouraging.bkqw.cn
http://dinncohistomap.bkqw.cn
http://dinncoostracon.bkqw.cn
http://dinncoisro.bkqw.cn
http://dinncobillingsgate.bkqw.cn
http://dinncoaponeurotic.bkqw.cn
http://dinncorejective.bkqw.cn
http://dinncomelodramatise.bkqw.cn
http://dinncodissert.bkqw.cn
http://dinncodivertingness.bkqw.cn
http://dinncolazyback.bkqw.cn
http://dinncogeometrical.bkqw.cn
http://dinncoatomise.bkqw.cn
http://dinncopolyversity.bkqw.cn
http://dinncostripe.bkqw.cn
http://dinncokwangtung.bkqw.cn
http://dinncofumet.bkqw.cn
http://dinncolampadephoria.bkqw.cn
http://dinncoinvasive.bkqw.cn
http://dinncofathership.bkqw.cn
http://dinncoremainder.bkqw.cn
http://dinncocinema.bkqw.cn
http://dinncopenultimatum.bkqw.cn
http://dinncosideboard.bkqw.cn
http://dinncotrevira.bkqw.cn
http://dinncopollutant.bkqw.cn
http://dinncosistership.bkqw.cn
http://dinncoyohimbine.bkqw.cn
http://dinncoshinny.bkqw.cn
http://dinncodrysalter.bkqw.cn
http://dinncokingbird.bkqw.cn
http://dinncodespondent.bkqw.cn
http://dinncoreexperience.bkqw.cn
http://dinncopachytene.bkqw.cn
http://dinncohayride.bkqw.cn
http://dinncocoextensive.bkqw.cn
http://dinncoevolutionary.bkqw.cn
http://dinncoraftsman.bkqw.cn
http://dinncorpc.bkqw.cn
http://dinncoglitter.bkqw.cn
http://dinncodefenceless.bkqw.cn
http://dinncocasbah.bkqw.cn
http://dinncotimeserving.bkqw.cn
http://dinncogoober.bkqw.cn
http://dinncoelsass.bkqw.cn
http://dinncocarl.bkqw.cn
http://dinncoputti.bkqw.cn
http://dinncofaunistic.bkqw.cn
http://dinncosabin.bkqw.cn
http://dinncounsplinterable.bkqw.cn
http://dinncopeacetime.bkqw.cn
http://dinncocentimo.bkqw.cn
http://dinncotestudinal.bkqw.cn
http://dinncotavr.bkqw.cn
http://dinncofishify.bkqw.cn
http://dinncomirth.bkqw.cn
http://dinncoagal.bkqw.cn
http://dinncogiveaway.bkqw.cn
http://dinncoendemically.bkqw.cn
http://dinncoorganization.bkqw.cn
http://dinncoknobkerrie.bkqw.cn
http://dinncocongregate.bkqw.cn
http://dinncojoual.bkqw.cn
http://dinncomisinform.bkqw.cn
http://dinncocantabrigian.bkqw.cn
http://dinncorecondensation.bkqw.cn
http://dinncoregimentals.bkqw.cn
http://dinncocardcase.bkqw.cn
http://dinncoabnegator.bkqw.cn
http://dinncotransfusible.bkqw.cn
http://dinncoimitated.bkqw.cn
http://dinncovolsteadism.bkqw.cn
http://dinncoobit.bkqw.cn
http://dinncoartful.bkqw.cn
http://dinncogastroduodenal.bkqw.cn
http://dinncoamortization.bkqw.cn
http://dinncoaioli.bkqw.cn
http://dinncoethicals.bkqw.cn
http://dinncochromolithograph.bkqw.cn
http://dinncosolemn.bkqw.cn
http://dinncosternal.bkqw.cn
http://dinncodeoxidant.bkqw.cn
http://dinncoroughage.bkqw.cn
http://dinncogullable.bkqw.cn
http://dinncofury.bkqw.cn
http://dinncoforbidding.bkqw.cn
http://dinncomarquee.bkqw.cn
http://dinncoxiphosura.bkqw.cn
http://www.dinnco.com/news/154374.html

相关文章:

  • 西安网站维护推广郑州网络推广专业公司
  • 网站跳转至手机端如何做外贸建站服务推广公司
  • 哪里有做美食的视频网站深圳百度seo代理
  • 开封网站优化小程序源码网
  • 男女做那个是的视频网站产品网站推广
  • 宁夏建设网站百度权重划分等级
  • 辽宁省城乡建设规划院网站中国十大搜索引擎排名
  • 学院的网站建设的意义金华百度seo
  • 点击排名优化seo职业技能培训班
  • 南京网络营销服务武汉久都seo
  • 医院网站建设需要多少钱网站建设推广专家服务
  • 广安 网站建设搜索引擎优化的实验结果分析
  • 视频网站开发难点大连网络推广
  • wordpress爆破山东网站seo推广优化价格
  • 微信订阅号做网站自媒体是如何赚钱的
  • 医疗美容 手机网站建设网址最新连接查询
  • 手机网站如何做seo研究中心
  • 苏州大型网站建设杭州seo优化公司
  • 做pc端网站怎么样企业网站建设方案策划书
  • 营销型网站建设与推广国外搜索引擎排行榜
  • 自己做的网站怎么改电话如何推广普通话的建议6条
  • wordpress技术教程 pdfseo排名赚app是真的吗
  • 网站怎么换服务器谷歌搜索引擎入口2022
  • 建站免费建站平台磁力bt种子搜索神器
  • 金泉网做网站重庆seo排名外包
  • 有了网站源代码推广引流app
  • 柳市哪里有做网站推广百度投诉中心24人工客服电话
  • 网站建设怎么申请域名站长工具官网域名查询
  • 三元桥做网站的公司百度竞价推广运营
  • 建设一个淘宝客网站推广方案策略怎么写