Exemplo n.º 1
0
        public override void MenuKeyPress(ConsoleKeyInfo pressedChar)
        {
            switch (pressedChar.Key)
            {
            case ConsoleKey.Escape:
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                ExitMenu();
                break;

            case ConsoleKey.Enter:
                MenuEnterButton();
                break;

            case ConsoleKey.RightArrow:
                MenuRightMove();
                break;

            case ConsoleKey.LeftArrow:
                MenuLeftMove();
                break;

            case ConsoleKey.UpArrow:
                MenuUpMove();
                break;

            case ConsoleKey.DownArrow:
                MenuDownMove();
                break;

            default:
                break;
            }
        }
Exemplo n.º 2
0
        public override void MenuKeyPress(ConsoleKeyInfo pressedChar)
        {
            switch (pressedChar.Key)
            {
            case ConsoleKey.R:
                OnMenuLeave?.Invoke(this, MenuOperations.Replay);
                ExitMenu();
                break;

            case ConsoleKey.M:
                OnMenuLeave?.Invoke(this, MenuOperations.GotoMainMenu);
                ExitMenu();
                break;

            case ConsoleKey.Q:
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                ExitMenu();
                break;

            case ConsoleKey.Enter:
                MenuEnterButton();
                break;

            case ConsoleKey.UpArrow:
                MenuUpMove();
                break;

            case ConsoleKey.DownArrow:
                MenuDownMove();
                break;

            default:
                break;
            }
        }
Exemplo n.º 3
0
        private void GameOverMenuCall()
        {
            Console.Clear();
            GameOverMenu gameOverMenu = new GameOverMenu(X, Y, Width, Height);

            gameOverMenu.TitleMenu.Label = $"Game over. Best score {player.GetPlayerScore}";

            gameOverMenu.OnMenuLeave += (sender, args) =>
            {
                OnMenuLeave?.Invoke(gameOverMenu, args);
            };

            gameOverMenu.Show();
        }
Exemplo n.º 4
0
        private void MenuButton_OnEnter(Button button)
        {
            switch (button.Name)
            {
            case "play":
                OnMenuLeave?.Invoke(this, MenuOperations.GotoPlayerSelectionMenu);
                break;

            case "quit":
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                break;

            default:
                throw new Exception("Not found button by name");
            }

            ExitMenu();
        }
Exemplo n.º 5
0
        private void MenuButton_OnEnter(Button button)
        {
            switch (button.Name)
            {
            case "play":
                //OnMenuLeave?.Invoke(this, MenuOperations.?);
                OnMenuLeave?.Invoke(this, MenuOperations.Play);
                //TODO: run play game
                break;

            case "quit":
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                break;

            default:
                throw new Exception("Not found button by name");
            }

            ExitMenu();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Menu navigation
        /// </summary>
        /// <param name="btn"></param>
        private void Buttons_OnEnter(Button btn)
        {
            switch (btn.Name)
            {
            case "reply":
                OnMenuLeave?.Invoke(this, MenuOperations.Replay);
                break;

            case "gotoMenu":
                OnMenuLeave?.Invoke(this, MenuOperations.GotoMainMenu);
                break;

            case "quit":
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                break;

            default:
                throw new Exception("Button not found with name");
            }
            ExitMenu();
        }
Exemplo n.º 7
0
        public override void MenuKeyPress(ConsoleKeyInfo pressedChar)
        {
            switch (pressedChar.Key)
            {
            case ConsoleKey.Escape:
                OnMenuLeave?.Invoke(this, MenuOperations.Quit);
                ExitMenu();
                break;

            case ConsoleKey.Enter:
                MenuEnterButton();
                break;

            case ConsoleKey.Add:
            case ConsoleKey.UpArrow:
                counterDice++;

                diceQuantity.Label = counterDice.ToString();
                Render();
                break;

            case ConsoleKey.Subtract:
            case ConsoleKey.DownArrow:
                if (counterDice > 1)
                {
                    counterDice--;
                }

                diceQuantity.Label = counterDice.ToString();
                Render();
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
        //private DateTime _lastPressTime = DateTime.MinValue;

        /// <summary>
        /// Game loop
        /// </summary>
        private void StartGameLoop()
        {
            bool needToRender  = true;
            int  _speedCounter = 0;

            while (needToRender)
            {
                while (!Console.KeyAvailable)
                {
                    System.Threading.Thread.Sleep(5);

                    if (_speedCounter < _speedGame)
                    {
                        _speedCounter++;
                    }
                    else
                    {
                        if (IsGameOver())
                        {
                            needToRender = false;

                            GameOverMenuCall();

                            break;
                        }

                        ShapeMoveDown();
                        Render();

                        _speedCounter = 0;
                    }
                }

                var key = Console.ReadKey(true).Key;

                switch (key)
                {
                case ConsoleKey.Escape:
                    needToRender = false;
                    OnMenuLeave?.Invoke(null, MenuOperations.GotoGameOverMenu);
                    break;

                case ConsoleKey.RightArrow:
                    ShapeMoveRight();
                    break;

                case ConsoleKey.LeftArrow:
                    ShapeMoveLeft();
                    break;

                case ConsoleKey.DownArrow:
                    ShapeMoveDown();
                    break;

                case ConsoleKey.Spacebar:
                    //Todo: rotate shape tetris
                    ShapeRotate();
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Game loop
        /// </summary>
        private void StartGameLoop()
        {
            bool needToRender = true;

            int timeCountRoll     = 0;
            int waitTimeCountRoll = 0;
            int rounds            = 1;

            do
            {
                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    int            hashCode    = pressedChar.Key.GetHashCode();


                    switch (pressedChar.Key)
                    {
                    case ConsoleKey.Escape:
                        needToRender = false;
                        OnMenuLeave?.Invoke(null, MenuOperations.GotoGameOverMenu);
                        break;

                    default:
                        break;
                    }
                }

                //game
                if (timeCountRoll <= TIME_DICE_ROLL)
                {
                    dicesGroup.RollingDiceAnimation();
                    timeCountRoll++;
                }
                else
                {
                    int id = playersGroup.GetActivePlayer();

                    if (waitTimeCountRoll == 0)
                    {
                        dicesGroup.RollDice();

                        playersGroup.AddScore(id, dicesGroup.SumaDices);
                        gameScreen.UpdatePlayerScoreInTable(id, playersGroup.GetPlayerScore(id));
                    }

                    if (id + 1 > playersGroup.CountPlayers() - 1)
                    {
                        if (waitTimeCountRoll <= WAIT_TIME_NEXT_ROLL)
                        {
                            waitTimeCountRoll++;
                        }
                        else
                        {
                            //visi zaidejai suzeide
                            //TODO: rezultatai
                            string winnerExist = playersGroup.GetWinner();

                            if (winnerExist != string.Empty)
                            {
                                needToRender = false;

                                Console.Clear();
                                gameScreen.Render();

                                GameOverMenu gameOverMenu = new GameOverMenu(X, Y, Width, Height);
                                gameOverMenu.TitleMenu.Label = winnerExist;

                                gameOverMenu.OnMenuLeave += (sender, args) =>
                                {
                                    OnMenuLeave?.Invoke(gameOverMenu, args);
                                };

                                gameOverMenu.Show();
                            }
                            else
                            {
                                gameScreen.SetMessage($"Run next round {++rounds}");
                                //next add one round
                                playersGroup.SetActivePlayer(0);
                                dicesGroup.SetReadyDices();
                                timeCountRoll     = 0;
                                waitTimeCountRoll = 0;
                            }
                        }
                    }
                    else
                    {
                        if (waitTimeCountRoll <= WAIT_TIME_NEXT_ROLL)
                        {
                            waitTimeCountRoll++;
                        }
                        else
                        {
                            playersGroup.SetActivePlayer(id + 1);
                            dicesGroup.SetReadyDices();
                            timeCountRoll     = 0;
                            waitTimeCountRoll = 0;
                        }
                    }
                }

                Render();
                System.Threading.Thread.Sleep(20);
            } while (needToRender);
        }