Esempio n. 1
0
        void RunGame()
        {
            var rnd = new Random();

            var game = new Game(Cols, Rows, 5, new RandomMapBuilder(Cols, Rows).Build(),
                                new BoardPosition(rnd.Next(Cols), 0));

            game.GameGoalReached  += GameOnGameGoalReached;
            game.MoveNotAvailable += GameOnMoveNotAvailable;
            game.MineFound        += GameOnMineFound;
            game.MoveReported     += GameOnMoveReported;
            game.LivesRunOut      += GameOnLivesRunOut;
            _gameIsOn              = true;

            Report(game.GetGameStatusArguments(), "Begin game");
            Console.WriteLine("User arrow keys to navigate, Esc to exit the game.");

            while (_gameIsOn)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    switch (key.Key)
                    {
                    case ConsoleKey.LeftArrow:
                        _characterDirection = MoveDirection.Left;
                        break;

                    case ConsoleKey.RightArrow:
                        _characterDirection = MoveDirection.Right;
                        break;

                    case ConsoleKey.UpArrow:
                        _characterDirection = MoveDirection.Up;
                        break;

                    case ConsoleKey.DownArrow:
                        _characterDirection = MoveDirection.Down;
                        break;

                    case ConsoleKey.Escape:
                        _gameIsOn = false;
                        break;

                    default:
                        break;
                    }
                    game.AdvanceGame(_characterDirection);
                }
                Thread.Sleep(100);
            }
        }