コード例 #1
0
        private void StartInteraction()
        {
            string readBuffer = null;
            int    blownMines = 0;

            for (int i = 0; i < 50; i++)
            {
                Console.WriteLine();
            }


            while (GameServices.ContainsMines(gameField))
            {
                GameServices.PokajiMiRezultata(gameField);
                Console.Write("Please enter coordinates: ");
                readBuffer = Console.ReadLine();
                Mine mineToBlow =


                    GameServices.ExtractMineFromString(readBuffer);

                while (mineToBlow == null)
                {
                    Console.Write("Please enter coordinates: ");
                    readBuffer = Console.ReadLine();
                    mineToBlow = GameServices.ExtractMineFromString(readBuffer);
                }

                if (!GameServices.IsValidMove(gameField, mineToBlow.X, mineToBlow.Y))
                {
                    Console.WriteLine("Invalid move!");
                    continue;
                }

                GameServices.Гърми(gameField, mineToBlow);
                blownMines++;
            }

            GameServices.PokajiMiRezultata(gameField);
            Console.WriteLine("Game over. Detonated mines: {0}", blownMines);
        }
コード例 #2
0
        private void GameLoop()
        {
            int blownMines = 0;

            while (GameServices.ContainsMines(this.gameField))
            {
                GameServices.PrintResults(this.gameField);
                Position2D inputPosition = GetMoveInput();
                if (GameServices.IsValidMove(this.gameField, inputPosition.X, inputPosition.Y))
                {
                    GameServices.Explode(this.gameField, inputPosition);
                    blownMines++;
                }
                else
                {
                    Console.WriteLine("Invalid move!");
                }
            }

            EndGame(blownMines);
        }