Exemplo n.º 1
0
        public override bool HandleInput()
        {
            var originalColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Black;

            var exitInputLoop = false;

            do
            {
                var input = GetPlayerInput();

                if (input == Inputs.cancel)
                {
                    var dialog = new ConfirmDialog("Are you sure you want to exit the game?");
                    dialog.Process();
                    var result = dialog.DialogResult;
                    Draw();
                    if (result == ConfirmDialogResult.Yes)
                    {
                        Debug("Exit Game = [Y]");
                        ScreenResult = new ScreenTransitionResult {
                            FromScreen = ScreenType.MainMenu, ToScreen = ScreenType.None
                        };
                        return(false);
                    }

                    return(true);
                }

                if (input.Key == ConsoleKey.L)
                {
                    if (Layout.SelectedHeroIndex == -1)
                    {
                        Debug("You have not selected a hero yet....");
                        return(true);
                    }
                    var selectedHero = Storage.Heroes[Layout.SelectedHeroIndex];
                    ScreenResult = new ScreenTransitionResult {
                        FromScreen = ScreenType.NewPlayer, ToScreen = ScreenType.InGame, Result = selectedHero.Name
                    };

                    Debug("Loading Hero....");
                    return(false);
                }

                if (input.Key == ConsoleKey.N)
                {
                    Debug("New Hero....");
                    ScreenResult = new ScreenTransitionResult {
                        FromScreen = ScreenType.MainMenu, ToScreen = ScreenType.NewPlayer
                    };

                    return(false);
                }

                if (input.Key == ConsoleKey.D)
                {
                    Debug("Deleting Hero....");

                    if (Layout.SelectedHeroIndex == -1)
                    {
                        Debug("You have not selected a hero yet....");
                    }
                    else
                    {
                        var dialog = new ConfirmDialog("Are you sure you want to delete this hero?");
                        dialog.Process();
                        var result = dialog.DialogResult;
                        Draw();
                        if (result == ConfirmDialogResult.Yes)
                        {
                            Debug("Deleting Hero = [Y]");
                            Storage.Heroes.RemoveAt(Layout.SelectedHeroIndex);
                            Storage.Save();
                            Layout.Storage = Storage;
                            Layout.Initialise();
                            var buffer = new BufferContainer(0, 0, (short)ScreenHeight, (short)ScreenWidth);
                            Layout.Draw(buffer);
                        }
                        else
                        {
                            Debug("Deleting Hero = [N]");
                        }
                    }
                    return(true);
                }

                if (input == Inputs.n)
                {
                    Layout.DecrementSelectedHero();
                    return(true);
                }

                if (input == Inputs.s)
                {
                    Layout.IncrementSelectedHero();
                    return(true);
                }
            } while (exitInputLoop == false);

            Console.ForegroundColor = originalColor;

            return(false);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            var storage = new Storage(GameContent.Instance);

            storage.Load();

            var screenResult = new ScreenTransitionResult {
                ToScreen = ScreenType.MainMenu
            };

            var exitLoop = false;

            do
            {
                switch (screenResult.ToScreen)
                {
                case ScreenType.None:
                {
                    exitLoop = true;
                    break;
                }

                case ScreenType.MainMenu:
                {
                    var screen = new MainMenuScreen(storage);
                    screenResult = screen.Process();
                    break;
                }

                case ScreenType.NewPlayer:
                {
                    var screen = new NewPlayerScreen(storage);
                    screenResult = screen.Process();
                    break;
                }

                case ScreenType.InGame:
                {
                    try
                    {
                        var screen = new InGameScreen(storage, screenResult.Result.ToString());
                        screenResult = screen.Process();
                    }
                    catch (StageNotFoundExpection ex)
                    {
                        screenResult = new ScreenTransitionResult()
                        {
                            FromScreen = ScreenType.InGame,
                            ToScreen   = ScreenType.GameVictory
                        };
                    }
                    break;
                }

                case ScreenType.GameOver:
                {
                    var screen = new GameOverScreen(storage);
                    screenResult = screen.Process();
                    break;
                }

                case ScreenType.GameVictory:
                {
                    var screen = new GameVictoryScreen(storage);
                    screenResult = screen.Process();
                    break;
                }

                default:
                {
                    throw new ApplicationException("Invalid Screen / Unhandled Screen");
                }
                }
            } while (exitLoop == false);


            //GameRunner runner = new GameRunner();
            //runner.Process();
        }