This commit is contained in:
Yohann D'ANELLO 2020-11-06 18:11:59 +01:00
parent 43001f6ede
commit 8d9b5166b7
3 changed files with 35 additions and 31 deletions

View File

@ -1,13 +1,13 @@
import sys
from typing import Any from typing import Any
import sys
from .interfaces import Map from .interfaces import Map
from .mapdisplay import MapDisplay from .mapdisplay import MapDisplay
from .settings import Settings from .settings import Settings
from .term_manager import TermManager
from enum import Enum, auto from enum import Enum, auto
from . import menus from . import menus
class GameMode(Enum): class GameMode(Enum):
MAINMENU = auto() MAINMENU = auto()
PLAY = auto() PLAY = auto()
@ -34,7 +34,7 @@ class Game:
self.settings.load_settings() self.settings.load_settings()
self.settings.write_settings() self.settings.write_settings()
def new_game(self): def new_game(self) -> None:
# TODO generate a new map procedurally # TODO generate a new map procedurally
self.m = Map.load("example_map.txt") self.m = Map.load("example_map.txt")
self.player = Player() self.player = Player()
@ -43,11 +43,11 @@ class Game:
self.d = MapDisplay(self.m, self.player) self.d = MapDisplay(self.m, self.player)
@staticmethod @staticmethod
def load_game(filename): def load_game(filename: str) -> None:
# TODO loading map from a file # TODO loading map from a file
raise NotImplementedError() raise NotImplementedError()
def run(self, screen): def run(self, screen: Any) -> None:
while True: while True:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
@ -55,14 +55,18 @@ class Game:
key = screen.getkey() key = screen.getkey()
self.handle_key_pressed(self.translate_key(key)) self.handle_key_pressed(self.translate_key(key))
def translate_key(self, key:str) -> KeyValues: def translate_key(self, key: str) -> KeyValues:
if key in (self.settings.KEY_DOWN_SECONDARY, self.settings.KEY_DOWN_PRIMARY): if key in (self.settings.KEY_DOWN_SECONDARY,
self.settings.KEY_DOWN_PRIMARY):
return KeyValues.DOWN return KeyValues.DOWN
elif key in (self.settings.KEY_LEFT_PRIMARY, self.settings.KEY_LEFT_SECONDARY): elif key in (self.settings.KEY_LEFT_PRIMARY,
self.settings.KEY_LEFT_SECONDARY):
return KeyValues.LEFT return KeyValues.LEFT
elif key in (self.settings.KEY_RIGHT_PRIMARY, self.settings.KEY_RIGHT_SECONDARY): elif key in (self.settings.KEY_RIGHT_PRIMARY,
self.settings.KEY_RIGHT_SECONDARY):
return KeyValues.RIGHT return KeyValues.RIGHT
elif key in (self.settings.KEY_UP_PRIMARY, self.settings.KEY_UP_SECONDARY): elif key in (self.settings.KEY_UP_PRIMARY,
self.settings.KEY_UP_SECONDARY):
return KeyValues.UP return KeyValues.UP
def handle_key_pressed(self, key: KeyValues) -> None: def handle_key_pressed(self, key: KeyValues) -> None:

View File

@ -2,32 +2,32 @@ from enum import Enum, auto
class Menu: class Menu:
values: list
values:list
def __init__(self): def __init__(self):
self.position = 0 self.position = 0
def go_up(self): def go_up(self) -> None:
self.position = max(0, self.position -1) self.position = max(0, self.position - 1)
def go_down(self): def go_down(self) -> None:
self.position = min(len(self.values)-1, self.position +1) self.position = min(len(self.values) - 1, self.position + 1)
def validate(self): def validate(self) -> None:
return self.values[self.position] return self.values[self.position]
class MainMenuValues(Enum): class MainMenuValues(Enum):
START = auto() START = auto()
SETTINGS = auto() SETTINGS = auto()
EXIT = auto() EXIT = auto()
class MainMenu(Menu):
values = [ e for e in MainMenuValues ] class MainMenu(Menu):
values = [e for e in MainMenuValues]
class ArbitraryMenu: class ArbitraryMenu:
def __init__(self, values: list):
def __init__(self, values:list):
super().__init__(self) super().__init__(self)
self.values = values self.values = values

View File

@ -1,8 +1,8 @@
#This is the base ascii texturepack # This is the base ascii texturepack
ascii = { ascii = {
"EMPTY" : ' ', "EMPTY": ' ',
"WALL" : '#', "WALL": '#',
"FLOOR" : '.', "FLOOR": '.',
"PLAYER" : '@' "PLAYER": '@'
} }