Skip to content

Commit 6dfd91f

Browse files
authored
Merge pull request #12 from nuzcraft/part_9
Part 9
2 parents 222f7d4 + f2979c8 commit 6dfd91f

File tree

12 files changed

+1471
-9
lines changed

12 files changed

+1471
-9
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ I want to use this as an opportunity to:
1212
4. make a roguelike
1313
5. practice with git
1414

15+
## Part 9 Dev Notes
16+
17+
### Ranged Scrolls and Targeting
18+
19+
https://rogueliketutorials.com/tutorials/tcod/v2/part-9/
20+
21+
Woot! No additional refactoring yet! This section should be fun because it will give us the opportunity to use the code we just built to add more items that do unique things. Hopefully (outside of targeting) the additional things should be relatively minor and relatively atomic.
22+
23+
This part was really insightful to develop as I believe it will pave the way for a significant amount of future development. We developed some unique spells that function in very different ways; one that automatically targets the nearest actor and 2 the require additional user input mid-cast. This additional input is implemented in an interesting way and by watching it get out in place I think I understand the code flow.
24+
25+
From a unit testing standpoint, this part was intense. Adding new handlers for user input meant a significant amount of unit testing. I'm also noticing that there is a lot id dependencies around the player, engine, and game map objects that makes it cumbersome to set up tests on other objects. All in, unit testing is becoming more comfortable and I'm looking forward to a time when I feel like I can push what I know to make it more organized and more performant.
26+
1527
## Part 8 Dev Notes
1628

1729
### Items and Inventory

Tests/test_ai.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from numpy import power
66

7-
from components.ai import BaseAI, HostileEnemy
7+
from components.ai import BaseAI, HostileEnemy, ConfusedEnemy
88
from components.fighter import Fighter
99
from components.inventory import Inventory
1010
from entity import Entity, Actor
@@ -109,6 +109,53 @@ def test_get_path_to_avoid_entities(self):
109109
self.assertEqual(path, path_should_be)
110110

111111

112+
class TestConfusedEnemy(unittest.TestCase):
113+
def test_init(self):
114+
'''
115+
test that the confused enemy can be initized without issues
116+
'''
117+
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
118+
hp=10, defense=10, power=10), inventory=Inventory(capacity=5))
119+
ai = ConfusedEnemy(
120+
entity=actor, previous_ai=HostileEnemy, turns_remaining=5)
121+
self.assertEqual(ai.previous_ai, HostileEnemy)
122+
self.assertEqual(ai.turns_remaining, 5)
123+
124+
def test_perform_switch_ai(self):
125+
'''
126+
test that with 0 or less turns remaining the ai switches back
127+
'''
128+
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
129+
hp=10, defense=10, power=10), inventory=Inventory(capacity=5))
130+
ai = ConfusedEnemy(
131+
entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=0)
132+
actor.ai = ai
133+
eng = Engine(player=actor)
134+
gm = GameMap(engine=eng, width=10, height=10)
135+
actor.parent = gm
136+
self.assertIsInstance(actor.ai, ConfusedEnemy)
137+
actor.ai.perform()
138+
self.assertIsInstance(actor.ai, HostileEnemy)
139+
140+
def test_perform_bump_action(self):
141+
'''
142+
test that with turns remaining the ai will perform a bump action
143+
in a random direction and reduce the number of turns remaining
144+
'''
145+
actor = Actor(ai_cls=HostileEnemy, fighter=Fighter(
146+
hp=10, defense=10, power=10), inventory=Inventory(capacity=5))
147+
ai = ConfusedEnemy(
148+
entity=actor, previous_ai=HostileEnemy(entity=actor), turns_remaining=5)
149+
actor.ai = ai
150+
eng = Engine(player=actor)
151+
gm = GameMap(engine=eng, width=10, height=10)
152+
actor.parent = gm
153+
with patch('actions.BumpAction.perform') as patch_perform:
154+
ai.perform()
155+
self.assertEqual(ai.turns_remaining, 4)
156+
patch_perform.assert_called_once()
157+
158+
112159
class TestHostileEnemy(unittest.TestCase):
113160
def test_init(self):
114161
'''

0 commit comments

Comments
 (0)