Beispiel #1
0
        public void Should_Compile_And_Run_Source_In_Sandbox()
        {
            var isolator    = new AppDomainIsolator();
            var environment = new DefaultEnvironment();

            var source = new CSharpSource("using System; using System.IO; namespace Foo { public class Bar { public int Greet() { return 42; } } }");

            environment.Register(source);

            using (var jail = Jail.Create(isolator, environment))
            {
                dynamic bar    = jail.Resolve("Foo.Bar");
                int     result = bar.Greet();

                Assert.AreEqual(42, result);
            }
        }
Beispiel #2
0
            public void Loads_And_Calculates_With_Dynamic_Proxy_In_Separate_AppDomain()
            {
                var isolator = new AppDomainIsolator();

                var environment = new DefaultEnvironment();

                environment.Register("Ext/Calculator.dll");

                using (var jail = Jail.Create(isolator, environment))
                {
                    dynamic calculator = jail.Resolve("Calculator.SimpleCalculator");
                    int     result     = calculator.Sum(new[] { 1, 2, 3, 4, 5 });
                    calculator.Name = "simple calculator";

                    Assert.AreEqual(15, result);
                    Assert.AreEqual("simple calculator", calculator.Name);
                }

                Assert.IsFalse(AppDomain.CurrentDomain.GetAssemblies().Any(asm => asm.GetName().Name == "Calculator"));
            }
Beispiel #3
0
    /// <summary>Uses the Event System to determine when a button is pressed and carry out the appropriate action</summary>
    /// <param name="id">ID of the button being pressed</param>
    public void OnClick(int id)
    {
        //Ensure buttons are at latest state
        UpdateButtonStatus();

        switch (id)
        {
        case 0:                 //Play
            if (!GameManager.IsGameOngoing())
            {
                Chessboard.Style style = Chessboard.Style.ANTIPODEAN;

                //Get the approiate mode
                switch (display.dropdownStyle.value)
                {
                case 0:
                    display.buttonInvert.gameObject.SetActive(true);
                    display.buttonPush.gameObject.SetActive(true);
                    display.buttonPull.gameObject.SetActive(true);
                    style = Chessboard.Style.ANTIPODEAN;
                    break;

                case 1:
                    display.buttonInvert.gameObject.SetActive(false);
                    display.buttonPush.gameObject.SetActive(false);
                    display.buttonPull.gameObject.SetActive(false);
                    style = Chessboard.Style.SPHERE;
                    break;

                default:
                    break;
                }

                GameManager.SetGameOngoing(true);
                GameManager.board.Create(style);
                jail.Create();
            }

            display.menuUI.SetActive(false);
            display.ingameUI.SetActive(true);
            break;

        case 1:                 //Options
            break;

        case 2:                 //Quit
            if (Application.isEditor)
            {
                GameManager.SetGameOngoing(false);
                GameManager.board.Clear();
                jail.Clear();
            }
            else
            {
                Application.Quit();
            }
            break;

        case 3:                 //Invert
            if (display.buttonInvert.interactable)
            {
                GameManager.board.isInverted = !GameManager.board.isInverted;
                BoardAnimation.Inversion();
            }
            break;

        case 4:                 //Toggle Names
            GameManager.board.ToggleTileNames();
            break;

        case 5:                 //Show Score
            if (display.buttonShowScore.interactable)
            {
                bool jailVisibility = !jail.gameObject.activeSelf;
                GameManager.board.gameObject.SetActive(!jailVisibility);
                jail.SetVisible(jailVisibility);
            }
            break;

        case 6:                 //Push
            if (display.buttonPush.interactable && Rules.CanPush(selection.selectedPiece))
            {
                //Decolor
                SetMovementPathsColor(selection.selectedPiece, null);
                SetAttackPathsColor(selection.selectedPiece, null);

                //Swap and deselect after animation completed
                BoardAnimation.onComplete = () => {
                    GameManager.Swap(selection.selectedPiece.GetLocation());
                    selection.selectedPiece = null;

                    //Use turn
                    GameManager.NextTurn();
                };

                //Animate push
                BoardAnimation.PushOrPull(selection.selectedPiece.GetLocation());
            }
            break;

        case 7:                 //Pull
            if (display.buttonPull.interactable && Rules.CanPull(selection.selectedPiece))
            {
                //Decolor
                SetMovementPathsColor(selection.selectedPiece, null);
                SetAttackPathsColor(selection.selectedPiece, null);

                //Swap and deselect after animation completed
                BoardAnimation.onComplete = () => {
                    GameManager.Swap(selection.selectedPiece.GetLocation());
                    selection.selectedPiece = null;

                    //Use turn
                    GameManager.NextTurn();
                };

                //Animate pull or swap
                Tile tile = selection.selectedPiece.GetTile();
                if (tile.GetPiece() && tile.GetInversePiece() &&
                    (
                        (tile.GetPiece().type == Piece.Type.KING && tile.GetInversePiece().type == Piece.Type.QUEEN) ||
                        (tile.GetInversePiece().type == Piece.Type.KING && tile.GetPiece().type == Piece.Type.QUEEN))
                    )
                {
                    BoardAnimation.Swap(selection.selectedPiece.GetLocation());
                }
                else
                {
                    BoardAnimation.PushOrPull(selection.selectedPiece.GetLocation());
                }
            }
            break;

        case 8:
        case 9:
        case 10:
        case 11:                                          //Promotion
            Piece.Type type = Piece.Type.PAWN;

            //Get type based on button press
            if (id == 8)
            {
                type = Piece.Type.QUEEN;
            }
            else if (id == 9)
            {
                type = Piece.Type.KNIGHT;
            }
            else if (id == 10)
            {
                type = Piece.Type.ROOK;
            }
            else if (id == 11)
            {
                type = Piece.Type.BISHOP;
            }

            //Promopte the piece
            GameManager.Promote(selection.selectedPiece, type);

            //Change UI
            display.promotionUI.SetActive(false);
            display.ingameUI.SetActive(true);

            //Deselect and end the turn
            selection.selectedPiece = null;
            GameManager.NextTurn();
            break;

        case 12:                 //Rules
            display.rulesUI.SetActive(true);
            break;

        case 13:                 //Close Rules
            display.rulesUI.SetActive(false);
            break;

        case 14:                 //Undo
            GameManager.Undo();
            break;

        default:
            Debug.Log("Undefined interaction: " + id);
            break;
        }
    }