|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 不二如是 于 2022-6-6 20:59 编辑
在线讲解:
《俄罗斯方块》(Тетрис)英文名 Tetris,于 1984 年 6 月 6 日首次发布,风靡全球,没有之一的游戏~
游戏最初由阿列克谢·帕基特诺夫在苏联设计和编写。
此游戏的名称是由希腊语数字“四”的前缀“tetra-”。
所以所有落下方块皆由四块组成。
此外帕基特诺夫最喜欢的运动是网球(“tennis”),所以拼接在一起。
有趣的是,虽然游戏为苏联人发明,但最初为了规避版权,在苏联解体前就已经将其普遍称为“俄罗斯方块”了。
写好一个极简版俄罗斯程序给大家:
- # 上方向键-旋转
- # 左方向键-左移
- # 右方向键-右移
- # 下方向键-加速
- import pygame
- import random
- colors = [
- (0, 0, 0),
- (120, 37, 179),
- (100, 179, 179),
- (80, 34, 22),
- (80, 134, 22),
- (180, 34, 22),
- (180, 34, 122),
- ]
- class Figure:
- x = 0
- y = 0
- figures = [
- [[1, 5, 9, 13], [4, 5, 6, 7]],
- [[1, 2, 5, 9], [0, 4, 5, 6], [1, 5, 9, 8], [4, 5, 6, 10]],
- [[1, 2, 6, 10], [5, 6, 7, 9], [2, 6, 10, 11], [3, 5, 6, 7]],
- [[1, 4, 5, 6], [1, 4, 5, 9], [4, 5, 6, 9], [1, 5, 6, 9]],
- [[1, 2, 5, 6]],
- ]
- def __init__(self, x, y):
- self.x = x
- self.y = y
- self.type = random.randint(0, len(self.figures) - 1)
- self.color = random.randint(1, len(colors) - 1)
- self.rotation = 0
- def image(self):
- return self.figures[self.type][self.rotation]
- def rotate(self):
- self.rotation = (self.rotation + 1) % len(self.figures[self.type])
- class Tetris:
- level = 2
- score = 0
- state = "start"
- field = []
- height = 0
- width = 0
- x = 100
- y = 60
- zoom = 20
- figure = None
- def __init__(self, height, width):
- self.height = height
- self.width = width
- for i in range(height):
- new_line = []
- for j in range(width):
- new_line.append(0)
- self.field.append(new_line)
- def new_figure(self):
- self.figure = Figure(3, 0)
- ...
复制代码
完整源码(回复我爱鱼C):
|
|