/// <summary> /// Moves the tetromino to down if it's possible and return the changed blocks after movement /// If it is not possible to move down, checks for game over and if game has not been over, fixes the tetromino in deck and checks for rows to vanish /// </summary> /// <returns></returns> public MoveDownResult MoveDown() { if (!CanMoveDown()) { if (GameOver()) { return(new MoveDownResult { GameOver = true }); } deck.FixBlocks(VisibleBlocks); var currentTetrominosRows = VisibleBlocks.Select(s => s.Y).Distinct().ToArray(); var vanishRowResult = deck.VanishRows(currentTetrominosRows); return(new MoveDownResult { VanishRowResult = vanishRowResult }); } else { var inversedBlocks = InverseVisibleBlocks(); foreach (var block in Blocks) { block.MoveDown(); } var changedBlocks = AddVisibleBlocksToChangedBlocks(inversedBlocks); return(new MoveDownResult { ChangedBlocks = changedBlocks }); } }
public ViewModel() { VisibleBlocks.Add(new ObservableCollection <Block>()); VisibleBlocks.Add(new ObservableCollection <Block>()); VisibleBlocks.Add(new ObservableCollection <Block>()); VisibleBlocks.Add(new ObservableCollection <Block>()); for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { VisibleBlocks[x].Add(new Block()); } Blocks.AddRange(VisibleBlocks[x]); } RandomBlock(); RandomBlock(); }