Headless doesn't import pygame

This commit is contained in:
Thomas Forgione 2019-03-13 18:00:46 +01:00
parent eccf07876a
commit bb6f95bd2a
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 6 additions and 13 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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