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

微信公众号微官网怎么做seo描述是什么意思

微信公众号微官网怎么做,seo描述是什么意思,网站保持排名,电脑网页打不开但是可以上网俄罗斯方块简单实现 使用 pygame 模块实现俄罗斯方块的简单实现,这里没有使用pygame 自带的碰撞检测,而是自定义的方法实现边界碰撞和方块间碰撞检测。 代码实现 import random import pygame import time # 初始化游戏 pygame.init()# 设置游戏窗口大…

俄罗斯方块简单实现

使用 pygame 模块实现俄罗斯方块的简单实现,这里没有使用pygame 自带的碰撞检测,而是自定义的方法实现边界碰撞和方块间碰撞检测。

代码实现

import random
import pygame
import time
# 初始化游戏
pygame.init()# 设置游戏窗口大小
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 600
WINDOW_SIZE = (WINDOW_WIDTH, WINDOW_HEIGHT)# 设置游戏窗口标题
pygame.display.set_caption("俄罗斯方块")# 设置游戏窗口
screen = pygame.display.set_mode(WINDOW_SIZE)# 定义方块大小和颜色
BLOCK_SIZE = 20
BLOCK_COLOR = (255, 255, 255)# 定义方块类
class Block:def __init__(self, x, y):self.x = xself.y = ydef draw(self, color):pygame.draw.rect(screen, color, (self.x, self.y, BLOCK_SIZE, BLOCK_SIZE))# 定义方块组类
class BlockGroup:block_groups = list()shape_set = {"1": [(0, 1), (0, 2), (0, 3)],"一": [(1, 0), (2, 0), (3, 0)],"T": [(1, 0), (1, 1), (2, 0)],"Z": [(1, 0), (1, 1), (2, 1)],"田": [(1, 0), (0, 1), (1, 1)],"L": [(0, 1), (0, 2), (1, 2)],}bottom_boundary_points = set()def __init__(self):self.blocks = list()self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))def init(self):group = self.generate_group()self.block_groups.append(group)@staticmethoddef generate_group():group = BlockGroup()x0 = random.randint(0, WINDOW_WIDTH-2 * BLOCK_SIZE)//BLOCK_SIZE * BLOCK_SIZEy0 = -3 * BLOCK_SIZEgroup.blocks.append(Block(x0, y0))shape = random.choice(list(group.shape_set.keys()))for _x, _y in group.shape_set[shape]:# block = Block(random.randint(0, WINDOW_WIDTH - BLOCK_SIZE), i * BLOCK_SIZE)x = x0 + _x * BLOCK_SIZEy = y0 + _y * BLOCK_SIZEgroup.blocks.append(Block(x, y))group.shape = shapereturn groupdef draw(self):for group in self.block_groups:for block in group.blocks:block.draw(group.color)def move_down(self):if self.collision_detection("bottom"):group = self.generate_group()BlockGroup.block_groups.append(group)returnfor block in self.block_groups[-1].blocks:block.y += BLOCK_SIZEdef move_left(self):if self.collision_detection("left"):returnfor block in self.block_groups[-1].blocks:block.x -= BLOCK_SIZEdef move_right(self):if self.collision_detection("right"):returnfor block in self.block_groups[-1].blocks:block.x += BLOCK_SIZEdef collision_detection(self, move_direction):# 移动方向上的偏移量offset = {"left": {"x0": -1*BLOCK_SIZE, "y0": 0},"right": {"x0": 1*BLOCK_SIZE, "y0": 0},"bottom": {"x0": 0, "y0": 1*BLOCK_SIZE}}block_collision = Falseboundary_collision = False# 获取当前活动组每个方块的坐标像素值for block in self.block_groups[-1].blocks:after_offset_pos = (block.x + offset[move_direction]["x0"], block.y + offset[move_direction]["y0"])print(after_offset_pos, self.bottom_boundary_points)if after_offset_pos in self.bottom_boundary_points:print(f"预测到方块碰撞点", after_offset_pos)block_collision = Trueif after_offset_pos[0] < 0 or after_offset_pos[0] >= WINDOW_WIDTH or after_offset_pos[1] >= WINDOW_HEIGHT:print(f"预测到第边界碰撞点", after_offset_pos)boundary_collision = True# 方块下移时,发生方块碰撞if (block_collision or after_offset_pos[1] >= WINDOW_HEIGHT) and move_direction == "bottom":shape = self.block_groups[-1].shapeprint(self.blocks)start_block = self.block_groups[-1].blocks[0]self.bottom_boundary_points.update({(start_block.x, start_block.y)})for _x, _y in self.block_groups[-1].shape_set[shape]:self.bottom_boundary_points.update({(start_block.x + _x * BLOCK_SIZE, start_block.y + _y * BLOCK_SIZE)})print(len(self.bottom_boundary_points), self.bottom_boundary_points)# time.sleep(3)# print(f"{self}检测到碰撞, 坐标{(block.x, block.y)}")return block_collision or boundary_collision# 定义游戏主循环
def main():clock = pygame.time.Clock()# 创建方块组block_groups = BlockGroup()block_groups.init()# 游戏循环while True:clock.tick(3)# 处理事件for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()exit()if event.type == pygame.KEYDOWN:if event.key == pygame.K_LEFT:block_groups.move_left()elif event.key == pygame.K_RIGHT:block_groups.move_right()# 绘制背景screen.fill((0, 0, 0))# 移动方块组block_groups.move_down()# 绘制方块组block_groups.draw()# 更新屏幕pygame.display.update()# 启动游戏
if __name__ == '__main__':main()

效果展示
在这里插入图片描述

http://www.yayakq.cn/news/655085/

相关文章:

  • 制作梦核的网站小程序云开发收费
  • 免费私人网站网站建设宣传ppt模板
  • 服务好的网站开发宁波网站建设公司优选亿企邦
  • 郑州网站设计有哪些如何入侵自己做的网站
  • 专业外贸网站建设公司排名wordpress安全更改
  • 建设银陕西省分行网站网络域名费用多少钱
  • 贵阳网站建设策划方案可口可乐网络营销推广方案
  • 本地门户网站系统上海建站哪家好
  • 做网站的毕设用什么软件音乐网站答辩
  • 展馆设计网站wordpress增强自带搜索
  • 怎么用手机制作手机网站如何修改网站后台时间
  • 北京城乡建设网站企业网站设计推荐
  • 全景校园网站开发浙江新华建设有限公司官方网站
  • 网站产品链接怎么做女人与狗做视频网站
  • 怎样做企业的网站首页外贸网站模板 免费
  • 平凉热度网站建设电脑在哪网站接做扇子单
  • 优购物官方网站 商城如何下载网页在线视频
  • 网站做百度推广吗网络直播网站建设
  • 网站建设咨询有客诚信网站建设咨询seo关键词优化排名
  • 延庆精神文明建设的门户网站网站漂浮图片
  • 企业网站备案管理系统集美网站建设
  • 如何做一个企业网站网站 绝对路径
  • 烟台建设集团 招聘信息网站做动态文字的网站
  • 个人做游戏下载网站侵权吗专业客户管理系统
  • 做企业网站需要准备什么河北建设集团官网
  • 中山祥云网站建设西安网站制作工商
  • 网站建设规划申请网站建设前分析
  • 中英文企业网站模板公司网站后台登陆
  • 网站设计报告成都微信微网站建设
  • 个体工商户做网站做软件与做网站建设有什么区别