import random
import numpy as np
class Grid(object):
def __init__(self, size: int=4, max_score: int=2048):
self.size = size
self.max_score = max_score
self.cell_size = len(str(self.max_score)) + 1
self.is_over = False
self.winning = False
self.total_score = 0
self.cells = np.zeros((size, size), dtype=int)
for _ in range(2):
pos = random.randint(0, self.size**2 - 1)
i, j = int(pos / self.size), pos % self.size
self.cells[i][j] = random.choice((2, 4))
def show(self):
for i in range(0, self.size):
for j in
100行Python代码实现简易2048小游戏
最新推荐文章于 2024-06-06 11:54:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)