public void UnSelectOthersPieces() { var pieceList = Pieces.OfType <Piece>(); foreach (var piece in pieceList) { var selectedPiece = pieceList.FirstOrDefault(p => p.State == PieceState.Selected); if (selectedPiece != null && piece.Id != selectedPiece.Id) { piece.Unselect(); } } }
public void LoadContent(Texture2D texture = null) { foreach (var piece in Pieces) { piece.LoadContent(); piece.SetDrawMethodType(5); } var emptyPieceNumber = Global.RandomNext(0, Pieces.OfType <Piece>().Count()); var emptyPiece = Pieces.OfType <Piece>().FirstOrDefault(p => p.Number == emptyPieceNumber); emptyPiece.MakeEmpty(); }
public void Update(GameTime gameTime = null) { var pieceList = Pieces.OfType <Piece>().ToList(); foreach (var piece in pieceList) { if (InputManager.Selected(piece.DestinationRectangle)) { if (!pieceList.Any(p => p.State == PieceState.Selected)) { piece.Select(); } else { var previouslySelectedPiece = pieceList.FirstOrDefault(p => p.State == PieceState.Selected); previouslySelectedPiece.Unselect(); if (previouslySelectedPiece.Id != piece.Id) { if (piece.IsEmpty && previouslySelectedPiece.IsNeighborWith(piece)) { Piece.Replace(piece, previouslySelectedPiece, Pieces); } else { piece.Select(); } } } } piece.Update(); } UnSelectOthersPieces(); }
public override bool IsMoveAllowed() { return(!Pieces.OfType <BarricadePiece>().Any()); }