Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hmmm.. I'm thinking that maybe a command pattern would be a good solution to this problem. Here's what I mean:</p> <p>This is your character class:</p> <pre><code>Public class Character { //various character related variables and methods here... Command[] equipCommands; Command[] unequipCommands; public Character(Command[] p_equipCommands, Command[] p_unequipCommands) { equipCommands = p_equipCommands; unequipCommands = p_unEquipCommands; } public void itemEquiped(int itemID) { equipCommands[itemID].execute(this); } public void itemUnequiped(int itemID) { unequipCommands[itemID].execute(this); } } </code></pre> <p>Here are some examples of commands:</p> <pre><code>public class SwordOfDragonSlayingEquipCommand implements ItemCommand{ public void execute(Character p_character) { //There's probably a better way of doing this, but of the top of my head... p_character.addItemToInventory(Weapons.getIteM(Weapons.SWORD_OF_DRAGON_SLAYING)); //other methods that raise stats, give bonuses etc. here... } } public class SwordOfDragonSlayingUnequipCommand implements ItemCommand{ public void execute(Character p_character) { //There's probably a better way of doing this, but of the top of my head... p_character.removeItemFromInventory(Weapons.getIteM(Weapons.SWORD_OF_DRAGON_SLAYING)); //other methods that lower stats, remove bonuses etc. here... } } </code></pre> <p>Of course, this is just a suggestion and definitely open for debate, I'm not saying that this is the best or the only way to do this...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload