I'm trying to emulate a combat sequence of sorts using threads and MVC. Details:
- Every creature has an initiative score 开发者_高级运维governing who gets to go first.
- Every creature must state its intended target.
- Creatures are loaded into a stack on a 'Combat' class; the creature with the lowest score enters the stack first.
- Once every creature has selected a target, the stack empties, and creatures act according to their initiative order, highest-first.
An assignment constraint requires me to handle the creatures as separate threads. The problem is:
- I don't know of a way for the 'Combat' class to realize that it has to process the actions on the stack because there will be no more creatures entering it.
- I figure 'Combat' must have a way of knowing the lowest initiative score among all running threads, but I don't know how to manage that.
I apologize if I can't put this more clearly. It's very frustrating as it is.
Without knowing the exact requirements of this Assignment it's hard to give a good answer but here's a couple of ideas for you.
The Combat class needs to know when it has all the moves so it can process them. Either every creature needs to make a Combat move once per turn or has some way if signalling it isn't going to make a Combat move or something similar. Without this information you don't know when to process the moves.
Processing moves in Initiative order makes sense, but do you need them to pushed onto a stack in order. Adding all the moves and then sorting or using a priority queue seems like a better soloution. If it is a requirement for the combat class to only accept moves in a certain order then yes it will need to know the lowest score.
精彩评论