云寺手游网:做最专业最放心的安全下载站!
您当前所在位置:首页 > 游戏资讯 >

一定会挂掉的俄罗斯方块,为什么至今仍是世界游戏之王?

时间:2021-11-26 22:01:19 来源:云寺手游网

导语


为什么会有这么简单的游戏?这个游戏这么受欢迎吗?


只是因为游戏业界出现在非常不足的时代,成为了一代人的记忆吗?也许不是。

玩过俄罗斯方块的人们给人一种剥南瓜籽的感觉,一开始就像中毒一样停不下来,只为了填补空缺而绞尽脑汁。


哈哈哈。小编基本上每周都会破解一些游戏代码!

本文将允许您创建一个俄罗斯方块游戏!

正文

游戏规则:由小方块组成的各种形状的板块逐渐从屏幕顶部脱落,玩家通过改变板块的位置和方向,使它们在屏幕底部充满一个或多个元素。

这些完整的栅栏将消失,为新掉落的瓷砖腾出空间,同时,玩家将获得积分奖励。未消除的块继续累积。一旦它们在屏幕顶部累积,玩家将失败,游戏结束。

(1)游戏定义,各类儿童俄罗斯方块:

class tetrisShape(): def __init__(self, shape=0): # 空块 self.shape_empty = 0 # 一字型块 self.shape_I = 1 # L型块 self.shape_L = 2 # 向左的L型块 self.shape_J = 3 # T型块 self.shape_T = 4 # 田字型块 self.shape_O = 5 # 反向Z型块 self.shape_S = 6 # Z型块 self.shape_Z = 7

(5) 当每一行满时,它将相应地得分并消失一行:

def getRotatedRelativeCoords(self, direction): # 初始分布 if direction == 0 or self.shape == self.shape_O: return self.relative_coords # 逆时针旋转90度 if direction == 1: return [[-y, x] for x, y in self.relative_coords] # 逆时针旋转180度 if direction == 2: if self.shape in [self.shape_I, self.shape_Z, self.shape_S]: return self.relative_coords else: return [[-x, -y] for x, y in self.relative_coords] # 逆时针旋转270度 if direction == 3: if self.shape in [self.shape_I, self.shape_Z, self.shape_S]: return [[-y, x] for x, y in self.relative_coords] else: return [[y, -x] for x, y in self.relative_coords]

游戏方块可以向不同方向移动:

'''向右移动''' def moveRight(self): if self.ableMove([self.current_coord[0] + 1, self.current_coord[1]]): self.current_coord[0] += 1 '''向左移动''' def moveLeft(self): if self.ableMove([self.current_coord[0] - 1, self.current_coord[1]]): self.current_coord[0] -= 1 '''顺时针转''' def rotateClockwise(self): if self.ableMove(self.current_coord, (self.current_direction - 1) % 4): self.current_direction = (self.current_direction-1) % 4 '''逆时针转''' def rotateAnticlockwise(self): if self.ableMove(self.current_coord, (self.current_direction + 1) % 4): self.current_direction = (self.current_direction+1) % 4 '''向下移动''' def moveDown(self): removed_lines = 0 if self.ableMove([self.current_coord[0], self.current_coord[1] + 1]): self.current_coord[1] += 1 else: x_min, x_max, y_min, y_max = self.current_tetris.getRelativeBoundary(self.current_direction) # 简单起见, 有超出屏幕就判定游戏结束 if self.current_coord[1] + y_min < 0: self.is_gameover = True return removed_lines self.mergeTetris() removed_lines = self.removeFullLines() self.createNewTetris() return removed_lines '''坠落''' def dropDown(self): removed_lines = 0 while self.ableMove([self.current_coord[0], self.current_coord[1] + 1]): self.current_coord[1] += 1 x_min, x_max, y_min, y_max = self.current_tetris.getRelativeBoundary(self.current_direction) # 简单起见, 有超出屏幕就判定游戏结束 if self.current_coord[1] + y_min < 0: self.is_gameover = True return removed_lines self.mergeTetris() removed_lines = self.removeFullLines() self.createNewTetris() return removed_lines

组合俄罗斯方块(最低形状不能再移动的块):

def mergeTetris(self): for x, y in self.current_tetris.getAbsoluteCoords(self.current_direction, self.current_coord[0], self.current_coord[1]): self.board_data[x + y * self.width] = self.current_tetris.shape self.current_coord = [-1, -1] self.current_direction = 0 self.current_tetris = tetrisShape()

(5)各行都铺满了就得分。相应的行消失。


'''移出整行都有小方块的''' def removeFullLines(self): new_board_data = [0] * self.width * self.height new_y = self.height - 1 removed_lines = 0 for y in range(self.height - 1, -1, -1): cell_count = sum([1 if self.board_data[x + y * self.width] > 0 else 0 for x in range(self.width)]) if cell_count < self.width: for x in range(self.width): new_board_data[x + new_y * self.width] = self.board_data[x + y * self.width] new_y -= 1 else: removed_lines += 1 self.board_data = new_board_data return removed_lines

设计图:


​总结

哈哈哈!让我们做吧!按住方向键也可能会变形!快点。

制作不容易,记住一个三键按钮哦!!

如果一个初学者安装了一个任务包,匹配完整的记录源代码。

此总体项目源代码:base3535;他可以免费得到它!