コード例 #1
0
        static List <Point> GetCellLineComboItems(Match3Map actualMap, List <Point[]> bangLines, int targetBangLineLength)
        {
            var actualBangLines = bangLines.Where(line => line.Length == targetBangLineLength).ToArray();
            var result          = new List <Point>();

            for (int i = 0; i < actualBangLines.Count(); i++)
            {
                if (actualBangLines[i] == null || actualBangLines[i].Length < 2 || actualBangLines[i][0].y != actualBangLines[i][1].y)
                {
                    continue;
                }

                var bangLineY     = GetBangLineCellsLine(actualMap, actualBangLines[i]);
                var possibleCells = new Point[actualMap.Width];

                for (int j = 0; j < possibleCells.Length; j++)
                {
                    possibleCells[j] = new Point(j, bangLineY);
                }

                possibleCells = possibleCells
                                .Where(cell => !actualBangLines[i].Contains(cell))
                                .ToArray();
                result.AddRange(possibleCells);
            }

            return(result);
        }
コード例 #2
0
        static List <Point> GetCellTypeComboItems(
            Match3Map actualMap
            , List <Point[]> bangLines
            , int targetBangLineLength
            )
        {
            var actualBangLines = bangLines
                                  .Where(line => line.Length == targetBangLineLength)
                                  .ToArray();

            var result = new List <Point>();

            for (int i = 0; i < actualBangLines.Count(); i++)
            {
                var bangLineCellsType = GetBangLineCellsType(actualMap, actualBangLines[i]);
                var possibleCells     = actualMap.GetCellIndexesByType(bangLineCellsType);

                possibleCells = possibleCells
                                .Where(cell => !actualBangLines[i].Contains(cell))
                                .ToList();

                result.AddRange(possibleCells);
            }

            return(result);
        }
コード例 #3
0
        static List <Point[]> GetAllVerticalBangLines(Match3Map actualMap)
        {
            var result = GetAllHorizontalBangLines(actualMap.TransposeMap());

            return(result
                   .Select(bangLine => Utils.GetPointsForTransposedMatrix(bangLine))
                   .ToList());
        }
コード例 #4
0
        public static List <Point[]> GetAllBangLines(Match3Map actualMap)
        {
            var bangLines = new List <Point[]>();

            bangLines.AddRange(GetAllHorizontalBangLines(actualMap));
            bangLines.AddRange(GetAllVerticalBangLines(actualMap));

            return(bangLines);
        }
コード例 #5
0
 static void MakeAllSteps(Match3Map actualMap, Point startPoint)
 {
     for (int x = startPoint.x; x < actualMap.Width - 1; x += Constants.checkingStep)
     {
         for (int y = startPoint.y; y < actualMap.Height; y += Constants.checkingStep)
         {
             actualMap.SwapCells(new Point(x, y), new Point(x + 1, y));
         }
     }
 }
コード例 #6
0
        static List <Point> GetCellColumnComboItems(Match3Map actualMap, List <Point[]> bangLines, int targetBangLineLength)
        {
            var transposedMap       = actualMap.TransposeMap();
            var transposedBangLines = bangLines
                                      .Select(line => Utils.GetPointsForTransposedMatrix(line))
                                      .ToList();

            var result = GetCellLineComboItems(transposedMap, transposedBangLines, targetBangLineLength);

            return(Utils.GetPointsForTransposedMatrix(result));
        }
コード例 #7
0
        public static List <Point> GetComboBangItems(Match3Map actualMap, List <Point[]> bangLines)
        {
            var result = new List <Point>();

            result.AddRange(GetCellColumnComboItems(actualMap, bangLines, Constants.lineComboItemsLenght));
            result.AddRange(GetCellLineComboItems(actualMap, bangLines, Constants.lineComboItemsLenght));
            result.AddRange(GetCellTypeComboItems(actualMap, bangLines, Constants.cellTypeComboItemsLenght));
            result = result.Distinct().ToList();

            return(result);
        }
コード例 #8
0
        static List <Point[]> GetVerticalHints(Match3Map actualMap)
        {
            var hints  = GetHorizontalHints(actualMap.TransposeMap());
            var result = new List <Point[]>();

            for (int i = 0; i < hints.Count; i++)
            {
                result.Add(Utils.GetPointsForTransposedMatrix(hints[i]));
            }

            return(result);
        }
コード例 #9
0
        public static void ResetMap(Match3Map actualMap, int cellTypesCount)
        {
            for (int i = 0; i < actualMap.Width; i++)
            {
                for (int j = 0; j < actualMap.Height; j++)
                {
                    actualMap.DestroyCell(new Point(i, j));
                }
            }

            FillAllEmptyCells(actualMap, cellTypesCount);
        }
コード例 #10
0
 public static void FillAllEmptyCells(Match3Map actualMap, int cellTypesCount)
 {
     for (int i = 0; i < actualMap.Width; i++)
     {
         for (int j = actualMap.Height - 1; j > -1; j--)
         {
             if (actualMap[i, j] == null)
             {
                 actualMap.CreateCell(new Point(i, j), Utils.GetRandomValue(cellTypesCount - 1));
             }
         }
     }
 }
コード例 #11
0
        static Point[] GetHint(Match3Map gameMap)
        {
            var hints = new List <Point[]>();

            hints.AddRange(GetHorizontalHints(gameMap));
            hints.AddRange(GetVerticalHints(gameMap));

            if (hints.Count > 0)
            {
                var resultIndex = Utils.GetRandomValue(hints.Count - 1);
                return(hints[resultIndex]);
            }

            return(null);
        }
コード例 #12
0
ファイル: Match3Map.cs プロジェクト: andreylutiy/Match3Game
        public Match3Map(Match3Map templateMap)
        {
            this.map = new Match3MapItem[templateMap.Width, templateMap.Height];

            for (int i = 0; i < this.Width; i++)
            {
                for (int j = 0; j < this.Height; j++)
                {
                    if (templateMap.map[i, j] != null)
                    {
                        this.map[i, j] = new Match3MapItem(templateMap.map[i, j]);
                    }
                }
            }
        }
コード例 #13
0
ファイル: Match3Map.cs プロジェクト: andreylutiy/Match3Game
        public Match3Map TransposeMap()
        {
            var result = new Match3Map(this.Height, this.Width);

            for (int i = 0; i < this.Width; i++)
            {
                for (int j = 0; j < this.Height; j++)
                {
                    if (this.map[i, j] != null)
                    {
                        result.map[j, i] = new Match3MapItem(this.map[i, j]);
                    }
                }
            }

            return(result);
        }
コード例 #14
0
        public static void DestroyStepCells(
            Match3Map actualMap
            , List <Point[]> bangLines
            , List <Point> comboCells
            )
        {
            for (int i = 0; i < bangLines.Count; i++)
            {
                for (int j = 0; j < bangLines[i].Length; j++)
                {
                    actualMap.DestroyCell(bangLines[i][j]);
                }
            }

            for (int i = 0; i < comboCells.Count; i++)
            {
                actualMap.DestroyCell(comboCells[i]);
            }
        }
コード例 #15
0
        static List <Point[]> GetAllHorizontalBangLines(Match3Map actualMap)
        {
            var result = new List <Point[]>();

            for (int i = 0; i < actualMap.Width - 2; i++)
            {
                for (int j = 0; j < actualMap.Height; j++)
                {
                    if (actualMap[i, j] == null || actualMap[i, j].IsBlocked)
                    {
                        continue;
                    }

                    var startPointType = actualMap[i, j].ItemType;
                    int lineLength     = 0;

                    while (
                        actualMap.Width > i + lineLength &&
                        actualMap[i + lineLength, j].ItemType == startPointType
                        )
                    {
                        lineLength++;
                    }

                    if (lineLength < 3)
                    {
                        continue;
                    }

                    var bangLine = new Point[lineLength];

                    for (int k = 0; k < lineLength; k++)
                    {
                        bangLine[k] = new Point(i + k, j);
                    }

                    result.Add(bangLine);
                }
            }

            return(result);
        }
コード例 #16
0
        static bool IsAnyHorizontalStepsEffective(Match3Map actualMap)
        {
            for (int i = 0; i < Constants.checkingStep; i++)
            {
                for (int j = 0; j < Constants.checkingStep; j++)
                {
                    var mapCopy = new Match3Map(actualMap);
                    MakeAllSteps(mapCopy, new Point(i, j));

                    var bangLines = Match3BangController.GetAllBangLines(mapCopy);

                    if (bangLines.Count > 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #17
0
        static int GetBangLineCellsLine(Match3Map actualMap, Point[] bangLine)
        {
            var bangLineLines = new int[bangLine.Length];

            for (int i = 0; i < bangLine.Length; i++)
            {
                bangLineLines[i] = bangLine[i].y;
            }

            var possibleLines = bangLineLines.Distinct().ToArray();

            if (possibleLines.Length == 1)
            {
                return(possibleLines[0]);
            }
            else
            {
                throw new ArgumentException("Match3Lib.Match3BangController.GetBangLineCellsLine exception: bang line is invalid!");
            }
        }
コード例 #18
0
        public static void MoveDownAllPossibleCells(Match3Map actualMap)
        {
            int swaps = 0;

            do
            {
                swaps = 0;
                for (int j = 0; j < actualMap.Height - 1; j++)
                {
                    for (int i = 0; i < actualMap.Width; i++)
                    {
                        if (actualMap[i, j] == null && actualMap[i, j + 1] != null)
                        {
                            actualMap.SwapCells(new Point(i, j), new Point(i, j + 1));
                            swaps++;
                        }
                    }
                }
            }while (swaps != 0);
        }
コード例 #19
0
        static List <Point[]> GetHintsByStep(Match3Map actualMap, Point startPoint)
        {
            var result = new List <Point[]>();

            for (int x = startPoint.x; x < actualMap.Width - 1; x += Constants.checkingStep)
            {
                for (int y = startPoint.y; y < actualMap.Height; y += Constants.checkingStep)
                {
                    var mapCopy = new Match3Map(actualMap);
                    mapCopy.SwapCells(new Point(x, y), new Point(x + 1, y));

                    if (Match3BangController.GetAllBangLines(mapCopy).Count > 0)
                    {
                        result.Add(new Point[] { new Point(x, y), new Point(x + 1, y) });
                    }
                }
            }

            return(result);
        }
コード例 #20
0
        static List <Point[]> GetHorizontalHints(Match3Map actualMap)
        {
            var result = new List <Point[]>();

            for (int i = 0; i < Constants.checkingStep; i++)
            {
                for (int j = 0; j < Constants.checkingStep; j++)
                {
                    var mapCopy = new Match3Map(actualMap);
                    MakeAllSteps(mapCopy, new Point(i, j));

                    var bangLines = Match3BangController.GetAllBangLines(mapCopy);

                    if (bangLines.Count > 0)
                    {
                        result.AddRange(GetHintsByStep(actualMap, new Point(i, j)));
                    }
                }
            }

            return(result);
        }
コード例 #21
0
        public void NewGame(Point size, IGameEventsListener actualGameEventsListener, int actualCellTypesCount = 3)
        {
            if (size == null)
            {
                throw new NullReferenceException("Match3Lib.Match3Controller.NewGame exception: 'size' can't be null!");
            }

            if (!Utils.IsCellInRange(size - Constants.minSize, Constants.maxSize - Constants.minSize))
            {
                throw new ArgumentOutOfRangeException("Match3Lib.Match3Controller.NewGame exception: map size out of range!");
            }

            if (actualCellTypesCount < 2)
            {
                throw new ArgumentOutOfRangeException("Match3Lib.Match3Controller.NewGame exception: cellTypesCount out of range!");
            }

            map                = new Match3Map(size.x, size.y, this);
            cellTypesCount     = actualCellTypesCount;
            currentStepIndex   = 0;
            gameEventsListener = actualGameEventsListener;
            ActualScore        = 0;
            UpdateMapState();
        }
コード例 #22
0
 public static bool IsMapValid(Match3Map gameMap)
 {
     return(IsAnyVerticalStepsEffective(gameMap) || IsAnyHorizontalStepsEffective(gameMap));
 }
コード例 #23
0
 static bool IsAnyVerticalStepsEffective(Match3Map actualMap)
 {
     return(IsAnyHorizontalStepsEffective(actualMap.TransposeMap()));
 }