Topic List | Page List: 1 |
---|---|
Topic | ProgrammingGeneral++ |
1337toothbrush 12/28/21 8:53:43 PM #8: | ChocoboMog123 posted... That's a good idea. Make an array of the needed size, reference each actor by some unique ID and fill it appropriately. The problem, ultimately, is just iterating through x elements of somewhat different types and it will probably come back when I get to damage and actions. Yeah, the problem is that when you assign the Character array to an array of a different type, the limitations of that array apply to it. So you assigned an array of EnemyClass to actors, thus it will act like one (and so can't hold PlayerCharacter), you should do this instead: Character[] actors = new Character[enemy.length + 1]; Now if you want to put them all in the same array, you'll need a common method (e.g. Character has a method turn() which handles how the character carries out their turn). If it makes sense, you could always keep enemies and player characters separate and then simply iterate the two arrays based on speed. For example:
You sort both arrays by turn order and then advance the index based on which one is faster (or just advance the other array if one has been iterated through entirely already). --- https://imgur.com/a/FU9H8 - http://imgur.com/ZkQRDsR.png - http://imgur.com/2x2gtgP.jpg ... Copied to Clipboard! |
Topic List | Page List: 1 |