Beispiel #1
0
        public bool DigAt(CellCoordinate coordinate)
        {
            var coords = _infos[coordinate].Current.BoundingRectangle;

            var xpos = (int)(coords.X + coords.Width / 2);
            var ypos = (int)(coords.Y + coords.Height / 2);

            for (var i = 0; i < 10; i++)
            {
                Win32.SetForegroundWindow(_process.MainWindowHandle);
                Win32.SetCursorPos(xpos, ypos);
                Win32.mouse_event(Win32.MouseeventfLeftdown, xpos, ypos, 0, 0);
                Win32.mouse_event(Win32.MouseeventfLeftup, xpos, ypos, 0, 0);
                Thread.Sleep(10);

                var name = _infos[coordinate].Current.Name;
                if (name.Contains("masqué"))
                {
                    continue;
                }
                if (name.Contains("hors de danger"))
                {
                    return(false);
                }

                return(true);
            }


            Console.WriteLine("Failed to click, content was: ");
            Console.WriteLine(_infos[coordinate].Current.Name);
            return(true);
        }
Beispiel #2
0
        public bool DigAt(CellCoordinate coordinate)
        {
            var result       = _subject.DigAt(coordinate);
            var visitedCells = new HashSet <CellCoordinate>();

            UpdateCache(visitedCells, coordinate);
            return(result);
        }
Beispiel #3
0
        public int?NeighboursMineCountAt(CellCoordinate coordinate)
        {
            var name = _infos[coordinate].Current.Name;

            if (name.Contains("Aucune"))
            {
                return(0);
            }
            var index = name.IndexOf("Mine", StringComparison.InvariantCulture);

            return(index < 0 ? (int?)null : int.Parse(name.Substring(index - 2, 1)));
        }
Beispiel #4
0
        private void UpdateCache(ISet <CellCoordinate> visitedCells, CellCoordinate coordinate)
        {
            if (!visitedCells.Add(coordinate))
            {
                return;
            }

            var neighboursMineCount = _subject.NeighboursMineCountAt(coordinate);

            _cache[coordinate] = neighboursMineCount;
            if (neighboursMineCount == 0)
            {
                foreach (var neighbour in this.GetNeighbours(coordinate))
                {
                    UpdateCache(visitedCells, neighbour);
                }
            }
        }
Beispiel #5
0
 public bool IsSureAMine(CellCoordinate cellCoordinate)
 {
     return(_mines[cellCoordinate]);
 }
Beispiel #6
0
        public static IEnumerable <CellCoordinate> GetNeighbours(this IMineGame mineGame, CellCoordinate coordinate)
        {
            for (var dl = -1; dl <= 1; dl++)
            {
                for (var dc = -1; dc <= 1; dc++)
                {
                    if (dl == 0 && dc == 0)
                    {
                        continue;
                    }

                    var l = coordinate.Line + dl;
                    var c = coordinate.Column + dc;

                    if (l >= 0 && l < mineGame.LineCount && c >= 0 && c < mineGame.ColumnCount)
                    {
                        yield return(new CellCoordinate(l, c));
                    }
                }
            }
        }
Beispiel #7
0
 public T this[CellCoordinate coordinate]
 {
     get => _data[coordinate.Line, coordinate.Column];
Beispiel #8
0
 public int?NeighboursMineCountAt(CellCoordinate coordinate)
 {
     return(_cache[coordinate]);
 }