示例#1
0
    public void ExchangePieceProcedure(PieceType pieceType)
    {
        if (computer != null)
        {
            if (HasPiece)
            {
                if (computer.CanReceivePiece(pieceType, _pieceContainer.PieceBroken))
                {
                    computer.AddPiece(TakePiece());
                    RepairComputer?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
            else
            {
                if (computer.CanGivePiece(pieceType, computer.IsPieceBroken(pieceType)))
                {
                    AddPiece(computer.TakePiece(pieceType));
                    PlacePiece?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
        }

        if (desk != null)
        {
            if (HasPiece)
            {
                if (desk.CanReceivePiece(pieceType, _pieceContainer.PieceBroken))
                {
                    desk.AddPiece(TakePiece());
                    PlacePiece?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
            else
            {
                if (desk.CanGivePiece(pieceType, desk.PieceBroken))
                {
                    AddPiece(desk.TakePiece());
                    PlacePiece?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
        }

        if (trashContainer != null && HasPiece)
        {
            if (trashContainer.CanReceivePiece(pieceType, _pieceContainer.PieceBroken))
            {
                trashContainer.AddPiece(TakePiece());
                TrashPiece?.Invoke();
            }
            else
            {
                Error?.Invoke();
            }
        }

        if (shelves != null)
        {
            if (HasPiece)
            {
                if (shelves.CanReceivePiece(pieceType, _pieceContainer.PieceBroken))
                {
                    shelves.AddPiece(TakePiece());
                    PlacePiece?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
            else
            {
                if (shelves.CanGivePiece(pieceType, shelves.IsPieceBroken(pieceType)))
                {
                    AddPiece(shelves.TakePiece(pieceType));
                    PlacePiece?.Invoke();
                }
                else
                {
                    Error?.Invoke();
                }
            }
        }
    }