我正在开发一个简单的2048 游戏。到目前为止,它似乎进展顺利,我认为我遇到的问题是我的代码在我的control函数上缩放如此之快,以至于它没有更新列表。该列表开始于: ['none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none', 'none']
但是当您按下按钮时,列表不会更新。我曾尝试调整control函数代码,但一直没有取得任何进展。
import pygame
import sys
import random
pygame.init()
fps = pygame.time.Clock()
screen_size = screen_width, screen_height = 800, 800
display = pygame.display.set_mode(screen_size)
game_state = ['none', 'none', 'none', 'none',
'none', 'none', 'none', 'none',
'none', 'none', 'none', 'none',
'none', 'none', 'none', 'none']
class game_func:
def __init__(self):
self.input = False
self.count = 0
def controls(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
self.input = True
def random(self):
var = random.randrange(0, 16)
if game_state[var] == 'none':
return var
else:
self.random()
def spawn(self):
if self.input:
pos = self.random()
if random.randrange(0, 2) == 1:
num = 'two'
else:
num = 'four'
game_state[pos] = num
self.input = False
def blit(self):
x, y = 0, 0
idx = self.count
pos = game_state[idx]
if 0 < idx < 4:
y = 0
x = idx
elif 3 < idx < 8:
y = 200
x = idx - 4
elif 7 < idx < 12:
y = 400
x = idx - 8
elif 11 < idx < 16:
y = 600
x = idx - 12
x *= 200
cord = x, y
print(idx)
print(cord)
print(game_state)
self.count += 1
if self.count == 16:
self.count = 0
def end():
pygame.quit()
sys.exit()
慕桂英4014372
相关分类