gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
世界首富是谁?
- User
世界首富是谁?
- Assistant
截至2021年6月,世界首富依然是亚马逊创始人、执行董事会主席杰夫·贝索斯。他的财富价值已经超过了1900亿美元。
- User
写一个俄罗斯方块的代码
- Assistant
以下是一个简单的俄罗斯方块的代码,基于 Python 编写:
import random # 定义游戏区域宽、高 WIDTH = 10 HEIGHT = 20 # 定义方块样式,每种方块是一个 4x4 的矩阵 SHAPES = [ [[0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[2, 2, 0, 0], [0, 2, 2, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 3, 3, 0], [3, 3, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[4, 4, 4, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[5, 0, 0, 0], [5, 5, 5, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 6, 0], [6, 6, 6, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 7, 0, 0], [7, 7, 7, 0], [0, 0, 0, 0], [0, 0, 0, 0]] ] # 定义方块的颜色 COLORS = [ (0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255), (0, 255, 255), (255, 255, 255) ] # 初始化游戏区域,所有位置都是空的 board = [[0 for _ in range(WIDTH)] for _ in range(HEIGHT)] # 定义方块的初始位置和样式 shape = random.choice(SHAPES) row, col = -1, WIDTH // 2 - 2 color = random.randint(1, len(COLORS) - 1) # 定义下落速度和计数器 speed = 10 counter = 0 # 定义游戏循环 while True: # 更新计数器和方块位置 counter += 1 if counter == speed: row += 1 counter = 0 # 如果方块触底或者碰到其他方块,则将其固定在当前位置 if any(board[row + i][col + j] and shape[i][j] for i in range(4) for j in range(4)): row -= 1 for i in range(4): for j in range(4): if shape[i][j]: board[row + i][col + j] = color shape = random.choice(SHAPES) row, col = -1, WIDTH // 2 - 2 color = random.randint(1, len(COLORS) - 1) # 绘制游戏区域和方块 for i in range(HEIGHT): for j in range(WIDTH): if board[i][j]: color_index = board[i][j] elif shape[i - row][j - col]: color_index = color else: color_index = 0 color = COLORS[color_index] # 在游戏界面绘制方块 # 这里需要根据具体的界面实现来绘制方块 # 处理游戏操作 # 这里需要根据具体的界面实现来实现用户操作