我是一个初学者,我面临着制作“西蒙说”游戏的挑战。但是,在下面的代码中,我无法让“yellow_tile”出现在屏幕上。我错过了什么。我知道这一定是非常基本的东西,但我被困住了。
谢谢。
代码(在评论“创建瓷砖”下):
# Simon Says
# displays sequences of sounds and/or colors which the user has to repeat
from livewires import games, color
import random
# initialise screen
games.init(screen_width = 640, screen_height = 480, fps = 50)
class Game(object):
"""A sequence repeat game"""
sequence_count = 1
score = 0
def __init__(self):
"""Initialize Game object"""
# create key
self.menu_title = games.Text(value = "Key",
size = 25,
color = color.white,
top = 5,
left = games.screen.width - 100,
is_collideable = False)
self.menu_choice0 = games.Text(value = "0 - Quit",
size = 20,
color = color.white,
top = self.menu_title.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice1 = games.Text(value = "1 - Yellow",
size = 20,
color = color.yellow,
top = self.menu_choice0.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice2 = games.Text(value = "2 - Red",
size = 20,
color = color.red,
top = self.menu_choice1.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice3 = games.Text(value = "2 - Blue",
size = 20,
color = color.blue,
top = self.menu_choice2.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice4 = games.Text(value = "4 - Green",
size = 20,
color = color.green,
top = self.menu_choice3.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
games.screen.add(self.menu_title)
games.screen.add(self.menu_choice0)
games.screen.add(self.menu_choice1)
games.screen.add(self.menu_choice2)
games.screen.add(self.menu_choice3)
games.screen.add(self.menu_choice4)
# add scrolling text at bottom of screen
self.instructions = games.Text(value = "Repeat the sequence by entering the "
"corresponding number.",
size = 20,
color = color.white,
x = games.screen.width/2,
bottom = games.screen.height - 2)
games.screen.add(self.instructions)
# create score
self.score = games.Text(value = 0,
size = 30,
color = color.white,
top = 5,
left = 10,
is_collideable = False)
games.screen.add(self.score)
# create tiles
self.yellow_tile = Yellow(game = self, x = games.screen.width/4,
y = games.screen.height/4)
games.screen.add(self.yellow_tile)
def play(self):
"""Play game"""
# load and set background
black_background = games.load_image("blackbackground.jpg", transparent = False)
games.screen.background = black_background
games.screen.mainloop()
class Yellow(games.Sprite):
"""The yellow square"""
sound = games.load_sound("thrust.wav")
image = games.load_image("yellow_sq.bmp")
def __init__(self, game, x, y):
"""Initialize yellow sprite"""
super(Yellow, self).__init__(image = Yellow.image, x = x, y = y)
self.game = game
def main():
sequence = Game()
sequence.play()
main()