public void Execute(CommandContext context) { AssertNotAdjacentToSettlement(context); var settlement = context.Player.UseAvailableSettlement(); context.TargetNode.Add(settlement); context.Player.Spend( Resource.Brick, Resource.Wheat, Resource.Sheep, Resource.Wood); }
public void Execute(CommandContext context) { if (!context.Game.Board.RoadGraph .GetNeighbors(context.TargetEdge) .Any(edge => edge.Has<Road>() && context.Player.Roads.Contains(edge.Get<Road>()))) throw new Exception("Target road must be adjacent to another road"); var road = new Road(); context.Player.Roads.Add(road); context.TargetEdge.Add(road); }
private void AssertNotAdjacentToSettlement(CommandContext context) { if (context.Game.Board.RoadGraph.GetNeighbors(context.TargetNode).Any(n => n.Get<Settlement>() != null)) throw new Exception("Cannot place settlement immediately next to another settlement"); }
private CommandContext CreateContext(Node targetNode, Dictionary<Node, IEnumerable<Edge>> roadNodes, List<Resource> startingResources = null) { startingResources = startingResources ?? new List<Resource> { Resource.Wheat, Resource.Brick, Resource.Sheep, Resource.Wood, Resource.Wood }; var player = new Player { AvailableSettlements = new List<Settlement> { new Settlement() }, Settlements = new List<Settlement>(), Resources = startingResources }; var context = new CommandContext { Game = new Game { Board = new Board { RoadGraph = new Graph(roadNodes) }, Players = new List<Player> { player } }, Player = player, TargetNode = targetNode }; return context; }