Ejemplo n.º 1
0
        public static void ApplyChange(
            eCellType[] fieldMatrix,
            Position head,
            Position tail,
            eDirectionType currentDirection,
            eDirectionType nextDirection,
            out bool expanded)
        {
            expanded = false;

            if (nextDirection == eDirectionType.None)
            {
                return;
            }

            eCellType nextDirectionCellType = eCellType.None;

            Lookups.DirectionTypeToCellType(nextDirection, ref nextDirectionCellType);

            Position nextHeadPosition = new Position();

            Lookups.ApplyDirection(head, nextHeadPosition, nextDirection);

            ThrowIfCrashed(fieldMatrix, nextHeadPosition);

            eCellType tailCellType, nextHeadCellType;

            FieldMatrix.GetCellTypeByPosition(fieldMatrix, tail, out tailCellType);
            FieldMatrix.GetCellTypeByPosition(fieldMatrix, nextHeadPosition, out nextHeadCellType);

            // move head
            FieldMatrix.SetCellTypeByPosition(fieldMatrix, head, nextDirectionCellType);
            FieldMatrix.SetCellTypeByPosition(fieldMatrix, nextHeadPosition, eCellType.SnakeHead);

            FPGA.Runtime.DeepCopy(head, nextHeadPosition);

            if (nextHeadCellType == eCellType.NextPart)
            {
                expanded = true;
                return;
            }

            // move tail
            eDirectionType tailDirection = eDirectionType.None;

            // get value at current tail

            Lookups.CellTypeToDirectionType(tailCellType, ref tailDirection);

            // clear current tail
            FieldMatrix.SetCellTypeByPosition(fieldMatrix, tail, eCellType.None);

            // move tail
            Lookups.ApplyDirection(tail, tail, tailDirection);
        }
Ejemplo n.º 2
0
        public static void Seed(
            eCellType[] fieldMatrix,
            Position head,
            Position tail)
        {
            Reset(fieldMatrix);

            tail.row = 3;
            tail.col = 2;
            FPGA.Runtime.DeepCopy(head, tail);

            const byte seedSnakeLength = 3;

            for (byte i = 0; i < seedSnakeLength - 1; i++)
            {
                SetCellTypeByPosition(fieldMatrix, head, eCellType.SnakeRight);
                Lookups.ApplyDirection(head, head, eDirectionType.Right);
            }

            SetCellTypeByPosition(fieldMatrix, head, eCellType.SnakeHead);
        }