Comments (2)
Part 5 doesn't get into actual Entity actions, but I'm glad you're thinking ahead to it. For part 5 specifically, I think this is enough:
def handle_enemy_turns(self):
for entity in self.game_map.entities - {self.player}:
print(f'The {entity.name} wonders when it will get to take a real turn.')
When we get to Part 6 (where the enemies to take real turns), what if we have a "can_act" property, which does all the necessary checks? It can check if the entity is an Actor
and if it isn't dead.
from tcod_tutorial_v2.
Just assume I'm talking about part X and later in the issues posts. Ignore the code for future parts until they become relevant.
The thing about a property is it can't hint at the type of the class by itself. Which is why tcod's event.type
had to be replaced with isinstance. At the very least you'd need to add assert isinstance
or some other type cast in the property or after the check.
There's an alternative method which can be used. Which is to add an empty on_turn
method to Entity and override it for Actor, the overridden method on Actor will know that the type for self
is Actor.
class Entity:
def on_turn(self, engine: Engine) -> None:
"""Called on each non-player entity during handle_enemy_turns."""
class Actor(Entity):
def on_turn(self, engine: Engine) -> None:
"""Handle actions performed by an enemy actor."""
if self.fighter.hp <= 0:
continue
print(f'The {self.name} wonders when it will get to take a real turn.')
...
def handle_enemy_turns(self):
for entity in self.game_map.entities - {self.player}:
entity.on_turn(self)
I don't know about the performance of this. I suspect it would be a little faster than isinstance
.
from tcod_tutorial_v2.
Related Issues (17)
- Notes on Part 4: Field of View. HOT 3
- Part 5: Context sensitive actions. HOT 4
- Part 5: Entity contianer issues. HOT 2
- Part 5: Entity prorotypes and type extensibility. HOT 2
- Part 9, consumable.py, LightningDamageConsumable HOT 1
- Question regarding best practices HOT 2
- Question: Difference between going to engine vs entity for game_map? HOT 2
- Part 6: Clarification on Player AI HOT 1
- render_functions.py : get_names_at_location Capitalization HOT 1
- AskUserEventHandler for Inventory
- Feedback on part 12 HOT 3
- Dropping multiple identical items on a tile only creates one instance of the item. HOT 6
- Planned refactors for 2021. HOT 1
- Notes on tcod event handling. HOT 3
- Part 6: AttributeError: 'Actor' object has no attribute 'render_order' HOT 2
- Entities is initialized as a list, but code treats it as a set. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tcod_tutorial_v2.