# shapes.py

# modified from code in Object-Oriented Python, by Irv Kalb

# creates squares, circles and triangles that describe themselves 
# when clicked

# 1 - Import packages
import pygame
import sys
import random
from pygame.locals import *
from square import Square
from circle import Circle
from triangle import Triangle
import pygwidgets

# 2 - Define constants
WHITE = (255, 255, 255)
WINDOW_WIDTH = 640
WINDOW_HEIGHT = 480
FRAMES_PER_SECOND = 30
NUM_SHAPES = 7

# 3 - Initialize Pygame
pygame.init()
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32)
clock = pygame.time.Clock()

# 4 - Load resources: images, sounds, etc.

# 5 - Initialize variables
shapes_list   = []
shape_classes = (Square, Circle, Triangle)
for i in range(0, NUM_SHAPES):
    random_class = random.choice(shape_classes)
    shape = random_class(window, WINDOW_WIDTH, WINDOW_HEIGHT)
    shapes_list.append(shape)
    
# 6 - Game loop
while True:

    # 7 - Check for and handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
            
    # 8 - Animation changes
    
    # 9 - Clear the window
    window.fill(WHITE)
    
    # 10 - Draw all window elements
    for shape in shapes_list:
        shape.draw()
    
    # 11 - Update the window
    pygame.display.update()

    # 12 - Slow things down
    clock.tick(FRAMES_PER_SECOND)
