Esempio n. 1
0
        public int ShowMenu(List <Player> players)
        {
            bool            renderWindow    = true;
            State           currentState    = State.Play;
            ActivityChanger activityChanger = new ActivityChanger();
            List <Button>   buttonsList     = new List <Button>()
            {
                new Button(50, 5, "Play"),
                new Button(50, 10, "Quit")
            };

            buttonsList[0].SetActive();

            ConsoleKeyInfo keyInfo;

            do
            {
                foreach (Button button in buttonsList)
                {
                    button.Render();
                }

                while (Console.KeyAvailable)
                {
                    keyInfo = Console.ReadKey(true);

                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.UpArrow:
                        if (currentState != State.Play)
                        {
                            currentState -= 1;
                            activityChanger.SetPreviousActive(buttonsList);
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (currentState != State.Quit)
                        {
                            currentState += 1;
                            activityChanger.SetNextActive(buttonsList);
                        }
                        break;

                    case ConsoleKey.Enter:
                        switch (currentState)
                        {
                        case State.Play:
                            PlayersSetUp(players);
                            break;

                        case State.Quit:
                            return(-1);
                        }
                        renderWindow = false;
                        break;
                    }
                }
                System.Threading.Thread.Sleep(100);
            } while (renderWindow);

            return(0);
        }