Отладка простой игры-пигмея - PullRequest
0 голосов
/ 29 июня 2011

Когда я запускаю это, он выполняется с ошибкой в ​​одном из импортов.Я разместил ошибку в конце кода.Программа по сути не запускается, я не могу сказать, какие ошибки происходят из-за трассировки.Любое понимание будет оценено.

from livewires import games, color
import random

games.init (screen_width = 640, screen_height = 480, fps = 50)

class Pizza (games.Sprite):
        def __init__(self, screen, x, y, image):
            self.pizzaimage = games.load_image ("pizza.bmp", transparent = True)
            self.init_sprite (screen = screen,
                               x = x, 
                               y = 90, 
                               image = self.pizzaimage, 
                               dy = 1)
        def moved (self):
            if self.bottom > 480:
                self.game_over()

        def handle_caught (self):
            self.destroy()

        def game_over(self):
            games.Message(value = "Game Over",
                          size = 90,
                          color = color.red,
                          x = 320,
                          y = 240,
                          lifetime = 250,
                          after_death = games.screen.quit())
class Pan (games.Sprite):
    def __init__(self, screen, x, image ):
        self.panimage = games.load_image ("pan.bmp", transparent = True)
        self.init_sprite (screen = screen,
                          x = games.mouse.x,
                          image = self.panimage)
        self.score_value = 0
        self.score_text = games.Text (value = "Score"+str(self.score_value),
                                      size = 20,
                                      color = color.black,
                                      x = 500,
                                      y = 20)

    def update (self):
        self.x = games.mouse.x

        #When it reaches end, return value to corner. Example:
        if self.left < 0:
            self.left = 0
        if self.right > 640:
            self.right = 640

    def handling_pizzas (self):
        for Pizza in self.overlapping_sprites:
            self.score_value += 10
            Pizza.handle_caught()

class Chef (games.Sprite):
    def __init__(self, screen, x, y, image, dx, dy,):
        self.chefimage = games.load_image ("chef.bmp", transparent = True)
        self.timer = 80
        self.init_sprite (screen = screen, 
                         x = random.randrange(640),
                         y = y,
                         dx = 20,
                         dy = 0)

        def update (self):
            if self.left < 0:
                self.dx = -self.dx

            if self.right > 640:
                self.dx = -self.dx

            elif random.randrange (10) == 5:
                self.dx = -self.dx


        def add_teh_pizzas (self):
            if self.timer > 80:
                self.timer = self.timer - 1
            else:
                new_pizza = Pizza (x = self.x)
                games.screen.add (new_pizza)
                self.timer = 80

#main
def main ():
    backgroundwall = games.load_image ("wall.jpg", transparent = False)
    games.screen.background = backgroundwall

    le_chef = Chef = ()
    games.screen.add(le_chef)
    le_pan = Pan = ()
    games.screen.add (le_pan)
    games.mouse.is_visible = False
    games.screen.event_grab = False
    games.screen.mainloop()

main()

ОТЧЕТ ОБ ОШИБКАХ:

Traceback (most recent call last):
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt1.py", line 98, in <module>
    main()
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt1.py", line 96, in main
    games.screen.mainloop()
  File "C:\Python27\lib\site-packages\livewires\games.py", line 303, in mainloop
    object._erase()
AttributeError: 'tuple' object has no attribute '_erase'

1 Ответ

7 голосов
/ 29 июня 2011

Не знаю ничего о livewires , но следующее выглядит подозрительно:

le_chef = Chef = ()
games.screen.add(le_chef)
le_pan = Pan = ()
games.screen.add (le_pan)

У вас есть классы с именами Chef и Pan, но вы ничего с ними не делаете - просто назначаете эти вещи пустым кортежам, а затем добавляете их в games.screen. Они должны были быть инициализированы вместо этого?

например.

le_chef = Chef(<some args>)
le_pan = Pan(<some args>)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...