Example #1
0
        public void Update(GameTime gameTime)
        {
            if (stateList.Count == 0)
                return;

            // Loop?
            if (activeState == -1 && currentState == null)
            {
                finished = true;
                if (cycleStates || (!running && !ran && autoStart))
                {
                    activeState = 0;
                    currentState = stateList[activeState];
                    currentStage = Stage.Enter;
                    running = true;
                    finished = false;
                    ran = true;
                }
            }
            if (finished || currentState == null)
                return;

            StateAction returnAction = currentState.Update(gameTime, currentStage);

            if (returnAction == StateAction.Continue)
            {
                switch (currentStage)
                {
                    case Stage.Enter:
                        currentStage = Stage.During;
                        break;
                    case Stage.During:
                        currentStage = Stage.Exit;
                        break;
                    case Stage.Exit:
                        {
                            if (activeState != -1)
                            {
                                if (currentState == stateList[activeState])
                                {
                                    activeState++;
                                    if (activeState >= stateList.Count)
                                        activeState = -1;
                                }
                            }

                            currentStage = Stage.Enter;
                            State stateOverride = currentState.OverrideGetNext();
                            if (stateOverride != null)
                                currentState = stateOverride;
                            else
                            {
                                if (activeState == -1)
                                    currentState = null;
                                else
                                    currentState = stateList[activeState];
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
        }
Example #2
0
 public override StateMachine.StateAction Enter(GameTime gameTime)
 {
     Console.Clear();
     return StateMachine.StateAction.Continue;
 }
Example #3
0
 public override StateMachine.StateAction Exit(GameTime gameTime)
 {
     return StateMachine.StateAction.Continue;
 }
Example #4
0
        public override StateMachine.StateAction During(GameTime gameTime)
        {
            switch (creationStep)
            {
                case CreationStep.Name:
                    string name = "";
                    while (String.IsNullOrEmpty(name))
                    {
                        name = Console.ReadLine();
                        if (String.IsNullOrEmpty(name))
                            continue;
                        player.Name = name;
                        creationStep = CreationStep.Class;
                    }
                    break;
                case CreationStep.Class:
                    while (player.Class == Player.PlayerClass.None)
                    {
                        keyInfo = Console.ReadKey(true);

                        if (keyInfo.Key == ConsoleKey.Spacebar)
                            return StateMachine.StateAction.Continue;

                        if (classItemList.ContainsKey(keyInfo.Key.ToString().ToUpper()))
                            while (!classItems[ClassIndex].Equals(keyInfo.Key.ToString()))
                                ClassIndex++;

                        if (keyInfo.Key == ConsoleKey.UpArrow || keyInfo.Key == ConsoleKey.LeftArrow)
                            ClassIndex--;
                        if (keyInfo.Key == ConsoleKey.DownArrow || keyInfo.Key == ConsoleKey.RightArrow)
                            ClassIndex++;

                        selectedItem = classItemList[classItems[ClassIndex]];

                        if (keyInfo.Key == ConsoleKey.Enter)
                        {
                            selectedItem = classItemList[classItems[ClassIndex]];
                            player.Class = (Player.PlayerClass)(ClassIndex + 1);

                            creationStep = CreationStep.Stats;
                            //return StateMachine.StateAction.Continue;
                        }

                        return StateMachine.StateAction.Remain;
                    }
                    break;
                case CreationStep.Stats:
                    while (player.Strength == 0)
                    {
                        keyInfo = Console.ReadKey(true);

                        if (keyInfo.Key == ConsoleKey.Spacebar)
                            return StateMachine.StateAction.Continue;

                        if (keyInfo.Key == ConsoleKey.R)
                        {
                            strength = rand.Next(8, 21);
                            dexterity = rand.Next(8, 21);
                            constitution = rand.Next(8, 21);
                            intelligence = rand.Next(8, 21);
                            wisdom = rand.Next(8, 21);
                            charisma = rand.Next(8, 21);
                        }

                        if (keyInfo.Key == ConsoleKey.Enter)
                        {
                            player.Strength = strength;
                            player.Dexterity = dexterity;
                            player.Constitution = constitution;
                            player.Intelligence = intelligence;
                            player.Wisdom = wisdom;
                            player.Charisma = charisma;
                            return StateMachine.StateAction.Continue;
                        }

                        if (keyInfo.Key == ConsoleKey.Enter)
                        {
                            //return StateMachine.StateAction.Continue;
                        }

                        return StateMachine.StateAction.Remain;
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (keyInfo.Key == ConsoleKey.X)
                return StateMachine.StateAction.Continue;
            return StateMachine.StateAction.Remain;
        }