May-28-2020, 07:53 PM
I'm trying to teach myself Python. I have a little knowledge in C++, so python isn't completely foreign to me, but it's all still really new to me.
I bought a book: Matthes, Eric. Python Crash Course, 2nd Edition (p. 229). No Starch Press. Kindle Edition.
In the book I started the first Project. It's making an Alien Invasion game. I wrote the code he wrote to get a window to open, but I can't seem to get it to work. I looked at other parts of the forum and found a section that shows how to make a window. This code worked for me, and I got the window to pop up. However, that code is completely different than the code from the book. For now, I would just like to figure out why this code, copied directly from the book, is not working for me and why. Any help would be much appreciated.
I keep getting an error code AttributeError: 'AlienInvasion' object has no attribute 'run_game'
I bought a book: Matthes, Eric. Python Crash Course, 2nd Edition (p. 229). No Starch Press. Kindle Edition.
In the book I started the first Project. It's making an Alien Invasion game. I wrote the code he wrote to get a window to open, but I can't seem to get it to work. I looked at other parts of the forum and found a section that shows how to make a window. This code worked for me, and I got the window to pop up. However, that code is completely different than the code from the book. For now, I would just like to figure out why this code, copied directly from the book, is not working for me and why. Any help would be much appreciated.
I keep getting an error code AttributeError: 'AlienInvasion' object has no attribute 'run_game'
import sys import pygame class AlienInvasion: """Overall classs to manage game assets and behavior.""" def __init__(self): """Initialize the game, and greate game resources.""" pygame.init() self.screen = pygame.display.set_mode((1200,800)) pygame.display.set_caption("Alien Invasion") def run_game(self): """Start the main loop for the game.""" while True: # Watch for keyboard and mouse events. for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # Make the most recently drawn screen visible. pygame.display.flip() if __name__ == '__main__': # Make a game instance, and run the game. ai = AlienInvasion() ai.run_game()