Exemple #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //TODO: Make this more streamlined, and less manual

            TexturePool.AddTexture("menuscreen", Content.Load <Texture2D>("mainmenu"));
            TexturePool.AddTexture("button", Content.Load <Texture2D>("button"));

            TexturePool.AddTexture("dialogue", Content.Load <Texture2D>("DialogueBox"));
            TexturePool.AddTexture("select", Content.Load <Texture2D>("Selector"));

            TexturePool.AddTexture("itemSlot", Content.Load <Texture2D>("New Wall"));
            TexturePool.AddTexture("testItem", Content.Load <Texture2D>("Enemy"));

            //TexturePool.AddTexture("testItem", Content.Load<Texture2D>("Water"));

            TexturePool.AddFont("dialogue_font", Content.Load <SpriteFont>("Main Font"));

            TexturePool.AddTexture("robot_l", Content.Load <Texture2D>("robot_l"));
            TexturePool.AddTexture("robot_r", Content.Load <Texture2D>("robot_r"));
            TexturePool.AddTexture("robot_u", Content.Load <Texture2D>("robot_u"));
            TexturePool.AddTexture("robot_d", Content.Load <Texture2D>("robot_d"));

            //ReadTileSheets();
            TexturePool.AddTileSheet("World Tiles", new TileSheet(GraphicsDevice, Content.Load <Texture2D>("World Tiles"), 32, 32));
            TexturePool.AddTileSheet("Objects", new TileSheet(GraphicsDevice, Content.Load <Texture2D>("Objects"), 32, 32));

            gGameMode.Push("gamestate");
            gGameMode.Push("mainmenu");


            // TODO: use this.Content to load your game content here
        }
        public MainScreen()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);

            Dictionary <string, IState> states = new Dictionary <string, IState>()
            {
                { "MainMenu", new MainMenuState() },
                { "Logo", new LogoState() }
            };

            _GameStack = new StateStack(this, ClientSize.Width, ClientSize.Height, states);
            _GameStack.Push("MainMenu");
            _GameStack.Push("Logo");

            _GameTimer          = new Timer();
            _GameTimer.Interval = 10;
            _GameTimer.Tick    += new EventHandler(_GameStack.Update);
            _GameTimer.Start();

            ResizeEnd += new EventHandler(_GameStack.Buffer);
            Load      += new EventHandler(_GameStack.Buffer);
            KeyDown   += new KeyEventHandler(_GameStack.Input);
            Paint     += new PaintEventHandler(_GameStack.Render);
        }
        public void Test_Count()
        {
            string group = "TestGroup";

            StateStack <string> collection = new StateStack <string>(StateScope.Application, group);

            string zero = "Zero";
            string one  = "One";


            collection.Push(zero);


            Assert.AreEqual(1, collection.Count);

            string key = collection.GetStateKey();

            //StateAccess.State.SetApplication(key, collection);

            StateCollection <string> foundCollection0 = (StateCollection <string>)StateAccess.State.GetApplication(key);

            Assert.AreEqual(1, foundCollection0.Count);



            collection.Push(one);

            Assert.AreEqual(2, collection.Count);

            //StateAccess.State.SetApplication(key, collection);

            StateCollection <string> foundCollection2 = (StateCollection <string>)StateAccess.State.GetApplication(key);

            Assert.AreEqual(2, foundCollection2.Count);


            collection.Pop();



            Assert.AreEqual(1, collection.Count);

            //StateAccess.State.SetApplication(key, collection);

            StateCollection <string> foundCollection3 = (StateCollection <string>)StateAccess.State.GetApplication(key);

            Assert.AreEqual(1, foundCollection3.Count);
        }
 public override void Execute(IList <Token> tokens, ref int i)
 {
     if (tokens[i].TokenType == TokenType.Modifier)
     {
         modifs.Add(tokens[i].Value);
         i++;
     }
     else if (tokens[i].Value == "func")
     {
         i++;
         StateStack.Push(new MethodState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, modifs.ToArray()));
         modifs.Clear();
     }
     else if (tokens[i].TokenType == TokenType.Type)
     {
         StateStack.Push(new FieldState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, modifs.ToArray()));
         modifs.Clear();
     }
     else if (tokens[i].TokenType == TokenType.End)
     {
         i++;
         StateStack.Pop();
         StateStack.Pop();
         ((TypeBuilder)TypeBuilder).CreateType();
     }
     else
     {
         ExceptionManager.ThrowCompiler(ErrorCode.UnexpectedToken, "", tokens[i].Line);
     }
 }
 public override void Execute(IList <Token> tokens, ref int i)
 {
     if (tokens[i].TokenType == TokenType.Identifier)
     {
     }
     StateStack.Push(new ConstructionBodyState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, Method));
 }
Exemple #6
0
        public ParsingObject ToStack(State newState, bool important = true)
        {
            logger.Debug($"Push {newState.ToString()}");
            if (important)
            {
                CurrentToken += '{' + TokenParameters.Count.ToString() + '}';
            }
            StateStack.Push(this);
            var newObject = new ParsingObject
            {
                State             = newState,
                Index             = Index,
                CurrentHtmlObject = new HtmlObject
                {
                    Attributes = new List <DataAtrModel>(),
                    Children   = new List <HtmlObject>(),
                    Parent     = CurrentHtmlObject,
                    Tag        = string.Empty
                },
                CurrentToken    = string.Empty,
                ParenthStack    = new Stack <char>(),
                RawHtml         = RawHtml,
                StateStack      = StateStack,
                TokenParameters = new List <ParsingObject>()
            };

            newObject._startIndex = Index;
            newObject._important  = important;
            return(newObject);
        }
Exemple #7
0
 public void OnAfterDeserialize()
 {
     for (int i = StateList.Count; i >= 0; i--)
     {
         StateStack.Push(StateList[i]);
     }
 }
Exemple #8
0
        public void OnObjectStart(string name)
        {
            var state = new KVPartialState();

            state.Key = name;
            StateStack.Push(state);
        }
Exemple #9
0
        /// <summary>
        /// Shift.
        /// </summary>
        /// <param name="stateIndex">state index.</param>
        private void Shift(int stateIndex)
        {
            FsaState = states[stateIndex];

            ValueStack.Push(Scanner.yylval);
            StateStack.Push(FsaState);
            LocationStack.Push(Scanner.yylloc);

            if (recovering)
            {
                if (NextToken != errorToken)
                {
                    tokensSinceLastError++;
                }

                if (tokensSinceLastError > 5)
                {
                    recovering = false;
                }
            }

            if (NextToken != endOfFileToken)
            {
                NextToken = 0;
            }
        }
Exemple #10
0
        public void OnObjectStart(string name)
        {
            var state = new KvPartialState {
                Key = name
            };

            StateStack.Push(state);
        }
Exemple #11
0
 /// <summary>
 /// Push something onto the state Stack of the bot, this calls the Stop() of current State
 /// and the Start() of new State.
 /// </summary>
 /// <param name="botState">the state you want to change to</param>
 public void PushAction(BotState botState, [CallerMemberName] string functionName = "")
 {
     if (GetCurrentState() != botState)
     {
         AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"FSM Push [{botState}] called by: {functionName}", this);
         GetCurrentStateAction(GetCurrentState())?.StartExit.Invoke();
         StateStack.Push(botState);
         GetCurrentStateAction(GetCurrentState())?.StartAction.Invoke();
     }
 }
Exemple #12
0
    // Use this for initialization
    void Start()
    {
        stateStack = GetComponent <StateStack>();

        //Add all possible states here
        stateStack.Add("Game", new GameState());

        //Push the first thingy on
        stateStack.Push("Game");
    }
Exemple #13
0
 /// <summary>
 /// Push a versioning state with a VersioningMode and a specific ItemVersion (making it active)
 /// </summary>
 /// <param name="mode">The VersioningMode to push</param>
 /// <param name="specificVersion">The SpecificVersion to push</param>
 public void PushState(VersioningMode mode, ItemVersion specificVersion)
 {
     StateStack.Push(new VersioningState {
         Mode = this.Mode, SpecificVersion = this.SpecificVersion
     });
     this.Mode = mode;
     if (specificVersion != null)
     {
         this.SpecificVersion = specificVersion;
     }
 }
 public override void Execute(IList <Token> tokens, ref int i)
 {
     if (tokens[i].TokenType == TokenType.End)
     {
         StateStack.Pop();
         StateStack.Pop();
     }
     else
     {
         StateStack.Push(new InstructionState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, Method));
     }
 }
Exemple #15
0
        /// <summary>
        /// Push a versioning state with a VersioningMode and a specific ItemVersion (making it active)
        /// </summary>
        /// <param name="mode">The VersioningMode to push</param>
        /// <param name="specificVersion">The SpecificVersion to push</param>
        /// <returns>A versioning context which ensures this pushed changed is removed</returns>
        public VersioningContext PushState(VersioningMode mode, ItemVersion specificVersion)
        {
            StateStack.Push(new VersioningState {
                Mode = this.Mode, SpecificVersion = this.SpecificVersion
            });
            this.Mode = mode;
            if (specificVersion != null)
            {
                this.SpecificVersion = specificVersion;
            }

            return(new VersioningContext(this));
        }
Exemple #16
0
        private SceneNodeContainer FuseefyNode(Node assimpNode)
        {
            _currentAssimpNode.Tos = assimpNode;

            SceneNodeContainer fuNode;

            if (assimpNode.HasMeshes)
            {
                if (assimpNode.MeshIndices.Count == 1)
                {
                    // We can create a 1:1 Fusee node for this assimp node
                    fuNode = CreateFuseeNode(assimpNode.Name, GetXForm(assimpNode.Transform),
                                             GetMaterial(_assimpScene.Meshes[assimpNode.MeshIndices[0]].MaterialIndex),
                                             GetMesh(assimpNode.MeshIndices[0]));
                }
                else
                {
                    // Create a group node to contain all meshes as child nodes.
                    fuNode = new SceneNodeContainer {
                        Name = assimpNode.Name
                    };
                    fuNode.AddComponent(GetXForm(assimpNode.Transform));
                    foreach (var meshIndex in assimpNode.MeshIndices)
                    {
                        fuNode.Children.Add(CreateFuseeNode($"{assimpNode.Name}_mat{meshIndex}",
                                                            MakeIdentityXForm(),
                                                            GetMaterial(_assimpScene.Meshes[assimpNode.MeshIndices[meshIndex]].MaterialIndex),
                                                            GetMesh(assimpNode.MeshIndices[meshIndex])));
                    }
                }
            }
            else
            {
                // Create a simple group node
                fuNode = CreateFuseeNode(assimpNode.Name, GetXForm(assimpNode.Transform), null, null);
            }

            if (assimpNode.HasChildren)
            {
                fuNode.Children = new ChildList();
                _currentAssimpNode.Push();
                // Recursively convert all children.
                foreach (var child in assimpNode.Children)
                {
                    fuNode.Children.Add(FuseefyNode(child));
                }
                _currentAssimpNode.Pop();
            }

            return(fuNode);
        }
Exemple #17
0
        public ParsingObject PopAttributeVariable()
        {
            logger.Debug($"PopAttributeVariable {State}");
            var attributeValue = StateStack.Pop();
            var attribute      = attributeValue.StateStack.Pop();
            var element        = attribute.StateStack.Pop();

            element.currentAttr.ValueParameters.Add(CurrentToken);
            StateStack.Push(element);
            StateStack.Push(attribute);
            attributeValue.Index = Index;
            attributeValue.TokenParameters.Add(this);
            return(attributeValue);
        }
Exemple #18
0
 public void OnKeyValuePair(string name, KvValue value)
 {
     if (StateStack.Count > 0)
     {
         var state = StateStack.Peek();
         state.Items.Add(new KvObject(name, value));
     }
     else
     {
         var state = new KvPartialState {
             Key = name, Value = value
         };
         StateStack.Push(state);
     }
 }
Exemple #19
0
        public override void Execute(IList <Token> tokens, ref int i)
        {
            if (tokens[i].TokenType == TokenType.TypeDef || tokens[i].TokenType == TokenType.Modifier)
            {
                StateStack.Push(new TypeState(StateStack, DefinedTypes, AsmBuilder, _moduleBuilder));
            }

            else if (tokens[i].TokenType == TokenType.Namespace)
            {
                StateStack.Push(new NamespaceState(StateStack, DefinedTypes, AsmBuilder));
            }

            else if (tokens[i].TokenType == TokenType.Using)
            {
                StateStack.Push(new UsingState(StateStack, DefinedTypes, AsmBuilder));
            }
        }
        public override void Execute(IList <Token> tokens, ref int i)
        {
            if (tokens[i].TokenType == TokenType.Modifier)
            {
                if (ModifierCollection.TypeModifiers.ContainsKey(tokens[i].Value))
                {
                    if (AccesssModifier is null)
                    {
                        AccesssModifier = ModifierCollection.TypeModifiers[tokens[i].Value];
                        i++;
                        return;
                    }
                    else
                    {
                        ExceptionManager.ThrowCompiler(ErrorCode.AccessModifierAlreadySet, "", tokens[i].Line);
                    }
                }
                else if (!ModifierCollection.TypeAttributeses.ContainsKey(tokens[i].Value))
                {
                    ExceptionManager.ThrowCompiler(ErrorCode.UnexpectedModifier, "", tokens[i].Line);
                }

                Modifiers |= ModifierCollection.TypeAttributeses[tokens[i].Value];
                i++;
            }
            else if (tokens[i].TokenType == TokenType.TypeDef)
            {
                if (tokens[++i].TokenType != TokenType.Type)
                {
                    ExceptionManager.ThrowCompiler(ErrorCode.NameExpected, "", tokens[i].Line);
                }

                Name = tokens[i++].Value;
                if (AccesssModifier is null)
                {
                    AccesssModifier = 0;
                }

                var type = _moduleBuilder.DefineType(Name, (TypeAttributes)(AccesssModifier | Modifiers));
                DefinedTypes[Name] = type;

                StateStack.Push(new TypeBodyState(StateStack, DefinedTypes, AsmBuilder,
                                                  (TypeBuilder)DefinedTypes[Name]));
            }
        }
Exemple #21
0
        /// <summary>
        /// Main entry point of the Shift-Reduce Parser.
        /// </summary>
        /// <returns>True if parse succeeds, else false for
        /// unrecoverable errors</returns>
        public bool Parse()
        {
            _valueParameterList = new TValue[15]; // added Nate Wallace
            _errorOccured       = false;

            Initialize();       // allow derived classes to instantiate rules, states and nonTerminals

            NextToken = 0;
            FsaState  = states[0];

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);

            while (true)
            {
                int action = FsaState.defaultAction;

                if (FsaState.ParserTable != null)
                {
                    if (NextToken == 0)
                    {
                        // We save the last token span, so that the location span
                        // of production right hand sides that begin or end with a
                        // nullable production will be correct.
                        LastSpan  = Scanner.yylloc;
                        NextToken = Scanner.yylex();
                    }

                    if (FsaState.ParserTable.ContainsKey(NextToken))
                    {
                        action = FsaState.ParserTable[NextToken];
                    }
                }

                if (action > 0)         // shift
                {
                    Shift(action);
                }
                else if (action < 0)   // reduce
                {
                    try
                    {
                        Reduce(-action);
                        if (action == -1)       // accept
                        {
                            return(true);
                        }
                    }
                    catch (Exception x)
                    {
                        if (x is AbortException)
                        {
                            return(false);
                        }
                        else if (x is AcceptException)
                        {
                            return(true);
                        }
                        else if (x is ErrorException && !ErrorRecovery())
                        {
                            return(false);
                        }
                        else
                        {
                            throw;  // Rethrow x, preserving information.
                        }
                    }
                }
                else if (action == 0)   // error
                {
                    _tokenOnError    = NextToken;
                    _locationOnError = Scanner.yylloc;
                    if (!ErrorRecovery())
                    {
                        return(false);
                    }
                }
            }
        }
Exemple #22
0
        public override void Execute(IList <Token> tokens, ref int i)
        {
            var currentToken = tokens[i];

            if (literal != null)
            {
                //ParserHelper.PushToStack(PrevMember, Method);
                //var member = ParserHelper.GetMember(literal, DefinedTypes, Method.Locals, TypeBuilder);

                if (PrevMember is MemberInfo[] members)
                {
                    PrevMember = members[0];
                }

                switch (PrevMember)
                {
                case FieldInfo field:
                    Method.StoreField(field);
                    break;

                case Local local:
                    Method.StoreLocal(local);
                    break;

                default:
                    ExceptionManager.ThrowCompiler(ErrorCode.NotPossibleToSetValue, "", currentToken.Line);
                    break;
                }
            }

            if (IsInner)
            {
                if (tokens[i + 1].TokenType != TokenType.Operator)
                {
                    ParserHelper.PushToStack(tokens[i].Value, Method, DefinedTypes, TypeBuilder, AsmBuilder);
                    i++;
                }
                else
                {
                    var left  = tokens[i].Value;
                    var right = tokens[i + 2].Value;

                    //todo узнавать, переменная, константа или функция (вроде как сделал)
                    ParserHelper.PushToStack(left, Method, DefinedTypes, TypeBuilder, AsmBuilder);
                    ParserHelper.PushToStack(right, Method, DefinedTypes, TypeBuilder, AsmBuilder);

                    //todo добавить больше операций
                    switch (tokens[i + 1].Value)
                    {
                    case "+":
                        Method.Add();
                        break;

                    case "-":
                        Method.Subtract();
                        break;

                    case "*":
                        Method.Multiply();
                        break;

                    case "/":
                        Method.Divide();
                        break;
                    }
                    i += 3;
                }
            }
            else
            {
                if (currentToken.TokenType == TokenType.Type)
                {
                    if (tokens[i + 1].TokenType == TokenType.Identifier)
                    {
                        if (!ParserHelper.CheckUnusedLocal(tokens, _methodBodyState.FirstInstructionIndex,
                                                           tokens[i + 1].Value))
                        {
                            var type = DefinedTypes[currentToken.Value];
                            Method.DeclareLocal(type, tokens[i + 1].Value);
                            i++;
                        }
                    }
                    i++;
                    PrevMember = DefinedTypes[currentToken.Value];
                }
                else if (currentToken.Value == "=") //(currentToken.TokenType == TokenType.Operator)
                {
                    StateStack.Push(new InstructionState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, Method)
                    {
                        IsInner = true
                    });
                    literal = tokens[i - 1].Value;
                    i++;
                    return;
                    //ProcessOperator(tokens, ref i);
                }
                else if (currentToken.TokenType == TokenType.Identifier)
                {
                    if (tokens[i + 1].TokenType == TokenType.OpenBrace)
                    {
                        StateStack.Push(new CallMethodState(StateStack, DefinedTypes, AsmBuilder, TypeBuilder, Method));
                        return;
                    }
                    PrevMember = ParserHelper.GetMember(currentToken.Value, DefinedTypes, Method.Locals, TypeBuilder, AsmBuilder);
                    i++;
                }
                else if (currentToken.Value == "ret")
                {
                    var nextToken = tokens[i + 1];
                    if (nextToken.TokenType == TokenType.Identifier ||
                        nextToken.TokenType == TokenType.Constant)
                    {
                        ParserHelper.PushToStack(nextToken.Value, Method, DefinedTypes, TypeBuilder, AsmBuilder);
                        i++;
                    }
                    Method.Return();
                    i++;
                }
                else if (currentToken.Value == ".")
                {
                    MemberInfo[] members;
                    if (PrevMember is Type type)
                    {
                        type    = DefinedTypes[type.FullName];
                        members = type.GetMember(tokens[i + 1].Value);
                    }
                    else
                    {
                        members = PrevMember.GetType().GetMember(tokens[i + 1].Value);
                    }
                    if (members.Length == 0)
                    {
                        ExceptionManager.ThrowCompiler(ErrorCode.UnexpectedToken, string.Empty, tokens[i + 1].Line);
                    }

                    var currMember = members[0];

                    if (currMember is MethodInfo)
                    {
                        i++;
                        ParserHelper.PushToStack(PrevMember, Method);
                        Method.Box(ParserHelper.GetMemberType(PrevMember));

                        var callMethodState = new CallMethodState(StateStack, DefinedTypes, AsmBuilder,
                                                                  ((MethodInfo)currMember).DeclaringType, Method);
                        StateStack.Push(callMethodState);
                        callMethodState.Execute(tokens, ref i);
                        return;
                    }
                    else
                    {
                        i += 2;
                    }
                    PrevMember = currMember;
                }
            }

            StateStack.Pop();
        }
 /// <summary>
 /// Used for sudden transitions, such as a seemelss change from jumping to attacking. Basically, instances where we don't
 /// actually want Enter() to be called
 /// </summary>
 public void SubstituteState(State <CoreType> newState)
 {
     StateStack.Push(CurrentState);
     CurrentState = newState;
 }
 /// <summary>
 /// Suspend state is used for transitions where it may be important to keep the state we just transitioned from
 /// Examples of this include things like enemy patrol patterns and other sorts of advancedish AI
 /// </summary>
 public void SuspendState(State <CoreType> newState)
 {
     StateStack.Push(CurrentState);
     CurrentState = newState;
     CurrentState.Enter();
 }
Exemple #25
0
 public Game()
 {
     stateStack = new StateStack();
     stateStack.Push(new WelcomeState());
 }
Exemple #26
0
 //TODO deactivate the current state when the stack is not empty
 public void PushState(State state)
 {
     StateStack.Push(state);
     state.OnEntry();
     state.gameObject.SetActive(true);
 }
Exemple #27
0
 private void StateStackPush_FirstMapState()
 {
     _stateStack.Push(EState.FirstMapState);
 }
Exemple #28
0
 /// <summary>Pushes the current draw state onto the stack. Calling <see cref="Draw.Pop()"/> will restore the saved state state</summary>
 public static void Push() => StateStack.Push(Draw.style, Draw.matrix);
Exemple #29
0
        /// <summary>
        /// Reduce.
        /// </summary>
        /// <param name="ruleNumber">The rule to reduce by.</param>
        private void Reduce(int ruleNumber)
        {
            Rule rule = rules[ruleNumber];

            //
            //  Default actions for unit productions.
            //
            if (rule.RightHandSide.Length == 1)
            {
                CurrentSemanticValue = ValueStack.TopElement();    // Default action: $$ = $1;
                CurrentLocationSpan  = LocationStack.TopElement(); // Default action "@$ = @1;
            }
            else
            {
                if (rule.RightHandSide.Length == 0)
                {
                    // Create a new blank value.
                    // Explicit semantic action may mutate this value
                    CurrentSemanticValue = default(TValue);
                    // The location span for an empty production will start with the
                    // beginning of the next lexeme, and end with the finish of the
                    // previous lexeme.  This gives the correct behaviour when this
                    // nonsense value is used in later Merge operations.
                    CurrentLocationSpan = (Scanner.yylloc != null && LastSpan != null ?
                                           Scanner.yylloc.Merge(LastSpan) :
                                           default(TSpan));
                }
                else
                {
                    // Default action: $$ = $1;
                    CurrentSemanticValue = ValueStack.TopElement();
                    //  Default action "@$ = @1.Merge(@N)" for location info.
                    TSpan at1 = LocationStack[LocationStack.Depth - rule.RightHandSide.Length];
                    TSpan atN = LocationStack[LocationStack.Depth - 1];
                    CurrentLocationSpan =
                        ((at1 != null && atN != null) ? at1.Merge(atN) : default(TSpan));
                }
            }

            DoAction(ruleNumber);

            for (int i = rule.RightHandSide.Length - 1; i >= 0; i--)
            {
                _valueParameterList[i] = ValueStack.Pop(); // capture the values - added by Nate Wallace
                StateStack.Pop();
                LocationStack.Pop();
            }

            if (!_errorOccured)
            {
                ProcessReduce(rule.LeftHandSide, _valueParameterList, rule.RightHandSide.Length); // process the reduce action - added by Nate Wallace
            }
            else
            {
                _errorOccured = false;
            }

            FsaState = StateStack.TopElement();

            if (FsaState.Goto.ContainsKey(rule.LeftHandSide))
            {
                FsaState = states[FsaState.Goto[rule.LeftHandSide]];
            }

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);
        }
Exemple #30
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            mainMenuBackground  = Content.Load <Texture2D>("Space");
            firstMapBackground  = Content.Load <Texture2D>("samurai");
            playerSheet         = Content.Load <Texture2D>("playerSheet");
            btnNoHover          = Content.Load <Texture2D>("btnNoHover");
            btnHover            = Content.Load <Texture2D>("btnHover");
            inventoryBackground = Content.Load <Texture2D>("blueBackground");

            recTex = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            recTex.SetData(new[] { Color.White });

            fontNoHover = Content.Load <SpriteFont>("FontNoHover");
            fontHover   = Content.Load <SpriteFont>("FontHover");

            Menu mainMenu = new Menu(new List <MenuElement>()
            {
                new VBox(0, 0, 10, elements: new MenuButton[]
                {
                    new MenuButton(btnNoHover, btnHover, function: StateStackPush_FirstMapState),
                    new MenuButton(btnNoHover, btnHover, function: QuitGame)
                })
            });
            Menu mapMenu = new Menu(new List <MenuElement>()
            {
                new VBox(0, 0, 0, elements: new MenuButton[]
                {
                    new MenuButton(btnNoHover, btnHover, function: StateStackPush_InventoryState),
                    new MenuButton(btnNoHover, btnHover, function: StateStackPop),
                })
            });
            Menu inventoryMenu = new Menu(new List <MenuElement>()
            {
                new MenuButton(btnNoHover, btnHover, function: StateStackPop),
            });

            List <Character> characters = new List <Character>()
            {
                new Character("Player 1", 1000, 99, 10, 10, 10, 10, 10, true, new KeyboardInput()
                {
                    Left  = Keys.A,
                    Up    = Keys.W,
                    Right = Keys.D,
                    Down  = Keys.S
                }, animatedSprite: new AnimatedSprite("Player 1 Sprite", new Vector2(300, 300), PlayerIndex.One, GraphicsDevice, playerSheet)),

                new Character("Player 2", 200, 700, 10, 10, 10, 10, 10, true, new KeyboardInput()
                {
                    Left  = Keys.Left,
                    Up    = Keys.Up,
                    Right = Keys.Right,
                    Down  = Keys.Down
                }, animatedSprite: new AnimatedSprite("Player 2 Sprite", new Vector2(400, 300), PlayerIndex.Two, GraphicsDevice, playerSheet))
            };

            _stateStack = new StateStack(new Dictionary <EState, State>()
            {
                { EState.MainMenuState, new MainMenuState(mainMenu, _spriteBatch, mainMenuBackground, _screenWidth, _screenHeight) },
                { EState.FirstMapState, new FirstMapState(mapMenu, _spriteBatch, firstMapBackground, _screenWidth, _screenHeight, characters) },
                { EState.InventoryState, new InventoryState(fontNoHover, fontHover, _spriteBatch, inventoryBackground, _screenWidth, _screenHeight,
                                                            StateStackPop, textures: new Texture2D[] { btnNoHover, btnHover }, characters: characters) }
            });

            _stateStack.Push(EState.MainMenuState);
        }