Headless doesn't import pygame
This commit is contained in:
parent
eccf07876a
commit
bb6f95bd2a
15
headless.py
15
headless.py
|
@ -1,23 +1,16 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import contextlib
|
||||
with contextlib.redirect_stdout(None):
|
||||
import pygame
|
||||
|
||||
from snake.map import Map
|
||||
from snake.game import Game
|
||||
from snake.window import Window
|
||||
from snake.player import Player, Direction, ConstantDecision
|
||||
from snake.game import Game, PositionPlayer
|
||||
from snake.player import Player, Direction, ConstantPlayer, KeyboardPlayer
|
||||
|
||||
def main():
|
||||
pygame.init()
|
||||
|
||||
width = 40
|
||||
height = 40
|
||||
|
||||
game = Game(width, height, [
|
||||
Player(0, 0, (255, 0, 0), ConstantDecision(Direction.LEFT)),
|
||||
Player(width - 1, height - 1, (0, 255, 0), ConstantDecision(Direction.RIGHT)),
|
||||
PositionPlayer(1, KeyboardPlayer(Direction.RIGHT), [0, 0]),
|
||||
PositionPlayer(2, ConstantPlayer(Direction.LEFT), [width - 1, height - 1]),
|
||||
])
|
||||
|
||||
game.main_loop()
|
||||
|
|
|
@ -4,7 +4,6 @@ This module contains everything related to the game.
|
|||
|
||||
from time import sleep
|
||||
from enum import Enum
|
||||
import pygame
|
||||
|
||||
from snake.map import Map
|
||||
|
||||
|
@ -94,6 +93,7 @@ class Game:
|
|||
|
||||
# Manage the events
|
||||
if window:
|
||||
import pygame
|
||||
while True:
|
||||
event = pygame.event.poll()
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ This module contains everything related to the players and the controls.
|
|||
|
||||
from enum import Enum
|
||||
|
||||
import pygame
|
||||
|
||||
class Direction(Enum):
|
||||
"""
|
||||
|
@ -70,6 +69,7 @@ class KeyboardPlayer(Player):
|
|||
"""
|
||||
Changes the direction of the snake depending on the keyboard inputs.
|
||||
"""
|
||||
import pygame
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_q:
|
||||
self.direction = Direction.LEFT
|
||||
|
|
Loading…
Reference in New Issue