# Arup Guha
# Dot Game - example for SI@UCF
# 6/14/2024
# Updated dot game from 2022 - this is the main screen
# Repositioned buttons added quit button

import dotconsts
import dotfunctions
import dotgame
import choosecolor
import pygame, sys
from pygame.locals import *

# Initialize all imported pygame modules.
pygame.init()
# Create a custom caption that will be displayed on the top of your window of your game.
pygame.display.set_caption('Dot Game!')

# Create a Font object from the system fonts. I chose size 100.
font = pygame.font.SysFont(None, 75)

# Create an object to help track time
clock = pygame.time.Clock()

def menu():

    # Default color of your dot.
    color = dotconsts.LIME

    myScore = -1

    # While true, so infinite loop.
    while True:

        # Creates a screen with width and height.
        screen = pygame.display.set_mode((dotconsts.SCREEN_W, dotconsts.SCREEN_H))

        # Fill surface with a solid color, I chose black.
        screen.fill("black")

        # Get mouse position x and y.
        mx, my = pygame.mouse.get_pos()

        # Refers to the draw_text function I made above.
        # Requires text, font, color, surface, x, y.
        # This is how we draw text to screen. IMPORTANT!!
        dotfunctions.draw('Menu', font, (255, 255, 255), screen, 430, 20)

        # Created buttons. X, Y, Width, Height.
        button_1 = pygame.Rect(300, 100, 400, 100)
        button_2 = pygame.Rect(300, 250, 400, 100)
        button_3 = pygame.Rect(300, 400, 400, 100)

        # Draws buttons onto screen
        pygame.draw.rect(screen, (192,192,192), button_1)
        pygame.draw.rect(screen, (147,112,219), button_2)
        pygame.draw.rect(screen, "cyan", button_3)

        # Creates and draws text on buttons.
        dotfunctions.draw('Play', font, "white", screen, 440, 125)
        dotfunctions.draw('Color', font, "white", screen, 430, 275)
        dotfunctions.draw('Quit', font, "white", screen, 440, 425)
        
        if myScore != -1:
            dotfunctions.draw("Last Game Score = "+str(myScore), font, "white", screen, 230, 525)

        # Get events from the queue
        for event in pygame.event.get():

            # If you close the game.
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

            # If you press down a key.
            if event.type == KEYDOWN:
                # If that key was the escape button do this.
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()

            # If you click on screen.
            if event.type == MOUSEBUTTONDOWN:
                # 1 - left click, 2 - middle click, 3 - right click, 4 - scroll up, 5 - scroll down
                if event.button == 1:
                    
                    # If mouse location is inside this rectangle.
                    if button_1.collidepoint((mx, my)):
                        myScore = dotgame.main_game(color)

                    # If mouse location is inside this rectangle.
                    if button_2.collidepoint((mx, my)):
                        color = choosecolor.options()

                    # If mouse location is inside this rectangle.
                    if button_3.collidepoint((mx, my)):
                        pygame.quit()
                        sys.exit()

        # Update portions of the screen for software displays
        pygame.display.update()

        # Update the clock in milliseconds. Should be called once per frame.
        clock.tick(30)


# Loads main menu.
menu()
