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 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 GetsThePlayerWithTheProperTag_02() { PlacedFormation placedFormation = new PlacedFormation(); placedFormation.leftTackle.tag = "LT"; placedFormation.skillPlayers[2].tag = "X"; PlacedPlayer expectedPlayer = placedFormation.leftTackle; PlacedPlayer returnedPlayer = placedFormation.GetPlayerByTag("LT"); bool sameObject = ReferenceEquals(expectedPlayer, returnedPlayer); Assert.True(sameObject); }
public void GettingPlayerWithNonexistantTagThrowsException() { PlacedFormation placedFormation = new PlacedFormation(); placedFormation.leftTackle.tag = "LT"; placedFormation.skillPlayers[2].tag = "X"; PlacedFormationException ex = Assert.Throws <PlacedFormationException>(() => placedFormation.GetPlayerByTag("Nonexistent")); Assert.Equal("No player in formation has tag Nonexistent", ex.Message); }