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)); }
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())); }
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())); }
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())); }
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); }
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)); }
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())); }
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); }
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())); }
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); }
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); }
public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation) { return(new OnLineOfScrimmage()); }
public IPlacementRule GetPlacementRule(FormationRule formationRule, PlacedFormation placedFormation) { return(new FakePlacementRule()); }