Ejemplo 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);
        }
Ejemplo n.º 2
0
        private void HitStand()
        {
            for (int i = 0; i < players.Count; i++)
            {
                State currentState = State.Hit;
                buttonsList[0].SetActive();
                buttonsList[1].SetNotActive();

                ConsoleKeyInfo keyInfo;

                bool needMoreCards = true;
                do
                {
                    Console.Clear();
                    view.ShowWhoesTurn(players[i], i * 20);
                    Render();

                    CalculatePoints(players[i]);
                    if (players[i].GetPoins() > 21)
                    {
                        players[i].Busted = true;
                        needMoreCards     = false;
                    }
                    else
                    {
                        RenderHitStand();

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

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

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

                            case ConsoleKey.Enter:
                                switch (currentState)
                                {
                                case State.Hit:
                                    players[i].Hit(dealer);
                                    break;

                                case State.Stand:
                                    needMoreCards = false;
                                    break;
                                }
                                break;
                            }
                        }
                        System.Threading.Thread.Sleep(200);
                    }
                } while (needMoreCards);
            }
        }