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: def refresh(self) -> None:
raise NotImplementedError raise NotImplementedError
def display(self, y: int, x: int) -> None:
raise NotImplementedError

View File

@ -1,20 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
import curses import curses
from typing import Any
from dungeonbattle.display.display import Display
from dungeonbattle.display.texturepack import TexturePack from dungeonbattle.display.texturepack import TexturePack
from dungeonbattle.entities.player import Player
from dungeonbattle.interfaces import Map from dungeonbattle.interfaces import Map
class MapDisplay: class MapDisplay(Display):
def __init__(self, screen: Any, m: Map, player: Player, pack: TexturePack):
def __init__(self, m: Map, pack: TexturePack, height: int, width: int, super().__init__(screen)
init_pad: bool = True): self.height = self.rows
self.width = width self.width = self.cols
self.height = height
self.pack = pack self.pack = pack
self.map = m self.map = m
if init_pad: self.player = player
self.pad = curses.newpad(m.height, m.width + 1) self.pad = curses.newpad(m.height, m.width + 1)
def update_pad(self) -> None: def update_pad(self) -> None:
self.pad.addstr(0, 0, self.map.draw_string(self.pack)) self.pad.addstr(0, 0, self.map.draw_string(self.pack))
@ -35,3 +37,6 @@ class MapDisplay:
self.pad.clear() self.pad.clear()
self.update_pad() self.update_pad()
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) 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 = Player()
self.player.move(1, 6) self.player.move(1, 6)
self.m.add_entity(self.player) 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 @staticmethod
def load_game(filename: str) -> None: def load_game(filename: str) -> None:
@ -51,7 +51,7 @@ class Game:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
# self.d.display(self.player.y, self.player.x) # self.d.display(self.player.y, self.player.x)
self.d.refresh() self.current_display.refresh()
key = screen.getkey() key = screen.getkey()
self.handle_key_pressed(self.translate_key(key)) self.handle_key_pressed(self.translate_key(key))
@ -94,4 +94,4 @@ class Game:
self.state = GameMode.SETTINGS self.state = GameMode.SETTINGS
elif option == menus.MainMenuValues.EXIT: elif option == menus.MainMenuValues.EXIT:
sys.exit(0) sys.exit(0)
self.d.refresh() self.current_display.refresh()