Ejemplo n.º 1
0
        private void ProcessCommand(string[] command)
        {
            ConsoleVisualizer visualizer = new ConsoleVisualizer(field);

            if (command.Length == 1)
            {
                string gameCommand = command[0];

                switch (gameCommand)
                {
                case "restart": Play();
                    break;

                case "top": visualizer.VisualizeScore(this.Scores);
                    break;

                case "exit": this.Exit();
                    break;

                default: visualizer.VisualizeField();
                    break;
                }
            }
            else if (command.Length == 2)
            {
                int  row      = 0;
                int  col      = 0;
                bool tryParse = false;
                tryParse = (Int32.TryParse(command[0], out row) || tryParse);
                tryParse = (Int32.TryParse(command[1], out col) || tryParse);

                if (!tryParse)
                {
                    throw new CommandUnknownException();
                }

                if (field.RevealCell(row, col) == '*')
                {
                    field.MarkAndRevealEmptyFields('-');
                    field.RevealMines();
                    Console.WriteLine(field.ToString());
                    Console.WriteLine(String.Format("Booooom! You were killed by a mine. You revealed {0} cells without mines.", CurrentScore));
                    Console.Write("Please enter your name for the top scoreboard: ");
                    string playerName = Console.ReadLine();
                    Scores.Add(new Score(playerName, this.CurrentScore));
                    Console.WriteLine();
                    PrintScoreBoard();
                    //Play();
                }
                else
                {
                    visualizer.VisualizeField();
                    //Console.WriteLine(field.ToString());
                    this.CurrentScore++;
                    //ProcessCommand(command);
                }
                //TODO: Implement the missed logic
            }
            else
            {
                throw new CommandUnknownException("No exist such command!");
            }
        }