Пример #1
0
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.B))
            {
                IRifle rifle = new BasicRifle();

                Debug.Log($"basic accuracy: { rifle.GetAccuracy() }");
            }

            if (Input.GetKeyDown(KeyCode.S))
            {
                IRifle rifle = new BasicRifle();
                rifle = new WithScope(rifle);

                Debug.Log($"WithScope accuracy { rifle.GetAccuracy() }");
            }

            if (Input.GetKeyDown(KeyCode.T))
            {
                IRifle rifle = new BasicRifle();
                rifle = new WithScope(new WithStabilizer(rifle));

                Debug.Log($"Stabilizer+Scope accuracy { rifle.GetAccuracy() }");
            }
        }
Пример #2
0
        /// <summary>
        /// Generates CIL for the statement.
        /// </summary>
        /// <param name="generator"> The generator to output the CIL to. </param>
        /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param>
        public override void GenerateCode(ILGenerator generator, OptimizationInfo optimizationInfo)
        {
            // Generate code for the start of the statement.
            var statementLocals = new StatementLocals();

            GenerateStartOfStatement(generator, optimizationInfo, statementLocals);

            // Create the scope instance.
            WithScope.GenerateScopeCreation(generator, optimizationInfo);
            WithScope.GenerateHoistedDeclarations(generator, optimizationInfo);

            // Bind the scope to the with() object.
            WithScope.GenerateReference(generator, optimizationInfo);
            WithObject.GenerateCode(generator, optimizationInfo);
            ILLocalVariable withObject = generator.CreateTemporaryVariable(typeof(object));

            generator.Duplicate();
            generator.StoreVariable(withObject);
            generator.Call(ReflectionHelpers.RuntimeScope_With);

            // Generate code for the body statements.
            this.Body.GenerateCode(generator, optimizationInfo);

            // Generate code for the end of the statement.
            GenerateEndOfStatement(generator, optimizationInfo, statementLocals);
        }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B))
        {
            IRifle rifle = new BasicRifle();
            Instantiate(rifle.LoadPart());
            Debug.Log("Basic accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(rifle);
            Instantiate(rifle.LoadPart());
            Debug.Log("WithScope accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithStabilizer(new WithScope(rifle));
            Instantiate(rifle.LoadPart());
            Debug.Log("Stabilizer+Scope accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithSilencer(new WithStabilizer(new WithScope(rifle)));
            Instantiate(rifle.LoadPart());
            Debug.Log("Stabilizer+Scope+Silencer accuracy: "
                      + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            IRifle rifle = new BasicRifle();
            rifle = new InPink(new WithStabilizer
                                   (new WithSilencer(new WithScope(rifle))));
            Instantiate(rifle.LoadPart());
            Debug.Log("Stabilizer+Scope+Silencer in Pink! accuracy: "
                      + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
Пример #4
0
    void Update()
    {
        if (Input.GetKeyDown("b"))
        {
            IRifle rifle = new BasicRifle();
            text.text = "Basic accuracy: " + rifle.GetAccuracy();
            Debug.Log("Basic accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("s"))
        {
            IRifle rifle = new BasicRifle();
            rifle     = new WithScope(rifle);
            text.text = "WithScope accuracy: " + rifle.GetAccuracy();
            Debug.Log("WithScope Accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("t"))
        {
            IRifle rifle = new BasicRifle();
            rifle     = new WithScope(new WithStabilizer(rifle));
            text.text = "Stabilizer + Scope Accuracy: " + rifle.GetAccuracy();
            Debug.Log("Stabilizer + Scope Accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("f"))
        {
            IRifle rifle = new BasicRifle();
            rifle     = new WithMagazine(rifle);
            text.text = "Magazine Accuracy: " + rifle.GetAccuracy();
        }

        if (Input.GetKeyDown("t"))
        {
            IRifle rifle = new BasicRifle();
            rifle     = new WithScope(new WithStabilizer(rifle));
            text.text = "Stabilizer + Scope Accuracy: " + rifle.GetAccuracy();
            Debug.Log("Stabilizer + Scope Accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("a"))
        {
            IRifle rifle = new BasicRifle();
            rifle     = new WithScope(new WithStabilizer(new WithMagazine(rifle)));
            text.text = "Stabilizer + Scope + Mag Accuracy: " + rifle.GetAccuracy();
            Debug.Log("Stabilizer + Scope + Mag Accuracy: " + rifle.GetAccuracy());
        }
    }
    void Update()
    {
        if (Input.GetKeyDown(Keycode.A))
        {
            IRifle rifle = new BasicRifle();
            Debug.Log("Basic Accurancy: " + rifle.GetAccurancy());
        }

        if (Input.GetKeyDown(Keycode.S))
        {
            IRifle rifle = new WithScope(new BasicRifle());
            Debug.Log("Scope Accurancy: " + rifle.GetAccurancy());
        }

        if (Input.GetKeyDown(Keycode.Z))
        {
            IRifle rifle = new WithScope(new WithStabilizer(new BasicRifle()));
            Debug.Log("Scope + Stabilizer Accurancy: " + rifle.GetAccurancy());
        }
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.B))
        {
            IRifle rifle = new BasicRifle();
            Debug.Log("Basic Accuracy: " + rifle.GetAccuracy());
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(rifle);
            Debug.Log("With Scope Accuracy: " + rifle.GetAccuracy());
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithStabilzer(rifle));
            Debug.Log("With Stabilzer Accuracy: " + rifle.GetAccuracy());
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithStabilzer(new WithDotSight(new WithLongBarrel(rifle))));
            Debug.Log("With Everything Accuracy: " + rifle.GetAccuracy());
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithDotSight(rifle);
            Debug.Log("With Dot Sight Accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown(KeyCode.L))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithLongBarrel(rifle);
            Debug.Log("With Long Barrel Accuracy: " + rifle.GetAccuracy());
        }
    }
Пример #7
0
        void Update()
        {
            if (Input.GetKeyDown("b"))
            {
                IRifle rifle = new BasicRifle();
                Debug.Log("Rifle has a basic configuration, current accurancy: " + rifle.GetAccuracy());
            }

            if (Input.GetKeyDown("s"))
            {
                IRifle rifle = new BasicRifle();
                rifle = new WithScope(rifle);
                Debug.Log("Rifle is equipped with a scope, current accurancy: " + rifle.GetAccuracy());
            }

            if (Input.GetKeyDown("t"))
            {
                IRifle rifle = new BasicRifle();
                rifle = new WithScope(new WithStabilizer(rifle));
                Debug.Log("Rifle is equipped with a scope and stabilizer, current accurancy: " + rifle.GetAccuracy());
            }
        }
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        // Basic Rifle
        if (Input.GetKeyDown("a"))
        {
            IRifle rifle = new BasicRifle();
            Debug.Log("Basic accuracy: " + rifle.GetAccuracy());
            Result.text = "You got: " + rifle.ToString();
        }

        // With Scope and Stabilizer
        if (Input.GetKeyDown("w"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithStabilizer(rifle));
            Debug.Log("Fancy accuracy: " + rifle.GetAccuracy());
            Result.text = "You got: Fancy Rifle";
        }

        // With Scope
        if (Input.GetKeyDown("s"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(rifle);
            Debug.Log("+ Scope accuracy: " + rifle.GetAccuracy());
            Result.text = "You got: " + rifle.ToString();
        }

        // With Stabilizer
        if (Input.GetKeyDown("d"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithStabilizer(rifle);
            Debug.Log("+ Stabilizer accuracy: " + rifle.GetAccuracy());
            Result.text = "You got: " + rifle.ToString();
        }
    }
Пример #9
0
    void Update()
    {
        if (Input.GetKeyDown("b"))
        {
            IRifle rifle = new BasicRifle();
            Debug.Log("Basic accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("s"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(rifle);
            Debug.Log("Basic accuracy: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("t"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithStabilizer(rifle));
            Debug.Log("Stabilizer + Scope: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("p"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithSuppressor(rifle));
            Debug.Log("Scope + Suppressor: " + rifle.GetAccuracy());
        }

        if (Input.GetKeyDown("l"))
        {
            IRifle rifle = new BasicRifle();
            rifle = new WithScope(new WithExtendedBarrel(rifle));
            Debug.Log("Scope + Extended Barrel: " + rifle.GetAccuracy());
        }
    }
Пример #10
0
        //---------------------------------------------------------------------------------------
        // ParseWithStatement
        //
        //  WithStatement :
        //    'with' '(' Expression ')' Statement
        //---------------------------------------------------------------------------------------
        private WithNode ParseWithStatement()
        {
            Context withCtx = m_currentToken.Clone();
            AstNode obj = null;
            Block block = null;
            m_blockType.Add(BlockType.Block);
            try
            {
                GetNextToken();
                if (JSToken.LeftParenthesis != m_currentToken.Token)
                    ReportError(JSError.NoLeftParenthesis);
                GetNextToken();
                m_noSkipTokenSet.Add(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet);
                try
                {
                    obj = ParseExpression();
                    if (JSToken.RightParenthesis != m_currentToken.Token)
                    {
                        withCtx.UpdateWith(obj.Context);
                        ReportError(JSError.NoRightParenthesis);
                    }
                    else
                        withCtx.UpdateWith(m_currentToken);
                    GetNextToken();
                }
                catch (RecoveryTokenException exc)
                {
                    if (IndexOfToken(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet, exc) == -1)
                    {
                        // give up
                        exc._partiallyComputedNode = null;
                        throw;
                    }
                    else
                    {
                        if (exc._partiallyComputedNode == null)
                            obj = new ConstantWrapper(true, PrimitiveType.Boolean, CurrentPositionContext(), this);
                        else
                            obj = exc._partiallyComputedNode;
                        withCtx.UpdateWith(obj.Context);

                        if (exc._token == JSToken.RightParenthesis)
                            GetNextToken();
                    }
                }
                finally
                {
                    m_noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockConditionNoSkipTokenSet);
                }

                // if the statements aren't withing curly-braces, throw a possible error
                if (JSToken.LeftCurly != m_currentToken.Token)
                {
                    ReportError(JSError.StatementBlockExpected, withCtx, true);
                }

                WithScope withScope = new WithScope(ScopeStack.Peek(), withCtx, this);
                ScopeStack.Push(withScope);
                try
                {
                    // parse a Statement, not a SourceElement
                    AstNode statement = ParseStatement(false);

                    // but make sure we save it as a block
                    block = statement as Block;
                    if (block == null)
                    {
                        block = new Block(statement.Context, this);
                        block.Append(statement);
                    }
                }
                catch (RecoveryTokenException exc)
                {
                    if (exc._partiallyComputedNode == null)
                    {
                        block = new Block(CurrentPositionContext(), this);
                    }
                    else
                    {
                        block = exc._partiallyComputedNode as Block;
                        if (block == null)
                        {
                            block = new Block(exc._partiallyComputedNode.Context, this);
                            block.Append(exc._partiallyComputedNode);
                        }
                    }
                    block.BlockScope = withScope;
                    exc._partiallyComputedNode = new WithNode(withCtx, this, obj, block);
                    throw;
                }
                finally
                {
                    // pop off the with-scope
                    ScopeStack.Pop();

                    // save the with-scope on the block
                    block.BlockScope = withScope;
                }
            }
            finally
            {
                m_blockType.RemoveAt(m_blockType.Count - 1);
            }

            return new WithNode(withCtx, this, obj, block);
        }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        //Event e = Event.current;
        foreach (KeyCode k in keys)
        {
            if (Input.GetKeyDown(k))
            {
                switch (k)
                {
                case KeyCode.B:

                    IRifle rifle = new BasicRifle(nextPos);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = rifle;
                        Debug.Log("Basic Accuracy: " + rifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = rifle;
                        Debug.Log("Basic Accuracy: " + rifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                case KeyCode.S:

                    IRifle sRifle = new BasicRifle(nextPos);
                    sRifle = new WithScope(sRifle);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = sRifle;
                        Debug.Log("Scoped Accuracy: " + sRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = sRifle;
                        Debug.Log("Scoped Accuracy: " + sRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                case KeyCode.T:

                    IRifle tRifle = new BasicRifle(nextPos);
                    tRifle = new WithStabilizer(tRifle);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = tRifle;
                        Debug.Log("With Stabilizer: " + tRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = tRifle;
                        Debug.Log("With Stabilizer: " + tRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                case KeyCode.C:

                    IRifle cRifle = new BasicRifle(nextPos);
                    cRifle = new WithBrake(cRifle);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = cRifle;
                        Debug.Log("With Brake: " + cRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = cRifle;
                        Debug.Log("With Brake: " + cRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                case KeyCode.L:

                    IRifle lRifle = new BasicRifle(nextPos);
                    lRifle = new WithLaser(lRifle);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = lRifle;
                        Debug.Log("With Laser: " + lRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = lRifle;
                        Debug.Log("With Laser: " + lRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                case KeyCode.A:

                    IRifle aRifle = new BasicRifle(nextPos);
                    aRifle = new WithScope(new WithStabilizer(new WithLaser(new WithBrake(aRifle))));

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = aRifle;
                        Debug.Log("With All: " + aRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = aRifle;
                        Debug.Log("With All: " + aRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;

                default:

                    IRifle bRifle = new BasicRifle(nextPos);

                    if (currentRifle != null)
                    {
                        GameObject.Destroy(currentRifle.GetGameObject());
                        currentRifle = bRifle;
                        Debug.Log("Basic Accuracy: " + bRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }
                    else
                    {
                        currentRifle = bRifle;
                        Debug.Log("Basic Accuracy: " + bRifle.GetAccuracy());
                        //nextPos += new Vector3(1, 0, 0);
                    }

                    break;
                }
            }
        }
    }