private void Cell_Click(object sender, EventArgs e) { FieldCell clickedCell = (FieldCell)sender; if (clickedCell.Gem == null) { return; } if (_prevCell != null) { clickedCell.Gem.WasMoved = true; _prevCell.Gem.WasMoved = true; Move = new CurrentMove(clickedCell, _prevCell); GemsController.SwapGems(Move.FirstCell, Move.SecondCell); foreach (var cell in GameField) { if (cell.Gem != null) { cell.Gem.IsClicked = false; } GemsController.UpdateGemTexture(cell.Gem); } _prevCell = null; } else { clickedCell.Gem.IsClicked = true; GemsController.UpdateGemTexture(clickedCell.Gem); _prevCell = clickedCell; } }
private static void CheckGemAndActivateBonus(FieldCell cell) { switch (cell.Gem.Type) { case GemType.Bomb: ActivatedBombs.Add((FieldCell)cell.Clone()); GemsController.DeleteGem(cell); break; case GemType.VerticalLine: case GemType.HorizontalLine: BonusController.LaunchDestroyers(cell); GemsController.DeleteGem(cell); break; } }
private static bool IsCurrentMoveImposible() { if (Move.FirstCell != null && Move.SecondCell != null) { if (Move.FirstCell.Gem == null || Move.SecondCell.Gem == null) { return(true); } if (Move.FirstCell.Gem.WasMoved && Move.SecondCell.Gem.WasMoved) { GemsController.SwapGems(Move.FirstCell, Move.SecondCell); Move.FirstCell = null; Move.SecondCell = null; } } return(false); }
public override void Update(GameTime gameTime) { if (IsTimerEnded(gameTime)) { _gameOverWindow?.Update(gameTime); return; } GameBoardConroller.MatchAndClear(GameField); UpdateActivatedBonuses(); UpdateDestroyers(gameTime); BonusController.BlowActivatedBombs(); BonusController.UseDestoyers(); if (Destroyers.Count == 0) { GemsController.MoveGems(GameField); GemsController.GenerateNewGems(GameField); } if (IsCurrentMoveImposible()) { return; } foreach (var cell in GameField) { cell.Update(gameTime); cell.Gem?.Update(gameTime); } }