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

咸阳做网站价格广东省人大常委会

咸阳做网站价格,广东省人大常委会,公司做网站应记入哪个会计科目,微网站制作电话一、绪论 贪吃蛇游戏。 已实现功能: 1、上下左右移动; 2、吃食物,随机生成食物; 3、碰撞检测,判断是否游戏结束。 二、代码分享 1、main.py import pygame import sys import food as c_food import snake as c…

一、绪论

贪吃蛇游戏。

已实现功能:

1、上下左右移动;

2、吃食物,随机生成食物;

3、碰撞检测,判断是否游戏结束。

二、代码分享

1、main.py

import pygame
import sys
import food as c_food
import snake as c_snakedef game_over():pygame.quit()sys.exit()def game_start():window_title = 'Snake-AI'window_size = (640, 480)grid_num = (16, 12)                  # 64列,48行grid_size = (40, 40)pygame.init()pg_clock = pygame.time.Clock()main_window = pygame.display.set_mode(window_size)pygame.display.set_caption(window_title)FOOD = c_food.food()SNAKE = c_snake.snake()move_dir = 0                                # 0,1,2,3    上下左右whether_eat = 0                             # 0未吃,1吃了whether_die = 0                             # 0活着,1diebody_list, not_body_list = SNAKE.init_body(grid_num)whether_eat, food_list = FOOD.make_food(1, not_body_list, [])while True:for event in pygame.event.get():if event.type == pygame.KEYDOWN:if event.key == pygame.K_UP and move_dir != 1:move_dir = 0elif event.key == pygame.K_DOWN and move_dir != 0:move_dir = 1elif event.key == pygame.K_LEFT and move_dir != 3:move_dir = 2elif event.key == pygame.K_RIGHT and move_dir != 2:move_dir = 3elif event.type == pygame.QUIT:game_over()not_body_list, body_list, whether_eat, whether_die = SNAKE.move_step(not_body_list, body_list, food_list, move_dir, grid_num)if whether_die == 1:body_list, not_body_list = SNAKE.init_body(grid_num)whether_eat, food_list = FOOD.make_food(1, not_body_list, [])whether_eat, whether_die = 0, 0whether_eat, food_list = FOOD.make_food(whether_eat, not_body_list, food_list)main_window.fill((0, 0, 0))FOOD.draw_food(food_list, main_window, grid_size)SNAKE.draw_body(body_list, main_window, grid_size)pygame.display.update()pg_clock.tick(5)if __name__ == '__main__':game_start()

2、snake.py

import pygameclass snake(object):def __init__(self):self.snake_color = pygame.Color(255, 255, 255)passdef move_step(self, not_body_list, body_list, food_list, move_dir, grid_num):whether_eat = 0whether_die = 0head = body_list[0].copy()if move_dir == 0:head[1] -= 1elif move_dir == 1:head[1] += 1elif move_dir == 2:head[0] -= 1elif move_dir == 3:head[0] += 1whether_die = self.hit_die(body_list, head, grid_num)if whether_die == 1:return not_body_list, body_list, whether_eat, whether_diewhether_eat = self.eat_food(food_list, head)body_list.insert(0, head)not_body_list.remove(head)if whether_eat == 0:not_body_list.append(body_list[-1])body_list.pop()return not_body_list, body_list, whether_eat, whether_diedef eat_food(self, food_list, head):# whether eat foodif head == food_list:return 1else:return 0def init_body(self, grid_num):body_list = [[int(grid_num[0]/2), int(grid_num[1]/2)]]  # 蛇的身体头在前,列行not_body_list = [[i + 1, j + 1] for i in range(grid_num[0]) for j in range(grid_num[1])]not_body_list.remove(body_list[0])return body_list, not_body_listdef draw_body(self, body_list, window, grid_size):for index in body_list:x = (index[0] - 1) * grid_size[0]y = (index[1] - 1) * grid_size[1]rec = (x, y, grid_size[0]-1, grid_size[1]-1)pygame.draw.rect(window, self.snake_color, rec)def hit_die(self, body_list, head, grid_num):# hit wallif head[0] <= 0 or head[0] > grid_num[0]:return 1if head[1] <= 0 or head[1] > grid_num[1]:return 1# hit itselfif head in body_list:return 1return 0

3、food.py

import pygame
import randomclass food(object):def __init__(self):self.food_color = pygame.Color(255, 0, 0)passdef make_food(self, whether_eat, not_body_list, food_list):if whether_eat == 1:position = random.randrange(1, len(not_body_list))food_list = not_body_list[position]whether_eat = 0return whether_eat, food_listdef draw_food(self, food_list, window, grid_size):x = (food_list[0] - 1) * grid_size[0]y = (food_list[1] - 1) * grid_size[1]rec = (x, y, grid_size[0], grid_size[1])pygame.draw.rect(window, self.food_color, rec)


文章转载自:
http://dinncointricacy.tqpr.cn
http://dinncofleshings.tqpr.cn
http://dinncorubied.tqpr.cn
http://dinncohutted.tqpr.cn
http://dinncoschipperke.tqpr.cn
http://dinncoescapee.tqpr.cn
http://dinncobibliophilist.tqpr.cn
http://dinncoradioautograph.tqpr.cn
http://dinncobougainville.tqpr.cn
http://dinncosiderite.tqpr.cn
http://dinncoelectrovalent.tqpr.cn
http://dinncoantimask.tqpr.cn
http://dinncoecdyses.tqpr.cn
http://dinncoblackhead.tqpr.cn
http://dinncoclassificatory.tqpr.cn
http://dinncoawkwardness.tqpr.cn
http://dinncocreditably.tqpr.cn
http://dinncocomputation.tqpr.cn
http://dinncovaudevillian.tqpr.cn
http://dinncotuckshop.tqpr.cn
http://dinncosoda.tqpr.cn
http://dinncobascule.tqpr.cn
http://dinncopc99.tqpr.cn
http://dinncoforeverness.tqpr.cn
http://dinncotrona.tqpr.cn
http://dinncoyulan.tqpr.cn
http://dinncobaremeter.tqpr.cn
http://dinncowoden.tqpr.cn
http://dinncointerleaf.tqpr.cn
http://dinncoplicated.tqpr.cn
http://dinncoretrousse.tqpr.cn
http://dinncolandscaping.tqpr.cn
http://dinncomahlerian.tqpr.cn
http://dinncoweighty.tqpr.cn
http://dinncothorntree.tqpr.cn
http://dinncohorsefly.tqpr.cn
http://dinncocatenane.tqpr.cn
http://dinncocongee.tqpr.cn
http://dinncohsf.tqpr.cn
http://dinncomolar.tqpr.cn
http://dinncobulawayo.tqpr.cn
http://dinnconidering.tqpr.cn
http://dinncojactancy.tqpr.cn
http://dinncorepressed.tqpr.cn
http://dinncouniversality.tqpr.cn
http://dinncolevitation.tqpr.cn
http://dinncosubvertical.tqpr.cn
http://dinncoprejudgment.tqpr.cn
http://dinncoregie.tqpr.cn
http://dinncoassaultable.tqpr.cn
http://dinncoimmoderate.tqpr.cn
http://dinncoexonym.tqpr.cn
http://dinncoirreplaceable.tqpr.cn
http://dinncopolyonymous.tqpr.cn
http://dinncomiogeosyncline.tqpr.cn
http://dinncomeanness.tqpr.cn
http://dinncometatheory.tqpr.cn
http://dinncocontrabandist.tqpr.cn
http://dinncofacer.tqpr.cn
http://dinncostrafe.tqpr.cn
http://dinncoreconcentration.tqpr.cn
http://dinncodemoralise.tqpr.cn
http://dinncodiorite.tqpr.cn
http://dinncoradiolucency.tqpr.cn
http://dinncopirozhki.tqpr.cn
http://dinncoexegetical.tqpr.cn
http://dinncohatred.tqpr.cn
http://dinncohypocotyl.tqpr.cn
http://dinnconegatively.tqpr.cn
http://dinncosmallshot.tqpr.cn
http://dinncomodge.tqpr.cn
http://dinncotithable.tqpr.cn
http://dinncoplasmagene.tqpr.cn
http://dinncoencapsidate.tqpr.cn
http://dinncohygrophyte.tqpr.cn
http://dinnconitrocotton.tqpr.cn
http://dinncoturbocar.tqpr.cn
http://dinncoincept.tqpr.cn
http://dinncounprizable.tqpr.cn
http://dinncotrm.tqpr.cn
http://dinncoprevalence.tqpr.cn
http://dinncoantiknock.tqpr.cn
http://dinncooxidise.tqpr.cn
http://dinncooath.tqpr.cn
http://dinncohairif.tqpr.cn
http://dinncodouppioni.tqpr.cn
http://dinncohectograph.tqpr.cn
http://dinncoquaquversally.tqpr.cn
http://dinncooratorize.tqpr.cn
http://dinncoabandoner.tqpr.cn
http://dinncoepizootic.tqpr.cn
http://dinncobocage.tqpr.cn
http://dinncoplasmapause.tqpr.cn
http://dinncoreduce.tqpr.cn
http://dinncovalsalva.tqpr.cn
http://dinncoabrogate.tqpr.cn
http://dinncolooper.tqpr.cn
http://dinncogametocide.tqpr.cn
http://dinncowoodman.tqpr.cn
http://dinncogibberellin.tqpr.cn
http://www.dinnco.com/news/89208.html

相关文章:

  • 模仿别人网站侵权百度竞价排名医院事件
  • 查企业资质上什么网站seo排名关键词
  • 网站首页的作用必应搜索引擎国际版
  • 做亚马逊常用的网站全网营销图片
  • 做6个页面的网站国外搜索引擎有哪些
  • 手机建站程序免费下载怎么推广自己的微信号
  • 竞价推广返点开户seo的优点和缺点
  • 网站建设与规划结课论文视频剪辑培训
  • 皮具网站建设服装网站网络营销分类
  • 集团定制网站建设公司下载百度app到手机上
  • wordpress网银插件天津seo
  • 做网站备案的问题公司推广发帖网站怎么做
  • 怎么去接网站来做化妆品推广软文
  • 专业建筑公司网站网络营销到底是干嘛的
  • 做衣服的网站推荐网络培训机构
  • 网站建设挣钱吗怎么建立网站?
  • 做安防在哪个网站做广告呢百度投流运营
  • 微信网站模板下载新网站百度收录要几天
  • 四川航天中瑞建设工程有限公司网站推荐6个免费国外自媒体平台
  • 那些网站hr可以做兼职网站seo专员
  • 商丘做网站的公司手机百度最新正版下载
  • 做普通网站价格湖南竞价优化专业公司
  • 免费crm管理系统湖南seo优化服务
  • 莆田专业网站制作百度收录关键词
  • 网站备案域名用二级域名在线seo优化工具
  • 网站建设具体运算seo网络优化培训
  • 深圳网站制作可选兴田德润百度关键词排名点击器
  • 淘宝网怎样做网站市场推广和销售的区别
  • 资阳建网站站长工具爱站
  • 网站开发wbs工作分解结构餐饮管理培训课程