More tests
This commit is contained in:
parent
3486c865a1
commit
0ab0e6a00c
|
@ -7,14 +7,11 @@ from dungeonbattle.tests.screen import FakePad
|
||||||
class Display:
|
class Display:
|
||||||
def __init__(self, screen: Any):
|
def __init__(self, screen: Any):
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
self.rows = curses.LINES if screen else 4
|
self.rows = curses.LINES if screen else 42
|
||||||
self.cols = curses.COLS * 4 // 5 if screen else 4
|
self.cols = curses.COLS * 4 // 5 if screen else 42
|
||||||
|
|
||||||
def refresh(self) -> None:
|
def refresh(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
def newpad(self, height: int, width: int) -> Union[FakePad, Any]:
|
||||||
if self.screen:
|
return curses.newpad(height, width) if self.screen else FakePad()
|
||||||
return curses.newpad(height, width)
|
|
||||||
else:
|
|
||||||
return FakePad()
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import curses
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from dungeonbattle.display.display import Display
|
from dungeonbattle.display.display import Display
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from dungeonbattle.display.display import Display
|
from dungeonbattle.display.display import Display
|
||||||
from dungeonbattle.menus import Menu
|
from dungeonbattle.menus import Menu
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import curses
|
|
||||||
|
|
||||||
|
|
||||||
class MenuDisplay(Display):
|
class MenuDisplay(Display):
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import curses
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from dungeonbattle.display.display import Display
|
from dungeonbattle.display.display import Display
|
||||||
|
|
|
@ -4,6 +4,10 @@ from ..interfaces import FightingEntity
|
||||||
class Player(FightingEntity):
|
class Player(FightingEntity):
|
||||||
maxhealth: int = 20
|
maxhealth: int = 20
|
||||||
strength: int = 5
|
strength: int = 5
|
||||||
|
intelligence: int = 1
|
||||||
|
charisma: int = 1
|
||||||
|
dexterity: int = 1
|
||||||
|
constitution: int = 1
|
||||||
level: int = 1
|
level: int = 1
|
||||||
current_xp: int = 0
|
current_xp: int = 0
|
||||||
max_xp: int = 10
|
max_xp: int = 10
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from dungeonbattle.display.display import Display
|
||||||
|
from dungeonbattle.display.statsdisplay import StatsDisplay
|
||||||
from dungeonbattle.game import Game, KeyValues, GameMode
|
from dungeonbattle.game import Game, KeyValues, GameMode
|
||||||
from dungeonbattle.menus import MainMenuValues
|
from dungeonbattle.menus import MainMenuValues
|
||||||
|
|
||||||
|
@ -14,6 +16,7 @@ class TestGame(unittest.TestCase):
|
||||||
|
|
||||||
def test_load_game(self) -> None:
|
def test_load_game(self) -> None:
|
||||||
self.assertRaises(NotImplementedError, Game.load_game, "game.save")
|
self.assertRaises(NotImplementedError, Game.load_game, "game.save")
|
||||||
|
self.assertRaises(NotImplementedError, Display(None).refresh)
|
||||||
|
|
||||||
def test_key_translation(self) -> None:
|
def test_key_translation(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -37,6 +40,7 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.settings.KEY_RIGHT_SECONDARY), KeyValues.RIGHT)
|
self.game.settings.KEY_RIGHT_SECONDARY), KeyValues.RIGHT)
|
||||||
self.assertEqual(self.game.translate_key(
|
self.assertEqual(self.game.translate_key(
|
||||||
self.game.settings.KEY_ENTER), KeyValues.ENTER)
|
self.game.settings.KEY_ENTER), KeyValues.ENTER)
|
||||||
|
self.assertEqual(self.game.translate_key(' '), KeyValues.SPACE)
|
||||||
|
|
||||||
def test_key_press(self) -> None:
|
def test_key_press(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -54,7 +58,8 @@ class TestGame(unittest.TestCase):
|
||||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||||
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
self.assertEqual(self.game.state, GameMode.SETTINGS)
|
||||||
|
|
||||||
self.game.state = GameMode.MAINMENU
|
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
|
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||||
|
|
||||||
self.game.handle_key_pressed(KeyValues.DOWN)
|
self.game.handle_key_pressed(KeyValues.DOWN)
|
||||||
self.assertEqual(self.game.main_menu.validate(),
|
self.assertEqual(self.game.main_menu.validate(),
|
||||||
|
@ -95,3 +100,11 @@ class TestGame(unittest.TestCase):
|
||||||
new_y, new_x = self.game.player.y, self.game.player.x
|
new_y, new_x = self.game.player.y, self.game.player.x
|
||||||
self.assertEqual(new_y, y)
|
self.assertEqual(new_y, y)
|
||||||
self.assertEqual(new_x, x - 1)
|
self.assertEqual(new_x, x - 1)
|
||||||
|
|
||||||
|
self.game.handle_key_pressed(KeyValues.SPACE)
|
||||||
|
self.assertEqual(self.game.state, GameMode.MAINMENU)
|
||||||
|
|
||||||
|
def test_stats_display(self) -> None:
|
||||||
|
self.game.current_display = StatsDisplay(None, self.game.player,
|
||||||
|
42, 42, 0, 0)
|
||||||
|
self.game.current_display.refresh()
|
||||||
|
|
|
@ -10,5 +10,5 @@ class FakePad:
|
||||||
smincol: int, smaxrow: int, smaxcol: int) -> None:
|
smincol: int, smaxrow: int, smaxcol: int) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def clear(self):
|
def clear(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue