예제 #1
0
 private void OnRemoveDone(object sender, EventArgs agrs)
 {
     lock (_tilesLock)
     {
         for (var j = 0; j < 8; ++j)
         {
             var count = 0;
             for (var i = 7; i >= 0; --i)
             {
                 if (_tiles[i, j] == null)
                 {
                     for (var k = i - 1; k >= 0; --k)
                     {
                         if (_tiles[k, j] != null)
                         {
                             SwapTiles(Tuple.Create(i, j), Tuple.Create(k, j));
                             _tiles[i, j]?.MoveTo(j, i);
                             break;
                         }
                     }
                 }
             }
             for (var i = 7; i >= 0; --i)
             {
                 if (_tiles[i, j] == null)
                 {
                     _tiles[i, j] = _window.CreateTileMove(Tuple.Create(count - 1, j), Tuple.Create(i, j),
                                                           (TileType)TileTypeValues.GetValue(_tileTypeRandom.Next(TileTypeValues.Length)));
                     count -= 1;
                 }
             }
         }
     }
 }
예제 #2
0
 public Game(IGameWindow window)
 {
     _window            = window;
     window.MoveDone   += OnMoveDone;
     window.RemoveDone += OnRemoveDone;
     for (int i = 0; i < _tiles.GetLength(0); ++i)
     {
         for (int j = 0; j < _tiles.GetLength(1); ++j)
         {
             _tiles[i, j] = _window.CreateTileMove(Tuple.Create(i - 8, j), Tuple.Create(i, j),
                                                   (TileType)TileTypeValues.GetValue(_tileTypeRandom.Next(TileTypeValues.Length)));
         }
     }
 }