예제 #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);
        }
예제 #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
                        }
                    }
                }
            }
        }
예제 #3
0
 public static bool IsGridPointOnHexagonEdge(HexagonPosition hexagonPosition, HexagonEdge hexagonEdge, GridPoint gridPoint)
 {
     return(HexagonGrid.GetGridPointByHexagonPositionAndPoint(hexagonPosition, hexagonEdge.PointA).Equals(gridPoint) ||
            HexagonGrid.GetGridPointByHexagonPositionAndPoint(hexagonPosition, hexagonEdge.PointB).Equals(gridPoint));
 }
예제 #4
0
        private bool[][][] getAllowedSiedlungenByClient(CatanClient client)
        {
            bool[][][] allowedSiedlungen = initilize3DBoolArrayBasedOnHexfields();

            for (int rowIndex = 0; rowIndex < allowedSiedlungen.GetLength(0); rowIndex++)
            {
                for (int columnIndex = 0; columnIndex < allowedSiedlungen[rowIndex].GetLength(0); columnIndex++)
                {
                    for (int pointIndex = 0; pointIndex < allowedSiedlungen[rowIndex][columnIndex].GetLength(0); pointIndex++)
                    {
                        var currentGridPoint = HexagonGrid.GetGridPointByHexagonPositionAndPoint(new HexagonPosition(rowIndex, columnIndex), new HexagonPoint(pointIndex));

                        var foundHexagones = HexagonGrid.GetHexagonesByGridPoint(currentGridPoint);
                        if (foundHexagones.Count >= 2)
                        {
                            #region Überprüfen, ob es schon eine Siedlung an diesem GridPoint angelegt wurde, wenn ja, dann ignorieren

                            var hexPositionAndHexPoint = HexagonGrid.GetHexagonAndHexagonPointByGridPoint(currentGridPoint);
                            if (hexPositionAndHexPoint.Exists(hexPosHexPoint => allowedSiedlungen[hexPosHexPoint.HexagonPosition.RowIndex][hexPosHexPoint.HexagonPosition.ColumnIndex][hexPosHexPoint.Point.Index]))
                            {
                                continue;
                            }

                            #endregion

                            #region Überprüfen, ob es hier eine Stadt oder Siedlung gibt

                            var stadtGefunden = catanClients.Exists(_client => _client.SpielfigurenContainer.Staedte.Find(
                                                                        stadt => HexagonGrid.GetGridPointByHexagonPositionAndPoint(stadt.HexagonPosition, stadt.HexagonPoint).Equals(currentGridPoint)) != null);

                            var siedlungGefunden = catanClients.Exists(_client => _client.SpielfigurenContainer.Siedlungen.Find(
                                                                           siedlung => HexagonGrid.GetGridPointByHexagonPositionAndPoint(siedlung.HexagonPosition, siedlung.HexagonPoint).Equals(currentGridPoint)) != null);

                            #endregion

                            if (!stadtGefunden && !siedlungGefunden)
                            {
                                #region Überprüfen, ob die drei angrenzenden Kreuzungen von Siedlungen oder Städten besetzt sind

                                allowedSiedlungen[rowIndex][columnIndex][pointIndex] = catanClients.Find(_client =>

                                                                                                         _client.SpielfigurenContainer.Siedlungen.Find(siedlung =>
                                                                                                                                                       HexagonGrid.GetHexagonEdgesByGridPoint(foundHexagones, currentGridPoint).Find(hex =>
                                                                                                                                                                                                                                     HexagonGrid.IsGridPointOnHexagonEdge(hex.HexagonPosition, hex.HexagonEdge,
                                                                                                                                                                                                                                                                          HexagonGrid.GetGridPointByHexagonPositionAndPoint(siedlung.HexagonPosition, siedlung.HexagonPoint))) != null) != null ||

                                                                                                         _client.SpielfigurenContainer.Staedte.Find(stadt =>
                                                                                                                                                    HexagonGrid.GetHexagonEdgesByGridPoint(foundHexagones, currentGridPoint).Find(hex =>
                                                                                                                                                                                                                                  HexagonGrid.IsGridPointOnHexagonEdge(hex.HexagonPosition, hex.HexagonEdge,
                                                                                                                                                                                                                                                                       HexagonGrid.GetGridPointByHexagonPositionAndPoint(stadt.HexagonPosition, stadt.HexagonPoint))) != null) != null) == null;

                                #endregion
                            }
                            else
                            {
                                allowedSiedlungen[rowIndex][columnIndex][pointIndex] = false;
                            }
                        }
                    }
                }
            }
            return(allowedSiedlungen);
        }
예제 #5
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);
        }