コード例 #1
0
            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);
            }
コード例 #2
0
    // 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);
    }
コード例 #3
0
 //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;
 }
コード例 #4
0
ファイル: Creature.cs プロジェクト: JHNUXER/Roguelike
 public void AttackCreature(ref ICreature creature)
 {
     if (FlamingAttack != null)
     {
         FlamingAttack(this);
     }
     AttackStrategy.AttackCreature(this, ref creature);
 }
コード例 #5
0
    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);
    }
コード例 #6
0
 public void UnEquipWeapon()
 {
     if (weaponModel != null)
     {
         currentAttackStrategy.ReleaseAttackStrategy();
         currentAttackStrategy = null;
         Destroy(weaponModel);
         weaponModel = null;
     }
 }
コード例 #7
0
        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();
        }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
        private static IMoveToStrategy DetermineStrategy(Tower towerFrom, Tower towerTo)
        {
            IMoveToStrategy strategy;

            if (AreFriendlyTowers(towerFrom, towerTo))
            {
                strategy = new ReinforceStrategy();
            }
            else
            {
                strategy = new AttackStrategy();
            }

            return(strategy);
        }
コード例 #10
0
ファイル: StaticUtils.cs プロジェクト: SybelBlue/Feldgeister
    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);
    }
コード例 #11
0
            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);
            }
コード例 #12
0
ファイル: Program.cs プロジェクト: FlintShi/FootballGame
        /// <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();
        }
コード例 #13
0
ファイル: Robot.cs プロジェクト: chj4535/study
 public void SetAttackStrategy(AttackStrategy attackStrategy)
 {
     this.attackStrategy = attackStrategy;
 }
コード例 #14
0
 public void SetAttackStrategy(AttackStrategy AttackStrategy)
 {
     this.AttackStrategy = AttackStrategy;
 }
コード例 #15
0
ファイル: Player.cs プロジェクト: TorideX/Design-Patterns
 public void Attack(object target)
 {
     AttackStrategy?.Attack(target);
 }
コード例 #16
0
 //Setter to dynamically change attack strategy
 public void SetStrategy(AttackStrategy attackStrategy)
 {
     Console.WriteLine("{0} {1} has changed attack strategy.", charType, name);
     this.attackStrategy = attackStrategy;
 }
コード例 #17
0
 /// <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)
 {
 }