public void HexagonNet_GetNeighbourFor_ReturnsCorrectNeighbour()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(2).SetHexagonNet(net),
                new BubbleNode(3).SetHexagonNet(net),
                new BubbleNode(4).SetHexagonNet(net),
                new BubbleNode(5).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(6).SetHexagonNet(net),
                new BubbleNode(7).SetHexagonNet(net),
                new BubbleNode(8).SetHexagonNet(net),
                new BubbleNode(9).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(11).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(12).SetHexagonNet(net),
                new BubbleNode(13).SetHexagonNet(net),
                new BubbleNode(14).SetHexagonNet(net),
                new BubbleNode(15).SetHexagonNet(net),
                new BubbleNode(16).SetHexagonNet(net),
                new BubbleNode(17).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var secondNodeMiddleRow = middleRow.Nodes[1];

            // act
            var secondNodeMiddleRow_LowerLeftNeighbour  = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.LowerLeft);
            var secondNodeMiddleRow_LowerRightNeighbour = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.LowerRight);
            var secondNodeMiddleRow_LeftNeighbour       = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.Left);
            var secondNodeMiddleRow_RightNeighbour      = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.Right);
            var secondNodeMiddleRow_UpperLeftNeighbour  = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.UpperLeft);
            var secondNodeMiddleRow_UpperRightNeighbour = (BubbleNode)net.GetNeighbourFor(secondNodeMiddleRow, HexagonNetEnums.Neighbours.UpperRight);

            // assert
            Assert.AreEqual(13, secondNodeMiddleRow_LowerLeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(14, secondNodeMiddleRow_LowerRightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(6, secondNodeMiddleRow_LeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(8, secondNodeMiddleRow_RightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(1, secondNodeMiddleRow_UpperLeftNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
            Assert.AreEqual(2, secondNodeMiddleRow_UpperRightNeighbour.Value.Exponent, $"HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Example #2
0
    bool hasObstacle(int row, int col)
    {
        BubbleNode node = null;

        if (RelativeDitionary.ContainsKey(row * GameConst.width + col))
        {
            node = RelativeDitionary[row * GameConst.width + col];
        }
        if (GameConst.sceneObstacles[row, col] != null)
        {
            return(true);
        }
        else if (node != null && (node.bubbleRow == row && node.bubbleCol == col))
        {
            if (node.bubbleRelative == BubbleRelative.OutLine)
            {
                return(true);
            }
            else if (node.bubbleRelative == BubbleRelative.OutEdge)
            {
                return(true);
            }
        }
        return(false);
    }
Example #3
0
    public void AddBubbleRelative(int row, int col)
    {
        Bubble           bubble     = GameConst.bubbles[row, col];
        BubbleInlineBox  inlineBox  = GameConst.bubbles[row, col].GetComponent <BubbleInlineBox>();
        BubbleOutlineBox outlineBox = GameConst.bubbles[row, col].GetComponent <BubbleOutlineBox>();

        if (behurtBox.BoxInline(inlineBox))
        {
            BubbleNode node = new BubbleNode();
            node.bubbleRelative = BubbleRelative.Inline;
            node.bubbleRow      = row;
            node.bubbleCol      = col;
            RelativeDitionary.Add(row * GameConst.width + col, node);
        }
        else if (colliderBox.BoxInline(outlineBox))
        {
            BubbleNode node = new BubbleNode();
            node.bubbleRelative = BubbleRelative.OutLine;
            node.bubbleRow      = row;
            node.bubbleCol      = col;
            RelativeDitionary.Add(row * GameConst.width + col, node);
        }
        else
        {
            BubbleNode node = new BubbleNode();
            node.bubbleRelative = BubbleRelative.OutEdge;
            node.bubbleRow      = row;
            node.bubbleCol      = col;
            RelativeDitionary.Add(row * GameConst.width + col, node);
        }
    }
Example #4
0
    void RollBackPosition()
    {
        int maxCount = Mathf.Max(GameConst.width, GameConst.height);

        while (maxCount > 0)
        {
            maxCount--;
            int        row    = (int)getCurrentGridPos().y;
            int        col    = (int)getCurrentGridPos().x;
            Vector3    offset = transform.position - prePosition;
            BubbleNode node   = null;
            if (RelativeDitionary.ContainsKey(row * GameConst.width + col))
            {
                node = RelativeDitionary[row * GameConst.width + col];
            }
            if (GameConst.sceneObstacles[row, col] != null)
            {
                AABBox box = getGridBox(row, col);
                RollbackPosition(getRollBackDirection(offset), colliderBox, box);
            }
            else if (node != null && (node.bubbleRow == row && node.bubbleCol == col))
            {
                if (node.bubbleRelative == BubbleRelative.OutLine)
                {
                    AABBox box = GameConst.bubbles[row, col].GetComponent <BubbleInlineBox>();
                    RollbackPosition(getRollBackDirection(offset), behurtBox, box);
                }
                else if (node.bubbleRelative == BubbleRelative.OutEdge)
                {
                    AABBox box = GameConst.bubbles[row, col].GetComponent <BubbleOutlineBox>();
                    RollbackPosition(getRollBackDirection(offset), colliderBox, box);
                }
                else
                {
                    Vector2 grid = checkRoadObstacle();
                    if (grid.Equals(Vector2.zero))
                    {
                        break;
                    }
                    Vector2 center = getCenter((int)grid.y, (int)grid.x);
                    transform.position = new Vector3(center.x, center.y, transform.position.z);
                    resetColliderBox();
                    resetBeHurtBox();
                }
            }
            else
            {
                Vector2 grid = checkRoadObstacle();
                if (grid.Equals(Vector2.zero))
                {
                    break;
                }
                Vector2 center = getCenter((int)grid.y, (int)grid.x);
                transform.position = new Vector3(center.x, center.y, transform.position.z);
                resetColliderBox();
                resetBeHurtBox();
            }
        }
    }
Example #5
0
        public void GameBoard_MergeBubbles_EvenMoreSimilarAtTheTopValid()
        {
            // arrange
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net)
            };
            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net)
            };
            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net)
            };

            var topRow    = new HexagonNetRow <Bubble>(bubblesForTopRow);
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var gameBoard = new GameBoard(net);

            var startBubble = net.BottomRow.Nodes[3];

            var expectedNetToString =
                $" 10 10 10 10 10 10{Environment.NewLine}" +
                $" 10 10 null null 10 10{Environment.NewLine}" +
                $" null null null 3 null null{Environment.NewLine}";

            // act
            gameBoard.MergeBubbles(startBubble);

            // assert

            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
        public void HexagonNet_ChangingNeighbours_ChangesNeighbourNodesInNet()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(2).SetHexagonNet(net),
                new BubbleNode(3).SetHexagonNet(net),
                new BubbleNode(4).SetHexagonNet(net),
                new BubbleNode(5).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(6).SetHexagonNet(net),
                new BubbleNode(7).SetHexagonNet(net),
                new BubbleNode(8).SetHexagonNet(net),
                new BubbleNode(9).SetHexagonNet(net),
                new BubbleNode(10).SetHexagonNet(net),
                new BubbleNode(11).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(12).SetHexagonNet(net),
                new BubbleNode(13).SetHexagonNet(net),
                new BubbleNode(14).SetHexagonNet(net),
                new BubbleNode(15).SetHexagonNet(net),
                new BubbleNode(16).SetHexagonNet(net),
                new BubbleNode(17).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            var secondNodeMiddleRow = middleRow.Nodes[1];

            var expectedNet         = HexagonNetTestHelper.GenerateTestNet3Rows(0, 1, -1000, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
            var expectedNetToString = expectedNet.ToString();

            // act
            secondNodeMiddleRow.GetNeighbour(Neighbours.UpperRight).Value.Exponent = -1000;

            // assert
            Assert.AreEqual(expectedNetToString, net.ToString(), $"Actual HexagonNet as string: {Environment.NewLine}{net.ToString()}");
        }
Example #7
0
    public bool ContainsOutlineBubbleRelative(int row, int col)
    {
        if (!RelativeDitionary.ContainsKey(row * GameConst.width + col))
        {
            return(false);
        }
        BubbleNode node = RelativeDitionary[row * GameConst.width + col];

        if (node.bubbleRow == row && node.bubbleCol == col && node.bubbleRelative == BubbleRelative.OutLine)
        {
            return(true);
        }
        return(false);
    }
        /// <summary>
        /// Generate a HexagonNet and add three rows to it with Bubbles, whose exponents are specified in parameters.
        /// </summary>
        /// <param name="exponents"></param>
        /// <returns></returns>
        public static HexagonNet <Bubble> GenerateTestNet3Rows(params int[] exponents)
        {
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(exponents[0]).SetHexagonNet(net),
                new BubbleNode(exponents[1]).SetHexagonNet(net),
                new BubbleNode(exponents[2]).SetHexagonNet(net),
                new BubbleNode(exponents[3]).SetHexagonNet(net),
                new BubbleNode(exponents[4]).SetHexagonNet(net),
                new BubbleNode(exponents[5]).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(exponents[6]).SetHexagonNet(net),
                new BubbleNode(exponents[7]).SetHexagonNet(net),
                new BubbleNode(exponents[8]).SetHexagonNet(net),
                new BubbleNode(exponents[9]).SetHexagonNet(net),
                new BubbleNode(exponents[10]).SetHexagonNet(net),
                new BubbleNode(exponents[11]).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(exponents[12]).SetHexagonNet(net),
                new BubbleNode(exponents[13]).SetHexagonNet(net),
                new BubbleNode(exponents[14]).SetHexagonNet(net),
                new BubbleNode(exponents[15]).SetHexagonNet(net),
                new BubbleNode(exponents[16]).SetHexagonNet(net),
                new BubbleNode(exponents[17]).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(topRow);
            net.AddBottomRow(middleRow);
            net.AddBottomRow(bottomRow);

            return(net);
        }
Example #9
0
    void UpdateBubbleRelative()
    {
        List <int> newList = new List <int>();

        foreach (KeyValuePair <int, BubbleNode> kv in RelativeDitionary)
        {
            BubbleNode node = kv.Value;
            int        key  = kv.Key;
            if (GameConst.bubbles[node.bubbleRow, node.bubbleCol] == null)
            {
                newList.Add(key);
                continue;
            }
            BubbleInlineBox  inlineBox  = GameConst.bubbles[node.bubbleRow, node.bubbleCol].GetComponent <BubbleInlineBox>();
            BubbleOutlineBox outlineBox = GameConst.bubbles[node.bubbleRow, node.bubbleCol].GetComponent <BubbleOutlineBox>();
            switch (node.bubbleRelative)
            {
            case BubbleRelative.Inline:
                if (!behurtBox.BoxInline(inlineBox))
                {
                    node.bubbleRelative = BubbleRelative.OutLine;
                }
                break;

            case BubbleRelative.OutLine:
                if (!colliderBox.BoxInline(outlineBox))
                {
                    node.bubbleRelative = BubbleRelative.OutEdge;
                    newList.Add(key);
                }
                break;

            case BubbleRelative.OutEdge:
                break;
            }
        }
        foreach (int node in newList)
        {
            RelativeDitionary.Remove(node);
        }
    }
        public void HexagonNet_EnumeratedThrough_ValuesShouldBeSortedByKeys()
        {
            // arrange
            HexagonNet <Bubble> net = new HexagonNet <Bubble>();

            var bubblesForTopRow = new BubbleNode[]
            {
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net),
                new BubbleNode(-1).SetHexagonNet(net)
            };
            var topRow = new HexagonNetRow <Bubble>(bubblesForTopRow);

            var bubblesForMiddleRow = new BubbleNode[]
            {
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net),
                new BubbleNode(0).SetHexagonNet(net)
            };
            var middleRow = new HexagonNetRow <Bubble>(bubblesForMiddleRow);

            var bubblesForLowerMiddleRow = new BubbleNode[]
            {
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net),
                new BubbleNode(1).SetHexagonNet(net)
            };
            var lowerMiddleRow = new HexagonNetRow <Bubble>(bubblesForLowerMiddleRow);

            var bubblesForBottomRow = new BubbleNode[]
            {
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net),
                new BubbleNode(null).SetHexagonNet(net)
            };
            var bottomRow = new HexagonNetRow <Bubble>(bubblesForBottomRow);

            net.AddTopRow(middleRow);
            net.AddTopRow(topRow);
            net.AddBottomRow(lowerMiddleRow);
            net.AddBottomRow(bottomRow);

            var expectedNetAsString =
                " -1 -1 -1 -1 -1 -1" + Environment.NewLine +
                " 0 0 0 0 0 0" + Environment.NewLine +
                " 1 1 1 1 1 1" + Environment.NewLine +
                " null null null null null null" + Environment.NewLine;

            // act
            string netAsString = net.ToString();

            // assert
            Assert.AreEqual(expectedNetAsString, netAsString, $"HexagonNet as string: {Environment.NewLine}{netAsString}");
        }