コード例 #1
0
        public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation)
        {
            string relativeTypeString   = formationRule.GetParameterValue("relativeType");
            string playerRelativeString = formationRule.GetParameterValue("playerRelative");
            string distanceString       = formationRule.GetParameterValue("distance");

            RelativeType relativeType;

            switch (relativeTypeString)
            {
            case "Left":
                relativeType = RelativeType.Left;
                break;

            case "Right":
                relativeType = RelativeType.Right;
                break;

            case "Inside":
                relativeType = RelativeType.Inside;
                break;

            case "Outside":
                relativeType = RelativeType.Outside;
                break;

            default:
                throw new FormationException("Relative type must be Left/Right/Inside/Outside.");
            }
            int          distance       = int.Parse(distanceString);
            PlacedPlayer playerRelative = placedFormation.GetPlayerByTag(playerRelativeString);

            return(new RelativeToPlayerHorizontally(playerRelative, distance, relativeType));
        }
コード例 #2
0
        public void PassingWrongParameterNamesThrowsException_01()
        {
            FormationRule formationRule = new FormationRule();

            formationRule.parameters.Add(new FormationRuleParameter("nonrelevantTag", "nonrelevantValue"));
            RelativeToPlayerHorizontallyAdapter relativePlayerAdapter = new RelativeToPlayerHorizontallyAdapter();

            Assert.Throws <FormationException>(() => relativePlayerAdapter.GetPlacementRule(formationRule, new PlacedFormation()));
        }
コード例 #3
0
            public void PassingWrongParameterNamesThrowsException_03()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.parameters.Add(new FormationRuleParameter("distanceBehind", "5"));
                BehindPlayerAdapter behindPlayerAdapter = new BehindPlayerAdapter();

                Assert.Throws <FormationException>(() => behindPlayerAdapter.GetPlacementRule(formationRule, new PlacedFormation()));
            }
コード例 #4
0
            public void PassingWrongParameterNamesThrowsException_01()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.parameters.Add(new FormationRuleParameter("nonrelevantTag", "nonrelevantValue"));
                BehindPlayerAdapter behindPlayerAdapter = new BehindPlayerAdapter();

                Assert.Throws <FormationException>(() => behindPlayerAdapter.GetPlacementRule(formationRule, new PlacedFormation()));
            }
コード例 #5
0
            public void GetNonexistantParameterThrowsExceptionWithProperMessage()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.rule = "Rule";

                FormationException ex = Assert.Throws <FormationException>(() => formationRule.GetParameterValue("Nonexistent"));

                Assert.Equal("The parameter Nonexistent doesn't exist for the formation rule Rule", ex.Message);
            }
コード例 #6
0
        public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation)
        {
            string behindTagParameter   = formationRule.GetParameterValue("playerBehindTag");
            string distanceBehindString = formationRule.GetParameterValue("distanceBehind");
            int    distanceBehind       = int.Parse(distanceBehindString);

            PlacedPlayer playerBehind = placedFormation.GetPlayerByTag(behindTagParameter);

            return(new BehindPlayer(playerBehind, distanceBehind));
        }
コード例 #7
0
            public void PassingNonexistentTagThrowsException()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.parameters.Add(new FormationRuleParameter("playerBehindTag", "RG"));
                formationRule.parameters.Add(new FormationRuleParameter("distanceBehind", "12"));
                BehindPlayerAdapter behindPlayerAdapter = new BehindPlayerAdapter();

                Assert.Throws <PlacedFormationException>(() => behindPlayerAdapter.GetPlacementRule(formationRule, new PlacedFormation()));
            }
コード例 #8
0
            public void GetsProperValueFromParameter()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.parameters.Add(new FormationRuleParameter("Parameter", "Value"));
                string expectedValue = "Value";

                string parameterValue = formationRule.GetParameterValue("Parameter");

                Assert.Equal(expectedValue, parameterValue);
            }
コード例 #9
0
        public void PassingNonexistentTagThrowsException()
        {
            FormationRule formationRule = new FormationRule();

            formationRule.parameters.Add(new FormationRuleParameter("playerRelative", "X"));
            formationRule.parameters.Add(new FormationRuleParameter("relativeType", "Inside"));
            formationRule.parameters.Add(new FormationRuleParameter("distance", "7"));
            RelativeToPlayerHorizontallyAdapter relativePlayerAdapter = new RelativeToPlayerHorizontallyAdapter();

            Assert.Throws <PlacedFormationException>(() => relativePlayerAdapter.GetPlacementRule(formationRule, new PlacedFormation()));
        }
コード例 #10
0
            public void PassingGoodParametersInDoesntThrowException()
            {
                FormationRule formationRule = new FormationRule();

                formationRule.parameters.Add(new FormationRuleParameter("playerBehindTag", "RG"));
                formationRule.parameters.Add(new FormationRuleParameter("distanceBehind", "12"));
                BehindPlayerAdapter behindPlayerAdapter = new BehindPlayerAdapter();
                PlacedFormation     placedFormation     = new PlacedFormation();

                placedFormation.rightGuard.tag = "RG";

                behindPlayerAdapter.GetPlacementRule(formationRule, placedFormation);
            }
コード例 #11
0
        public void PassingGoodParametersInDoesntThrowException()
        {
            FormationRule formationRule = new FormationRule();

            formationRule.parameters.Add(new FormationRuleParameter("playerRelative", "X"));
            formationRule.parameters.Add(new FormationRuleParameter("relativeType", "Inside"));
            formationRule.parameters.Add(new FormationRuleParameter("distance", "7"));
            RelativeToPlayerHorizontallyAdapter relativePlayerAdapter = new RelativeToPlayerHorizontallyAdapter();
            PlacedFormation placedFormation = new PlacedFormation();

            placedFormation.skillPlayers[1].tag = "X";

            relativePlayerAdapter.GetPlacementRule(formationRule, placedFormation);
        }
コード例 #12
0
 public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation)
 {
     return(new OnLineOfScrimmage());
 }
コード例 #13
0
 public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation)
 {
     return(new FakePlacementRule());
 }