Test sunflowers interaction

This commit is contained in:
Yohann D'ANELLO 2020-12-09 15:05:19 +01:00
parent 7ab4213273
commit 39787861dc
1 changed files with 30 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import unittest
from ..bootstrap import Bootstrap from ..bootstrap import Bootstrap
from ..display.display import Display from ..display.display import Display
from ..display.display_manager import DisplayManager from ..display.display_manager import DisplayManager
from ..entities.friendly import Sunflower
from ..entities.items import Bomb from ..entities.items import Bomb
from ..entities.player import Player from ..entities.player import Player
from ..enums import DisplayActions from ..enums import DisplayActions
@ -414,3 +415,32 @@ class TestGame(unittest.TestCase):
self.assertTrue(bomb.exploding) self.assertTrue(bomb.exploding)
self.assertEqual(bomb.y, self.game.player.y) self.assertEqual(bomb.y, self.game.player.y)
self.assertEqual(bomb.x, self.game.player.x) self.assertEqual(bomb.x, self.game.player.x)
def test_talk_to_sunflowers(self) -> None:
"""
Interact with sunflowers
"""
self.game.state = GameMode.PLAY
sunflower = Sunflower()
sunflower.move(2, 6)
self.game.map.add_entity(sunflower)
# Talk to sunflower... or not
self.game.handle_key_pressed(KeyValues.T)
self.assertTrue(self.game.waiting_for_friendly_key)
self.game.handle_key_pressed(KeyValues.UP)
self.assertFalse(self.game.waiting_for_friendly_key)
self.assertEqual(self.game.state, GameMode.PLAY)
self.assertFalse(len(self.game.logs.messages) > 1)
# Talk to sunflower
self.game.handle_key_pressed(KeyValues.T)
self.assertTrue(self.game.waiting_for_friendly_key)
self.game.handle_key_pressed(KeyValues.DOWN)
self.assertFalse(self.game.waiting_for_friendly_key)
self.assertEqual(self.game.state, GameMode.PLAY)
self.assertTrue(self.game.logs.messages)
# Ensure that the message is a good message
self.assertIn(self.game.logs.messages[1][21:],
Sunflower.dialogue_option)