Exemplo n.º 1
0
        private bool[][][] getAllowedStaedteByClient(CatanClient client)
        {
            if (client.SpielfigurenContainer.Siedlungen?.Count <= 0)
            {
                return(null);
            }

            var allowedStaedte = initilize3DBoolArrayBasedOnHexfields();

            foreach (var siedlung in client.SpielfigurenContainer.Siedlungen)
            {
                var gridPoint = HexagonGrid.GetGridPointByHexagonPositionAndPoint(siedlung.HexagonPosition, siedlung.HexagonPoint);
                foreach (var hexPosEdge in HexagonGrid.GetHexagonEdgesByGridPoint(HexagonGrid.GetHexagonesByGridPoint(gridPoint), gridPoint))
                {
                    if (client.SpielfigurenContainer.Strassen.Find(strasse =>
                                                                   HexagonGrid.IsHexagonEdgeOnHexagonEdge(hexPosEdge, new HexagonPositionHexagonEdge(strasse.HexagonPosition, strasse.HexagonEdge))) != null)
                    {
                        allowedStaedte[siedlung.HexagonPosition.RowIndex][siedlung.HexagonPosition.ColumnIndex][siedlung.HexagonPoint.Index] = true;
                        break;
                    }
                }
            }

            return(allowedStaedte);
        }
Exemplo n.º 2
0
        private void addNewKartenByClient(CatanClient cclient)
        {
            foreach (var strasse in cclient.SpielfigurenContainer.Strassen)
            {
                var            foundHexagons = new List <Hexagon>();
                List <Hexagon> tempHexagons;
                tempHexagons = HexagonGrid.GetHexagonesByGridPoint(HexagonGrid.GetGridPointByHexagonPositionAndPoint(strasse.HexagonPosition, strasse.HexagonEdge.PointA));
                foreach (var tempHex in tempHexagons)
                {
                    if (!foundHexagons.Exists(hex => hex.Position.Equals(tempHex.Position)))
                    {
                        foundHexagons.Add(tempHex);
                    }
                }
                tempHexagons = HexagonGrid.GetHexagonesByGridPoint(HexagonGrid.GetGridPointByHexagonPositionAndPoint(strasse.HexagonPosition, strasse.HexagonEdge.PointB));

                foreach (var tempHex in tempHexagons)
                {
                    if (!foundHexagons.Exists(hex => hex.Position.Equals(tempHex.Position)))
                    {
                        foundHexagons.Add(tempHex);
                    }
                }

                // checking edges
                foreach (var hex in foundHexagons)
                {
                    foreach (var edge in hex.Edges)
                    {
                        if (HexagonGrid.IsHexagonEdgeOnHexagonEdge(new HexagonPositionHexagonEdge(hex.Position, edge), new HexagonPositionHexagonEdge(strasse.HexagonPosition, strasse.HexagonEdge)))
                        {
                            cclient.KartenContainer.AddRohstoffkarte(Game.LandFeld.GetErtragByLandFeldTyp(hex.LandFeldTyp)); // matched hex
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private bool[][][] getAllowedStrassenByClient(CatanClient client)
        {
            if (client.SpielfigurenContainer.Siedlungen?.Count <= 0)
            {
                return(null);
            }

            bool[][][] allowedStrassen = initilize3DBoolArrayBasedOnHexfields();
            #region An den eigenen Siedlungen und Städten dürfen Straßen gebaut werden

            // Siedlungen
            foreach (var siedlung in client.SpielfigurenContainer.Siedlungen)
            {
                var hexPosEdges = HexagonGrid.GetHexagonEdgesByGridPoint(HexagonGrid.Instance.HexagonesList, HexagonGrid.GetGridPointByHexagonPositionAndPoint(siedlung.HexagonPosition, siedlung.HexagonPoint));
                foreach (var hexPosEdge in hexPosEdges)
                {
                    allowedStrassen[hexPosEdge.HexagonPosition.RowIndex][hexPosEdge.HexagonPosition.ColumnIndex][hexPosEdge.HexagonEdge.Index] =
                        client.SpielfigurenContainer.Strassen.Find(strasse =>
                                                                   HexagonGrid.IsHexagonEdgeOnHexagonEdge(hexPosEdge, new HexagonPositionHexagonEdge(strasse.HexagonPosition, strasse.HexagonEdge))) == null;
                }
            }
            // Städte
            foreach (var stadt in client.SpielfigurenContainer.Staedte)
            {
                var hexPosEdges = HexagonGrid.GetHexagonEdgesByGridPoint(HexagonGrid.Instance.HexagonesList, HexagonGrid.GetGridPointByHexagonPositionAndPoint(stadt.HexagonPosition, stadt.HexagonPoint));
                foreach (var hexPosEdge in hexPosEdges)
                {
                    allowedStrassen[hexPosEdge.HexagonPosition.RowIndex][hexPosEdge.HexagonPosition.ColumnIndex][hexPosEdge.HexagonEdge.Index] =
                        client.SpielfigurenContainer.Strassen.Find(strasse =>
                                                                   HexagonGrid.IsHexagonEdgeOnHexagonEdge(hexPosEdge, new HexagonPositionHexagonEdge(strasse.HexagonPosition, strasse.HexagonEdge))) == null;
                }
            }

            #endregion

            #region An den eigenen Straßen dürfen Straßen gebaut werden und auf der keine fremde Siedlung oder Stadt steht

            foreach (var strasse in client.SpielfigurenContainer.Strassen)
            {
                var gridPointA = HexagonGrid.GetGridPointByHexagonPositionAndPoint(strasse.HexagonPosition, strasse.HexagonEdge.PointA);
                var gridPointB = HexagonGrid.GetGridPointByHexagonPositionAndPoint(strasse.HexagonPosition, strasse.HexagonEdge.PointB);

                foreach (var allowedGridPoint in new List <GridPoint>()
                {
                    gridPointA, gridPointB
                })
                {
                    foreach (var allowedHexagonEdge in HexagonGrid.GetHexagonEdgesByGridPoint(HexagonGrid.Instance.HexagonesList, allowedGridPoint).Where(hexPosEdge =>
                                                                                                                                                          catanClients.Find(_client => _client.SpielfigurenContainer.Strassen.Find(_strasse =>
                                                                                                                                                                                                                                   HexagonGrid.IsHexagonEdgeOnHexagonEdge(hexPosEdge, new HexagonPositionHexagonEdge(_strasse.HexagonPosition, _strasse.HexagonEdge))) != null) == null).ToList())

                    {
                        allowedStrassen[allowedHexagonEdge.HexagonPosition.RowIndex][allowedHexagonEdge.HexagonPosition.ColumnIndex][allowedHexagonEdge.HexagonEdge.Index] = true;
                    }
                }
            }

            #endregion

            return(allowedStrassen);
        }