From 91a8919a01209a07d8a0d9b694f21731b0f2c92b Mon Sep 17 00:00:00 2001 From: eichhornchen Date: Tue, 10 Nov 2020 10:01:31 +0100 Subject: [PATCH] Added a MainMenuDisplay class and fixed errors in display --- dungeonbattle/display/ascii_art.txt | 11 +++++++++++ dungeonbattle/display/display.py | 4 ++-- dungeonbattle/display/mapdisplay.py | 10 +++++----- dungeonbattle/display/menudisplay.py | 27 ++++++++++++++++++++++++--- dungeonbattle/display/statsdisplay.py | 6 +++--- dungeonbattle/display/test.py | 17 +++++++++++++++++ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 dungeonbattle/display/ascii_art.txt create mode 100644 dungeonbattle/display/test.py diff --git a/dungeonbattle/display/ascii_art.txt b/dungeonbattle/display/ascii_art.txt new file mode 100644 index 0000000..966e832 --- /dev/null +++ b/dungeonbattle/display/ascii_art.txt @@ -0,0 +1,11 @@ + ██████ █████ █ ██ ██▓ ██▀███ ██▀███ ▓█████ ██▓ ▄▄▄▄ ▄▄▄ ▄▄▄█████▓▄▄▄█████▓ ██▓ ▓█████ +▒██ ▒ ▒██▓ ██▒ ██ ▓██▒▓██▒▓██ ▒ ██▒▓██ ▒ ██▒▓█ ▀ ▓██▒ ▓█████▄ ▒████▄ ▓ ██▒ ▓▒▓ ██▒ ▓▒▓██▒ ▓█ ▀ +░ ▓██▄ ▒██▒ ██░▓██ ▒██░▒██▒▓██ ░▄█ ▒▓██ ░▄█ ▒▒███ ▒██░ ▒██▒ ▄██▒██ ▀█▄ ▒ ▓██░ ▒░▒ ▓██░ ▒░▒██░ ▒███ + ▒ ██▒░██ █▀ ░▓▓█ ░██░░██░▒██▀▀█▄ ▒██▀▀█▄ ▒▓█ ▄ ▒██░ ▒██░█▀ ░██▄▄▄▄██░ ▓██▓ ░ ░ ▓██▓ ░ ▒██░ ▒▓█ ▄ +▒██████▒▒░▒███▒█▄ ▒▒█████▓ ░██░░██▓ ▒██▒░██▓ ▒██▒░▒████▒░██████▒ ░▓█ ▀█▓ ▓█ ▓██▒ ▒██▒ ░ ▒██▒ ░ ░██████▒░▒████▒ +▒ ▒▓▒ ▒ ░░░ ▒▒░ ▒ ░▒▓▒ ▒ ▒ ░▓ ░ ▒▓ ░▒▓░░ ▒▓ ░▒▓░░░ ▒░ ░░ ▒░▓ ░ ░▒▓███▀▒ ▒▒ ▓▒█░ ▒ ░░ ▒ ░░ ░ ▒░▓ ░░░ ▒░ ░ +░ ░▒ ░ ░ ░ ▒░ ░ ░░▒░ ░ ░ ▒ ░ ░▒ ░ ▒░ ░▒ ░ ▒░ ░ ░ ░░ ░ ▒ ░ ▒░▒ ░ ▒ ▒▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ +░ ░ ░ ░ ░ ░░░ ░ ░ ▒ ░ ░░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ + ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ + ░ + diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index 8f6ce54..333f2e9 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -15,8 +15,8 @@ class Display: def __init__(self, screen: Any, texture: Any): self.screen = screen self.texture = texture - self.mapdisplay = MapDisplay(self.screen, self.texture, curses.LINES * 4//5, curses.COLS) - self.statsdisplay = StatsDisplay(self.screen, curses.LINES//5, curses.COLS) + self.mapdisplay = MapDisplay(self.texture, curses.LINES * 4//5, curses.COLS) + self.statsdisplay = StatsDisplay(curses.LINES//5, curses.COLS, curses.LINES * 4//5, 0) def refresh(self, m : Map, p : Player) -> None: self.map = m diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index 7ed35b3..b795c8a 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -1,5 +1,6 @@ #!/usr/bin/env python from typing import Any +import curses from dungeonbattle.display.display import Display from dungeonbattle.display.texturepack import TexturePack @@ -11,19 +12,18 @@ class MapDisplay: self.map: Map self.player: Player - def __init__(self, screen: Any, pack: TexturePack, height : int, width : int): - self.screen = screen + def __init__(self, pack: TexturePack, height : int, width : int): self.height = height self.width = width self.pack = pack - self.pad = self.newpad(m.height, m.width + 1) + self.pad = curses.newpad(m.height, m.width + 1) def update_pad(self) -> None: self.pad.addstr(0, 0, self.map.draw_string(self.pack)) for e in self.map.entities: self.pad.addstr(e.y, e.x, self.pack.PLAYER) - def display(self) -> None: + def display(self, y, x) -> None: deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1 pminrow, pmincol = y - deltay, x - deltax sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0) @@ -42,4 +42,4 @@ class MapDisplay: self.map = m self.player = p y, x = self.map.currenty, self.map.currentx - return self.display() + self.display(y,x) diff --git a/dungeonbattle/display/menudisplay.py b/dungeonbattle/display/menudisplay.py index c8c6a3c..d61d46d 100644 --- a/dungeonbattle/display/menudisplay.py +++ b/dungeonbattle/display/menudisplay.py @@ -1,12 +1,11 @@ -from dungeonbattle.menus import Menu +from dungeonbattle.menus import Menu, MainMenu from typing import Any import curses class MenuDisplay: position: int - def __init__(self, menu : Menu, screen: Any, height : int, width : int, topleftx: int, toplefty: int) : - self.screen = screen + def __init__(self, menu : Menu, height : int, width : int, topleftx: int, toplefty: int) : self.values = menu.values self.width = width self.height = height @@ -46,3 +45,25 @@ class MenuDisplay: self.pad.refresh(cornery, 0, self.toplefty+1, self.topleftx+1, self.height-2 + self.toplefty, self.width-2 + self.topleftx) + +class MainMenuDisplay: + def __init__(self, menu : MainMenu) : + self.menu = menu + self.pad = curses.newpad(curses.LINES, curses.COLS) + + with open("ascii_art.txt", "r") as file: + title = file.read().split("\n") + + width = len(title[0]) + height = len(title) + + for i in range(len(title)) : + self.pad.addstr(4+i,curses.COLS//2-width//2-1,title[i]) + self.pad.refresh(0,0,0,0,curses.LINES,curses.COLS) + + self.menudisplay = MenuDisplay(self.menu, 15, 15, height+8, curses.COLS//2-15//2-1) + + def refresh(self, position) -> None: + self.menudisplay.refresh(position) + + diff --git a/dungeonbattle/display/statsdisplay.py b/dungeonbattle/display/statsdisplay.py index b990ee9..60e239b 100644 --- a/dungeonbattle/display/statsdisplay.py +++ b/dungeonbattle/display/statsdisplay.py @@ -1,4 +1,5 @@ from typing import Any +import curses from dungeonbattle.display.display import Display from dungeonbattle.entities.player import Player @@ -7,15 +8,14 @@ from dungeonbattle.entities.player import Player class StatsDisplay(Display): self.player: Player - def __init__(self, screen: Any, height: int, width: int, + def __init__(self, height: int, width: int, topleftx: int, toplefty: int): - super().__init__(screen) self.width = width self.height = height self.topleftx = topleftx self.toplefty = toplefty - self.pad = self.newpad(height, width) + self.pad = curses.newpad(height, width) def update_pad(self) -> None: string = "" diff --git a/dungeonbattle/display/test.py b/dungeonbattle/display/test.py new file mode 100644 index 0000000..a01ae15 --- /dev/null +++ b/dungeonbattle/display/test.py @@ -0,0 +1,17 @@ +import curses +import time + +def main(screen) : + pad = curses.newpad(curses.LINES, curses.COLS) + with open("ascii_art.txt", "r") as file: + title = file.read().split("\n") + + width = len(title[0]) + for i in range(len(title)) : + pad.addstr(4+i,curses.COLS//2-width//2-1,title[i]) + pad.refresh(0,0,0,0,curses.LINES,curses.COLS) + time.sleep(1) + + + +curses.wrapper(main)