Let's say I have an ai or player, I want him to be able to use different weapons. My design with weapons:
public class Weapon() { public virtual void FireWeapon(){} // this is useless for melee weapons public virtual void SwingMelee(){} // this is useless for guns public virtual void Reload(){} // this is also useless for melee weapons } Then in the ai controller class I simply call the function I want him to do. This is where the ugly part is (I think)... Controller class have a list containing some different weapons of ai and a weapon which is being used.
public class WeaponController { private List<Weapon> someWeapons; private Weapon aWeapon; public void Main() { if(/*"Some action or a button click" &&*/ aWeapon.CanSwingMelee() ) aWeapon.SwingMelee(); if(/*"Some action or a button click" &&*/ aWeapon.CanReload() ) aWeapon.Reload(); } } What is the better way to implement this? do you have any advices? Seems that for every different action in a new weapon, I need to implement a function in the most parent Weapon class and I don't think it's a good idea...
Use, and whether it's a swing or a shot, it's just used... why be so specific? It's going to do damage at the end of the day, right, that should be what countsUseWeaponmethod and then implement classes that fire or swing based on what they are. Basically you want the weapon to know how it's used.