private List <List <Card> > GetAttackersDeclarations() { var results = new List <List <Card> >(); var noAttackers = new List <Card>(); results.Add(noAttackers); var allAttackers = Controller.Battlefield.CreaturesThatCanAttack.ToList(); if (allAttackers.Count > 0) { var parameters = new AttackStrategyParameters { AttackerCandidates = allAttackers, BlockerCandidates = Defender.Battlefield.CreaturesThatCanBlock.ToList(), DefendingPlayersLife = Defender.Life }; var chosenAttackers = new AttackStrategy(parameters).ChooseAttackers(); if (chosenAttackers.Count > 0) { results.Add(chosenAttackers); } if (chosenAttackers.Count < allAttackers.Count) { results.Add(allAttackers); } } return(results); }
// The main way to construct strategies public static Strategy StrategyWithType(int playerNum, StrategyType type) { Strategy newStrategy = null; switch (type) { case StrategyType.Attack: newStrategy = new AttackStrategy(playerNum); break; case StrategyType.DigDown: newStrategy = new DigDownStrategy(playerNum); break; case StrategyType.GetAmmo: newStrategy = new GetAmmoStrategy(playerNum); break; case StrategyType.RunAway: newStrategy = new RunAwayStrategy(playerNum); break; } if (newStrategy != null) { newStrategy.type = type; } return(newStrategy); }
//Constructor public Role(string charType, string name, double hitPoints, AttackStrategy attackStrategy, DefenseStrategy defenseStrategy) { this.charType = charType; this.name = name; this.hitPoints = hitPoints; this.attackStrategy = attackStrategy; this.defenseStrategy = defenseStrategy; }
public void AttackCreature(ref ICreature creature) { if (FlamingAttack != null) { FlamingAttack(this); } AttackStrategy.AttackCreature(this, ref creature); }
private void LoadWeaponModel(WeaponData data) { GameObject foundModel = AssetBundleCacher.Instance.LoadAndGetAsset("weapon", data.Name) as GameObject; weaponModel = Instantiate(foundModel, WeaponGrapTarget); currentAttackStrategy = weaponModel.GetComponent <AttackStrategy>(); currentAttackStrategy.Initialize(weaponData, EndAttack); }
public void UnEquipWeapon() { if (weaponModel != null) { currentAttackStrategy.ReleaseAttackStrategy(); currentAttackStrategy = null; Destroy(weaponModel); weaponModel = null; } }
static void Main(string[] args) { TeamContext teamContext = new TeamContext(); AttackStrategy attackStrategy = new AttackStrategy(); DefendStrategy defendStrategy = new DefendStrategy(); teamContext.setStartegy(attackStrategy); teamContext.PlayGame(); teamContext.setStartegy(defendStrategy); teamContext.PlayGame(); }
void CheckDistance() { if (Vector3.Distance(target.position, transform.position) <= aggroRadius) { if (!(strategy is AttackStrategy)) { strategy = new AttackStrategy(); } } else if (!(strategy is RoamStrategy)) { strategy = new RoamStrategy(); } }
private static IMoveToStrategy DetermineStrategy(Tower towerFrom, Tower towerTo) { IMoveToStrategy strategy; if (AreFriendlyTowers(towerFrom, towerTo)) { strategy = new ReinforceStrategy(); } else { strategy = new AttackStrategy(); } return(strategy); }
public static House HouseForStrategy(AttackStrategy strat, List <House> houses) { houses.Shuffle(); switch (strat) { case AttackStrategy.Random: return(houses.RandomChoice()); case AttackStrategy.Weakest: return(houses.MinBy(h => h.defenseLevel)); case AttackStrategy.Strongest: return(houses.MaxBy(h => h.defenseLevel)); } throw new System.Exception("Unknown strat: " + strat); }
private List <ChosenAttackers> GetAttackersDeclarations() { var results = new List <ChosenAttackers>(); // First choice: only attackers that must attack results.Add(SelectAttackTarget(CreaturesThatMustAttack)); var everyCreatureThatCanAttack = RemoveAttackersIfWeCannotAffordToPayCombatCost( Controller.Battlefield.CreaturesThatCanAttack.ToList()); if (everyCreatureThatCanAttack.Count > CreaturesThatMustAttack.Count) { var parameters = new AttackStrategyParameters { AttackerCandidates = everyCreatureThatCanAttack, BlockerCandidates = Defender.Battlefield.CreaturesThatCanBlock.ToList(), DefendingPlayersLife = Defender.Life }; var greedyAttackers = new AttackStrategy(parameters) .ChooseAttackers() .Concat(CreaturesThatMustAttack) .Distinct() .ToList(); if (greedyAttackers.Count > CreaturesThatMustAttack.Count) { // Second choice: attackers selected by greedy attack strategy results.Add(SelectAttackTarget(greedyAttackers)); } if (greedyAttackers.Count < everyCreatureThatCanAttack.Count) { // Third choice: every creature that can attack results.Add(SelectAttackTarget(everyCreatureThatCanAttack)); } } return(results); }
/// <summary> /// 【策略模式】 /// /// 球队与球队策略(Team and TeamStrategy)在比赛中,终端用户可以改变球队的策略(如从进攻改为防守) /// </summary> static void Strategy() { ////'Let us create a team and set its strategy, // //'and make the teams play the game ////'Create few strategies var attack = new AttackStrategy(); var defend = new DefendStrategy(); ////'Create our teams var france = new Team("France"); var italy = new Team("Italy"); System.Console.WriteLine("Setting the strategies.."); ////'Now let us set the strategies france.SetStrategy(attack); italy.SetStrategy(defend); // //'Make the teams start the play france.PlayGame(); italy.PlayGame(); System.Console.WriteLine(); System.Console.WriteLine("Changing the strategies.."); // //'Let us change the strategies france.SetStrategy(defend); italy.SetStrategy(attack); // //'Make them play again france.PlayGame(); italy.PlayGame(); ////'Wait for a key press System.Console.Read(); }
public void SetAttackStrategy(AttackStrategy attackStrategy) { this.attackStrategy = attackStrategy; }
public void SetAttackStrategy(AttackStrategy AttackStrategy) { this.AttackStrategy = AttackStrategy; }
public void Attack(object target) { AttackStrategy?.Attack(target); }
//Setter to dynamically change attack strategy public void SetStrategy(AttackStrategy attackStrategy) { Console.WriteLine("{0} {1} has changed attack strategy.", charType, name); this.attackStrategy = attackStrategy; }
/// <summary> /// Detailed version of Constructor /// </summary> /// <param name="charType"></param> /// <param name="name"></param> /// <param name="hitPoints"></param> /// <param name="attackStrategy"></param> /// <param name="defenseStrategy"></param> public Guardian(string charType, string name, double hitPoints, AttackStrategy attackStrategy, DefenseStrategy defenseStrategy) : base(charType, name, hitPoints, attackStrategy, defenseStrategy) { }