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

外贸品牌网站设计在线网站编辑

外贸品牌网站设计,在线网站编辑,欧美风格的网页设计欣赏,网站如何有排名准备步骤 项目开发使用【Mu 编辑器】 1.新建项目#xff0c;并导入游戏图片 游戏编写 1.创建场景 SIZE 15 # 每个格子的大小 WIDTH SIZE * 30 # 游戏场景总宽度 HEIGHT SIZE * 30 # 游戏场景总高度def draw():screen…准备步骤 项目开发使用【Mu 编辑器】 1.新建项目并导入游戏图片 游戏编写 1.创建场景 SIZE 15 # 每个格子的大小 WIDTH SIZE * 30 # 游戏场景总宽度 HEIGHT SIZE * 30 # 游戏场景总高度def draw():screen.fill((255,255,255)) # 设置背景色为白色运行游戏可见一个简单的场景被绘制出来 2.创建主角 snake_head Actor(snake_head,(30, 30)) # 绘制蛇头图标初始坐标为3030def draw():screen.fill((255,255,255)) snake_head.draw() # 绘制蛇头运行后场景中可见多了一个蛇头图标 3.移动蛇头 direction R # 蛇头初始移动方向 counter 0 # 循环标识控制蛇头位置变更频率 # 监测按下的按键 def check_keys():global direction# ←键被按下且当前方向不为向右if keyboard.left and direction ! R:direction L# →键被按下且当前方向不为向左elif keyboard.right and direction ! L:direction R# ↑键被按下且当前方向不为向下elif keyboard.up and direction ! D:direction U# ↓键被按下且当前方向不为向上elif keyboard.down and direction ! U:direction D # 蛇头移动位置逻辑 def update_snake(): global countercounter 1# 每执行10次update函数才执行一次下方代码减缓蛇头位置变更速度if counter 10:returnelse:counter 0# 蛇头移动逻辑改变蛇头位置实现移动效果if direction L:snake_head.x - SIZEelif direction R:snake_head.x SIZEelif direction U:snake_head.y - SIZEelif direction D:snake_head.y SIZE def update():check_keys()update_snake()此刻开始游戏蛇头就会开始移动按下方向键便会改变蛇头移动方向 可使用angle属性控制图标翻转,实现蛇头朝向效果 # 监测按下的按键 def check_keys():global direction# ←键被按下且当前方向不为向右if keyboard.left and direction ! R:direction Lsnake_head.angle 0# →键被按下且当前方向不为向左elif keyboard.right and direction ! L:direction Rsnake_head.angle 180# ↑键被按下且当前方向不为向下elif keyboard.up and direction ! D:direction Usnake_head.angle 90# ↓键被按下且当前方向不为向上elif keyboard.down and direction ! U:direction Dsnake_head.angle -904.添加食物 food Actor(snake_food) # 在窗口内生成随机坐标作为食物出现的位置 food.x random.randint(2,WIDTH // SIZE - 2) * SIZE food.y random.randint(2,HEIGHT // SIZE - 2) * SIZEdef draw():screen.fill((255,255,255)) snake_head.draw()food.draw() # 绘制食物此时运行游戏窗口中会随机生成食物但蛇头触碰并不会被吃掉 5.吃食物 length 1 # 贪吃蛇当前的初始长度 body [] # 贪吃蛇蛇身各部位位置不含蛇头 # draw函数中添加蛇身绘制方法 def draw():screen.fill((255,255,255)) snake_head.draw() food.draw() # 通过循环列表绘制出所有蛇身for b in body:b.draw() # 蛇头移动位置逻辑中增加蛇身移动逻辑 def update_snake():global countercounter 1if counter 10:returnelse:counter 0# 如果蛇身数量等于蛇的总长度则移除列表记录的第一个蛇身实际是移除蛇尾if len(body) length:body.remove(body[0])# 在列表后追加当前蛇头的坐标用于绘制新的蛇身配合上面删除实现蛇身位置变更效果body.append(Actor(snake_body,(snake_head.x, snake_head.y)))if direction L:snake_head.x - SIZEelif direction R:snake_head.x SIZEelif direction U:snake_head.y - SIZEelif direction D:snake_head.y SIZE # 吃食物逻辑 def eat_food():global length# 如果当前食物坐标与蛇头坐标位置重叠if food.x snake_head.x and food.y snake_head.y:# 在窗口内随机坐标位置重新生成食物food.x random.randint(2,WIDTH // SIZE - 2) * SIZEfood.y random.randint(2,HEIGHT // SIZE - 2) * SIZElength 1 # 每吃一个食物贪吃蛇长度1 # 将eat_food方法写入update中 def update():check_keys()update_snake()eat_food()6.游戏结束判定 finished False # 游戏结束标识 # draw函数中添加失败弹窗 def draw():screen.fill((255,255,255)) snake_head.draw() food.draw() for b in body:b.draw()# 绘制失败提示图像if finished:screen.draw.text(Game Over!,center(WIDTH // 2,HEIGHT // 2),fontsize 50,color red) # 检测游戏是否结束 def check_gameover():global finished# 如果蛇头的位置超出窗口则判定失败if snake_head.left 0 or snake_head.right WIDTH or snake_head.top 0 or snake_head.bottom HEIGHT:finished True# 遍历蛇身判断是否存在与蛇头重叠的蛇身有则判定失败for n in range(len(body) - 1):if(body[n].x snake_head.x and body[n].y snake_head.y):finished True # update函数中调用检测方法 def update():# 如果游戏已结束则不再更新游戏即暂停游戏 if finished:returncheck_gameover()check_keys()eat_food()update_snake()运行游戏后当蛇头碰到蛇身或墙壁则会暂停游戏弹窗游戏失败提示语 完整代码 import random SIZE 15 # 每个格子的大小 WIDTH SIZE * 30 # 游戏场景总宽度 HEIGHT SIZE * 30 # 游戏场景总高度 direction R # 蛇头初始移动方向 counter 0 # 循环标识 snake_head Actor(snake_head,(30, 30)) # 绘制蛇头图标初始坐标为3030 length 1 # 贪吃蛇当前的初始长度 body [] # 贪吃蛇蛇身各部位位置不含蛇头 finished False # 游戏结束标识food Actor(snake_food) # 在窗口内生成随机坐标作为食物出现的位置 food.x random.randint(2,WIDTH // SIZE - 2) * SIZE food.y random.randint(2,HEIGHT // SIZE - 2) * SIZEdef draw():screen.fill((255,255,255)) # 设置背景色为白色snake_head.draw() # 绘制蛇头food.draw() # 绘制食物# 通过循环列表绘制出所有蛇身for b in body:b.draw()# 绘制失败提示图像if finished:screen.draw.text(Game Over!,center(WIDTH // 2,HEIGHT // 2),fontsize 50,color red)# 监测按下的按键 def check_keys():global direction# ←键被按下且当前方向不为向右if keyboard.left and direction ! R:direction Lsnake_head.angle 180# →键被按下且当前方向不为向左elif keyboard.right and direction ! L:direction Rsnake_head.angle 0# ↑键被按下且当前方向不为向下elif keyboard.up and direction ! D:direction Usnake_head.angle 90# ↓键被按下且当前方向不为向上elif keyboard.down and direction ! U:direction Dsnake_head.angle -90# 贪吃蛇移动位置各部位变化逻辑 def update_snake():global countercounter 1# 每执行10次update函数才执行一次下方代码减缓蛇头位置变更速度if counter 10:returnelse:counter 0# 如果蛇身数量等于蛇的总长度则移除列表记录的第一个蛇身实际是移除蛇尾if len(body) length:body.remove(body[0])# 在列表后追加当前蛇头的坐标用于绘制新的蛇身配合上面删除实现蛇身位置变更效果body.append(Actor(snake_body,(snake_head.x, snake_head.y)))# 蛇头移动逻辑改变蛇头位置实现移动效果if direction L:snake_head.x - SIZEelif direction R:snake_head.x SIZEelif direction U:snake_head.y - SIZEelif direction D:snake_head.y SIZE# 吃食物 def eat_food():global length# 如果当前食物坐标与蛇头坐标位置重叠if food.x snake_head.x and food.y snake_head.y:# 在窗口内随机坐标位置重新生成食物food.x random.randint(2,WIDTH // SIZE - 2) * SIZEfood.y random.randint(2,HEIGHT // SIZE - 2) * SIZElength 1 # 每吃一个食物贪吃蛇长度1 # 检测游戏是否结束 def check_gameover():global finished# 如果蛇头的位置超出窗口则判定失败if snake_head.left 0 or snake_head.right WIDTH or snake_head.top 0 or snake_head.bottom HEIGHT:finished True# 遍历蛇身判断是否存在与蛇头重叠的蛇身有则判定失败for n in range(len(body) - 1):if(body[n].x snake_head.x and body[n].y snake_head.y):finished True def update():# 如果游戏已结束则不再更新游戏即暂停游戏 if finished:returncheck_gameover()check_keys()eat_food()update_snake()
http://www.hkea.cn/news/14345809/

相关文章:

  • 足球比分网站怎么建设自己做网站的软件
  • 在安阳想建个网站怎么做如何进行产品开发
  • 济南网站怎么做seo是网站建设
  • 网站被百度惩罚放弃汕尾建设网站首页
  • 织梦网站定时树莓派wordpress博客
  • 香蜜湖网站建设微信视频号推广方法
  • 资源优化排名网站网站开发各年的前景
  • 网站基础建设英文翻译专门做网站的科技公司
  • 建设网站群套餐型网站建设合同
  • 做网站怎么开发客户源苏州网站建设自助建站模板
  • 哈尔滨营销型网站建设室内设计应届生简历
  • 上海网站公司设计网页访问紧急升级
  • 经典企业网站模板怎么制作网页步骤
  • 临漳网站建站百度排名工具
  • 网站建设怎么弄莱芜金点子广告电子版2022最新
  • 单位网站源码住建部禾建设部是一个网站吗
  • 泊头网站制作案例wordpress 交友
  • 弄一个网站网站官网建设的价格
  • 业务推广网站网站关键词优化的步骤
  • 网站模版切换网站全屏宽度是多少
  • 凡科可以做淘宝客网站吗提交链接
  • 做方案的网站月夜影视在线观看免费完整版
  • 哪些网站可以做平面设计wordpress弹出聊天
  • 上海网站建设外贸多功能创意产品设计
  • c 网站开发环境wordpress前台修改密码
  • 大朗网站建设公司nas ddnsto wordpress
  • 临安区规划建设局网站建设商务网站
  • 惠州网页建站模板网站域名 被别人备案
  • 镇江网站建设价格cad dwt模板做网站模版
  • 乐都企业网站建设网站建设策划书格式及范文