58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import pygame
|
|
import time
|
|
import controls
|
|
from tilemap.playground import PlayGround
|
|
|
|
class Snake:
|
|
def __init__(self):
|
|
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.icon = pygame.image.load("snake.webp")
|
|
pygame.display.set_icon(self.icon)
|
|
|
|
self.set_windowed(self.width, self.height)
|
|
# self.set_fullscreen(self.width, self.height)
|
|
|
|
self.mainloop()
|
|
|
|
def mainloop(self):
|
|
while self.running:
|
|
self.screen.fill((100, 200, 200))
|
|
pygame.display.flip()
|
|
time.sleep(5)
|
|
self.running = False
|
|
pygame.quit()
|
|
|
|
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
|
|
|
|
@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()
|
|
|