资源简介
俄罗斯方块是儿时最经典的游戏之一,使用Python实现俄罗斯方块游戏。

代码片段和文件信息
import random
from collections import namedtuple
Point = namedtuple(‘Point‘ ‘X Y‘)
Shape = namedtuple(‘Shape‘ ‘X Y Width Height‘)
Block = namedtuple(‘Block‘ ‘template start_pos end_pos name next‘)
# 方块形状的设计,我最初我是做成 4 × 4,因为长宽最长都是4,这样旋转的时候就不考虑怎么转了,就是从一个图形替换成另一个
# 其实要实现这个功能,只需要固定左上角的坐标就可以了
# S形方块
S_BLOCK = [Block([‘.OO‘
‘OO.‘
‘...‘] Point(0 0) Point(2 1) ‘S‘ 1)
Block([‘O..‘
‘OO.‘
‘.O.‘] Point(0 0) Point(1 2) ‘S‘ 0)]
# Z形方块
Z_BLOCK = [Block([‘OO.‘
‘.OO‘
‘...‘] Point(0 0) Point(2 1) ‘Z‘ 1)
Block([‘.O.‘
‘OO.‘
‘O..‘] Point(0 0) Point(1 2) ‘Z‘ 0)]
# I型方块
I_BLOCK = [Block([‘.O..‘
‘.O..‘
‘.O..‘
‘.O..‘] Point(1 0) Point(1 3) ‘I‘ 1)
Block([‘....‘
‘....‘
‘OOOO‘
‘....‘] Point(0 2) Point(3 2) ‘I‘ 0)]
# O型方块
O_BLOCK = [Block([‘OO‘
‘OO‘] Point(0 0) Point(1 1) ‘O‘ 0)]
# J型方块
J_BLOCK = [Block([‘O..‘
‘OOO‘
‘...‘] Point(0 0) Point(2 1) ‘J‘ 1)
Block([‘.OO‘
‘.O.‘
‘.O.‘] Point(1 0) Point(2 2) ‘J‘ 2)
Block([‘...‘
‘OOO‘
‘..O‘] Point(0 1) Point(2 2) ‘J‘ 3)
Block([‘.O.‘
‘.O.‘
‘OO.‘] Point(0 0) Point(1 2) ‘J‘ 0)]
# L型方块
L_BLOCK = [Block([‘..O‘
‘OOO‘
‘...‘] Point(0 0) Point(2 1) ‘L‘ 1)
Block([‘.O.‘
‘.O.‘
‘.OO‘] Point(1 0) Point(2 2) ‘L‘ 2)
Block([‘...‘
‘OOO‘
‘O..‘] Point(0 1) Point(2 2) ‘L‘ 3)
Block([‘OO.‘
‘.O.‘
‘.O.‘] Point(0 0) Point(1 2) ‘L‘ 0)]
# T型方块
T_BLOCK = [Block([‘.O.‘
‘OOO‘
‘...‘] Point(0 0) Point(2 1) ‘T‘ 1)
Block([‘.O.‘
‘.OO‘
‘.O.‘] Point(1 0) Point(2 2) ‘T‘ 2)
Block([‘...‘
‘OOO‘
‘.O.‘] Point(0 1) Point(2 2) ‘T‘ 3)
Block([‘.O.‘
‘OO.‘
‘.O.‘] Point(0 0) Point(1 2) ‘T‘ 0)]
BLOCKS = {‘O‘: O_BLOCK
‘I‘: I_BLOCK
‘Z‘: Z_BLOCK
‘T‘: T_BLOCK
‘L‘: L_BLOCK
‘S‘: S_BLOCK
‘J‘: J_BLOCK}
def get_block():
block_name = random.choice(‘OIZTLSJ‘)
b = BLOCKS[block_name]
idx = random.randint(0 len(b) - 1)
return b[idx]
def get_next_block(block):
b = BLOCKS[block.name]
return b[block.next]
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-14 14:16 俄罗斯方块\
文件 3176 2019-01-02 09:14 俄罗斯方块\blocks.py
文件 98600 2019-03-14 14:16 俄罗斯方块\freesansbold.ttf
文件 10240 2019-03-14 14:18 俄罗斯方块\tetris.py
文件 0 2018-08-30 21:03 俄罗斯方块\__init__.py
目录 0 2019-01-03 09:41 俄罗斯方块\__pycache__\
文件 1674 2019-01-03 09:41 俄罗斯方块\__pycache__\blocks.cpython-36.pyc
文件 45580 2019-01-02 13:13 俄罗斯方块\俄罗斯方块.png
- 上一篇:数值分析第五版部分上机实习题报告和源代码
- 下一篇:模拟示波器 py脚本
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论