Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Commands/CreateAndAddUnitCommand.cs @ 0:520818033bb6
Initial commit of WarFoundry code
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 19 Dec 2008 15:57:51 +0000 |
parents | |
children | 306558904c2a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Commands/CreateAndAddUnitCommand.cs Fri Dec 19 15:57:51 2008 +0000 @@ -0,0 +1,67 @@ +using System; +using IBBoard.Commands; +using IBBoard.Lang; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for AddUnitCommand. + /// </summary> + public class CreateAndAddUnitCommand : Command + { + private UnitType addedUnitType; + private Army army; + private ArmyCategory cat; + private Unit addedUnit; + + public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) + { + addedUnitType = toAdd; + cat = catTo; + army = armyTo; + } + + public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) + { + } + + public override bool CanExecute() + { + return (addedUnitType!=null && army!=null); + } + + public override string Description + { + get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } + } + + public override string UndoDescription + { + get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } + } + + public override bool Execute() + { + addedUnit = new Unit(addedUnitType, army); + this.Redo(); + return true; + } + + public override void Redo() + { + cat.AddUnit(addedUnit); + } + + public override void Undo() + { + cat.RemoveUnit(addedUnit); + } + + + public override string Name + { + get { return "Add new unit"; } + } + } +}