コード例 #1
0
        /// <summary>
        /// Moves the tile.
        /// </summary>
        /// <param name="xDelta">X delta.</param>
        /// <param name="yDelta">Y delta.</param>
        public void MoveTile(int xDelta, int yDelta)
        {
            Tile tile = repository.Get(GameInfo.TilesCount);

            if (tile.X + xDelta >= GameInfo.TableSize || tile.X + xDelta < 0)
            {
                return; //throw new ArgumentException("Invalid X delta");
            }
            if (tile.Y + yDelta >= GameInfo.TableSize || tile.Y + yDelta < 0)
            {
                return; //throw new ArgumentException("Invalid Y delta");
            }
            SwapTiles(tile.X, tile.Y, tile.X + xDelta, tile.Y + yDelta);
        }
コード例 #2
0
        /// <summary>
        /// Clears the tile.
        /// </summary>
        /// <param name="x">The X coordinate.</param>
        /// <param name="y">The Y coordinate.</param>
        public void ClearTile(int x, int y)
        {
            int[] dx = { -1, -1, -1, 0, 1, 1, 1, 0 };
            int[] dy = { -1, 0, 1, 1, 1, 0, -1, -1 };

            Tile tile = tileRepository.Get(x, y);

            if (tile.Cleared || tile.Flagged)
            {
                return;
            }

            if (tile.Mined)
            {
                Alive     = false;
                IsRunning = false;
                return;
            }

            tile.Cleared = true;

            if (tile.DangerLevel == 0)
            {
                for (int dir = 0; dir < 8; dir++)
                {
                    int x2 = dx[dir] + x;
                    int y2 = dy[dir] + y;

                    Tile tile2 = tileRepository.Get(x2, y2);

                    if (x2 >= 0 && x2 < TableSize && y2 >= 0 && y2 < TableSize)
                    {
                        if (!tile2.Cleared && !tile2.Flagged)
                        {
                            ClearTile(x2, y2);
                        }
                    }
                }
            }
        }