Exemple #1
0
 public SettingsWindow(GameParams gameParams)
 {
     GameParams = new GameParams()
     {
         RowsCount    = gameParams.RowsCount,
         ColumnsCount = gameParams.ColumnsCount,
         BombCount    = gameParams.BombCount,
         TimeGame     = gameParams.TimeGame,
         Time         = gameParams.Time
     };
     DataContext = GameParams;
     InitializeComponent();
 }
Exemple #2
0
        internal void NewGame(GameParams gameParams)
        {
            Params = new GameParams()
            {
                RowsCount    = gameParams.RowsCount,
                ColumnsCount = gameParams.ColumnsCount,
                BombCount    = gameParams.BombCount,
                TimeGame     = gameParams.TimeGame,
                Time         = gameParams.Time
            };

            if (Params.TimeGame)
            {
                TimeDisplay = gameParams.Time.ToString(@"hh\:mm\:ss");
            }
            else
            {
                TimeDisplay = TimeSpan.FromSeconds(0).ToString(@"hh\:mm\:ss");
            }

            OnPropertyChanged(nameof(TimeDisplay));

            FirstClick = true;
            TilesShown = 0;
            FlagCount  = 0;
            OnPropertyChanged(nameof(BombCountDisplay));

            Tiles = new Tile[Params.RowsCount * Params.ColumnsCount];

            //Create and shuffle Bombs
            bool[] bombs = Enumerable.Repeat(true, Params.BombCount)
                           .Concat(Enumerable.Repeat(false, Tiles.Length - Params.BombCount))
                           .OrderBy(r => rnd.Next())
                           .ToArray();

            //CreateGrid
            for (int i = 0; i < bombs.Length; i++)
            {
                CalculateRowColumn(i, out int row, out int column);
                Tiles[i] = new Tile(row, column)
                {
                    Bomb = bombs[i]
                };
            }

            //Calculate Number of AdjacentBombs
            foreach (Tile t in Tiles)
            {
                if (t.Bomb)
                {
                    ProccessNeighboors(t, tile => { tile.AdjacentBombsCount++; }, true);
                }
            }

            //Refresh
            OnPropertyChanged(nameof(Tiles));
            OnPropertyChanged(nameof(Params));

            //StartTimer
            if (Timer == null)
            {
                Timer          = new DispatcherTimer();
                Timer.Interval = TimeSpan.FromMilliseconds(1);
                Timer.Tick    += Count;
            }
            start = DateTime.Now;
            Timer.Start();
        }