MapDisplay extends Display

This commit is contained in:
Yohann D'ANELLO 2020-11-08 23:03:59 +01:00
parent 8ccf8c7b67
commit dc3f55cff3
3 changed files with 16 additions and 14 deletions

View File

@ -10,6 +10,3 @@ class Display:
def refresh(self) -> None:
raise NotImplementedError
def display(self, y: int, x: int) -> None:
raise NotImplementedError

View File

@ -1,19 +1,21 @@
#!/usr/bin/env python
import curses
from typing import Any
from dungeonbattle.display.display import Display
from dungeonbattle.display.texturepack import TexturePack
from dungeonbattle.entities.player import Player
from dungeonbattle.interfaces import Map
class MapDisplay:
def __init__(self, m: Map, pack: TexturePack, height: int, width: int,
init_pad: bool = True):
self.width = width
self.height = height
class MapDisplay(Display):
def __init__(self, screen: Any, m: Map, player: Player, pack: TexturePack):
super().__init__(screen)
self.height = self.rows
self.width = self.cols
self.pack = pack
self.map = m
if init_pad:
self.player = player
self.pad = curses.newpad(m.height, m.width + 1)
def update_pad(self) -> None:
@ -35,3 +37,6 @@ class MapDisplay:
self.pad.clear()
self.update_pad()
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
def refresh(self) -> None:
return self.display(self.player.y, self.player.x)

View File

@ -39,7 +39,7 @@ class Game:
self.player = Player()
self.player.move(1, 6)
self.m.add_entity(self.player)
self.d = MenuDisplay(self, self.main_menu, 0, 0)
self.current_display = MenuDisplay(self, self.main_menu, 0, 0)
@staticmethod
def load_game(filename: str) -> None:
@ -51,7 +51,7 @@ class Game:
screen.clear()
screen.refresh()
# self.d.display(self.player.y, self.player.x)
self.d.refresh()
self.current_display.refresh()
key = screen.getkey()
self.handle_key_pressed(self.translate_key(key))
@ -94,4 +94,4 @@ class Game:
self.state = GameMode.SETTINGS
elif option == menus.MainMenuValues.EXIT:
sys.exit(0)
self.d.refresh()
self.current_display.refresh()