import pygame
import time
import controls
from screens.startscreen import StartScreen
from tilemap.playground import PlayGround

class Snake:
    def __init__(self):
        self.STATES = {"starting": 0, "playing": 1, "pausing": 2, "ending": 3, "setting": 4, "highscore": 5}
        self.running = True
        self.numplayers: int = 1
        self.playground: PlayGround = None
        self.controls = None
        self.players: list = []
        self.windowed: bool = True
        self.width: int = 800
        self.height: int =600
        self.startscreen = None
        self.icon = pygame.image.load("snake.webp")
        pygame.display.set_icon(self.icon)
        
        self.set_state("starting")
        self.set_windowed(self.width, self.height)
        # self.set_fullscreen(self.width, self.height)
        
        self.mainloop()
        
    def mainloop(self):
        while self.running:
            match self.state:
                case 0:
                    self.startscreen = StartScreen(self)
                case 1:
                    pass
                case 2:
                    pass
                case 3:
                    pass
                case 4:
                    pass
                case 5:
                    pass
            pygame.display.flip()
            time.sleep(5)
            self.running = False
        pygame.quit()
    
    def set_state(self, state: str) -> None:
        self.state = self.STATES[state]
        
    def set_windowed(self, width:int, height: int) -> None:
        self.screen = pygame.display.set_mode((width, height))
        self.windowed = True
        pygame.display.set_caption("Snake")
        
    def set_fullscreen(self, width: int, height: int) -> None:
        self.screen = pygame.display.set_mode((width, height), flags=pygame.FULLSCREEN)
        self.windowed = False
        
    def get_width(self) -> int:
        return self.width
    
    @property
    def numplayers(self) -> int:
        return self._numplayers
    
    @numplayers.setter
    def numplayers(self, pl: int):
        if pl <= 0 or pl >= 3:
            raise ValueError("Numplayers must be a positive value of 1 or 2")
        else:
            self._numplayers = pl

def main():
    pygame.init()
    snake = Snake()

if __name__ == "__main__":
    main()
    