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

View File

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

View File

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