Esempio n. 1
0
    public HexagonPosition GetRandomPosition(bool needUp)
    {
        HexagonPosition position = HexagonPosition.None;

        if (!isBoard && lower == null && upper == null)
        {
            if (needUp && upperState != HexagonState.Rock)
            {
                position = HexagonPosition.Upper;
            }
            else if (!needUp && lowerState != HexagonState.Rock)
            {
                position = HexagonPosition.Lower;
            }
        }
        else if (lower == null && !isBoard && lowerState != HexagonState.Rock)
        {
            position = HexagonPosition.Lower;
        }
        else if (upper == null && upperState != HexagonState.Rock)
        {
            position = HexagonPosition.Upper;
        }
        return(position);
    }
Esempio n. 2
0
        public static HexagonPosition GetRelation(HexagonPosition pos)
        {
            switch (pos)
            {
            case HexagonPosition.Top:
                return(HexagonPosition.Bottom);

            case HexagonPosition.TopRight:
                return(HexagonPosition.BottomLeft);

            case HexagonPosition.BottomRight:
                return(HexagonPosition.TopLeft);

            case HexagonPosition.Bottom:
                return(HexagonPosition.Top);

            case HexagonPosition.BottomLeft:
                return(HexagonPosition.TopRight);

            case HexagonPosition.TopLeft:
                return(HexagonPosition.BottomRight);

            default:
                throw new Exception("Unknown Hexagon Position");
            }
        }
Esempio n. 3
0
        public static int ToInt(this HexagonPosition pos)
        {
            switch (pos)
            {
            case HexagonPosition.Top:
                return(1);

            case HexagonPosition.TopRight:
                return(2);

            case HexagonPosition.BottomRight:
                return(3);

            case HexagonPosition.Bottom:
                return(4);

            case HexagonPosition.BottomLeft:
                return(5);

            case HexagonPosition.TopLeft:
                return(6);

            default:
                throw new InvalidOperationException(MapExceptions.UnknownHexagonPositionToInt);
            }
        }
Esempio n. 4
0
        private void generateHexagonGrid()
        {
            Hexagon.LandfeldTyp[] randomHexagonFieldTypes = generateRandomHexagonFieldTyps();
            int[] nrChips = { 5, 2, 6, 3, 8, 10, 9, 12, 11, 4, 8, 10, 9, 4, 5, 6, 3, 11, 1 };


            // 7 Rows
            Hexagones    = new Hexagon[5][];
            Hexagones[0] = new Hexagon[3]; // Row 0, Columns 3
            Hexagones[1] = new Hexagon[4];
            Hexagones[2] = new Hexagon[5];
            Hexagones[3] = new Hexagon[4];
            Hexagones[4] = new Hexagon[3];

            int count = 0;

            for (int rowIndex = 0; rowIndex < Hexagones.GetLength(0); rowIndex++)
            {
                var points = new HexagonPoint[6];

                for (int columnIndex = 0; columnIndex < Hexagones[rowIndex].GetLength(0); columnIndex++)
                {
                    var hexPosition = new HexagonPosition(rowIndex, columnIndex);
                    for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
                    {
                        points[pointIndex] = new HexagonPoint(pointIndex);
                    }

                    Hexagones[rowIndex][columnIndex] = new Hexagon(hexPosition, randomHexagonFieldTypes[count], nrChips[count], points.ToList());
                    count++;
                }
            }
        }
Esempio n. 5
0
        public static GridPoint GetGridPointByHexagonPositionAndPoint(HexagonPosition hexagonPosition, HexagonPoint hexPoint)
        {
            GridPoint pointIndexTest = null; // point index 0

            switch (hexagonPosition.RowIndex)
            {
            case 0: pointIndexTest = new GridPoint(3, hexagonPosition.RowIndex * 2); break;

            case 1: pointIndexTest = new GridPoint(2, hexagonPosition.RowIndex * 2); break;

            case 2: pointIndexTest = new GridPoint(1, hexagonPosition.RowIndex * 2); break;

            case 3: pointIndexTest = new GridPoint(2, hexagonPosition.RowIndex * 2); break;

            case 4: pointIndexTest = new GridPoint(3, hexagonPosition.RowIndex * 2); break;

            default:
                throw new NotImplementedException($"getGridPointByHexagonRowIndexColumnIndex ");
            }
            if (hexPoint.Index == 0)
            {
                ;
            }
            else if (hexPoint.Index == 1)
            {
                pointIndexTest.Offset(1, 1);
            }
            else if (hexPoint.Index == 2)
            {
                pointIndexTest.Offset(1, 2);
            }
            else if (hexPoint.Index == 3)
            {
                pointIndexTest.Offset(0, 3);
            }
            else if (hexPoint.Index == 4)
            {
                pointIndexTest.Offset(-1, 2);
            }
            else if (hexPoint.Index == 5)
            {
                pointIndexTest.Offset(-1, 1);
            }
            else
            {
                throw new NotImplementedException($"getGridPointByHexagonRowIndexColumnIndex ");
            }

            if (hexagonPosition.ColumnIndex > 0)
            {
                pointIndexTest.Offset(2 * hexagonPosition.ColumnIndex, 0);
            }


            return(pointIndexTest);
        }
Esempio n. 6
0
        public Coords GetNearbyCoords(HexagonPosition nearby)
        {
            switch (nearby)
            {
            case HexagonPosition.Top:
                return(new Coords(Coord.X, Coord.Y + 1));

            case HexagonPosition.TopRight:
                if (Coord.X % 2 == 0)
                {
                    return(new Coords(Coord.X + 1, Coord.Y));
                }
                else
                {
                    return(new Coords(Coord.X + 1, Coord.Y + 1));
                }

            case HexagonPosition.BottomRight:
                if (Coord.X % 2 == 0)
                {
                    return(new Coords(Coord.X + 1, Coord.Y - 1));
                }
                else
                {
                    return(new Coords(Coord.X + 1, Coord.Y));
                }

            case HexagonPosition.Bottom:
                return(new Coords(Coord.X, Coord.Y - 1));

            case HexagonPosition.TopLeft:
                if (Coord.X % 2 == 0)
                {
                    return(new Coords(Coord.X - 1, Coord.Y));
                }
                else
                {
                    return(new Coords(Coord.X - 1, Coord.Y + 1));
                }

            case HexagonPosition.BottomLeft:
                if (Coord.X % 2 == 0)
                {
                    return(new Coords(Coord.X - 1, Coord.Y - 1));
                }
                else
                {
                    return(new Coords(Coord.X - 1, Coord.Y));
                }

            default:
                throw new InvalidOperationException("Unknown nearby hexagon");
            }
        }
Esempio n. 7
0
        public void Hexagon_GetNearbyCoords(int x, int y, HexagonPosition pos, int xRes, int yRes)
        {
            //Arrange
            Hexagon hex = new Hexagon(x, y);

            //Act
            int xNew = hex.GetNearbyCoords(pos).X;
            int yNew = hex.GetNearbyCoords(pos).Y;

            //Assert
            Assert.AreEqual(xRes, xNew);
            Assert.AreEqual(yRes, yNew);
        }
Esempio n. 8
0
 public HexagonPositionHexagonPoint(HexagonPosition hexagonPosition, HexagonPoint hexagonPoint)
 {
     this.HexagonPosition = hexagonPosition;
     this.Point           = hexagonPoint;
 }
Esempio n. 9
0
 public HexagonPositionHexagonEdge(HexagonPosition hexagonPosition, HexagonEdge hexagonEdge)
 {
     this.HexagonPosition = hexagonPosition;
     this.HexagonEdge     = hexagonEdge;
 }
Esempio n. 10
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));
 }