我试图理解一个pygame代码,但我无法在我的计算机上运行它。我在python中非常新。出错的代码部分就在这里..
from pygame.locals import *
from random import randint
import pygame
import time
class App:
windowWidth = 800
windowHeight = 600
player = 0
apple = 0
def __init__(self):
self._running = True
self._display_surf = None
self._image_surf = None
self._apple_surf = None
self.game = Game()
self.player = Player(5)
self.apple = Apple(8,5)
self.computer = Computer(5)
def on_init(self):
pygame.init()
self._display_surf = pygame.display.set_mode((self.windowWidth,self.windowHeight), pygame.HWSURFACE)
pygame.display.set_caption('Pygame pythonspot.com example')
self._running = True
self._image_surf = pygame.image.load("pygame.png").convert()
self._apple_surf = pygame.image.load("apple.png").convert()
if __name__ == "__main__" :
theApp = App()
theApp.on_execute()
错误信息与此完全相同......
RESTART: C:/Users/Dipto/AppData/Local/Programs/Python/Python36/gametest1.py
Traceback (most recent call last):
File "C:/Users/Dipto/AppData/Local/Programs/Python/Python36/gametest1.py",
line 263, in <module>
theApp.on_execute()
File "C:/Users/Dipto/AppData/Local/Programs/Python/Python36/gametest1.py",
line 233, in on_execute
if self.on_init() == False:
File "C:/Users/Dipto/AppData/Local/Programs/Python/Python36/gametest1.py",
line 185, in on_init
self._image_surf = pygame.image.load("pygame.png").convert()
pygame.error: Couldn't open pygame.png