Exemplo n.º 1
0
        public void Show()
        {
            while (true)
            {
                PrintField(_model.Field);

                while (true)
                {
                    Console.WriteLine("Enter the number of field (1-9) and the number of cell (1-9) without spaces:");
                    string input = Console.ReadLine();

                    int inputField;
                    int inputCell;

                    if ((input.Length != 2) ||
                        !int.TryParse(input.Substring(0, 1), out inputField) ||
                        !int.TryParse(input.Substring(1, 1), out inputCell) ||
                        (inputField == 0) || (inputCell == 0))
                    {
                        continue;
                    }
                    try
                    {
                        _model.MakeMove(inputField, inputCell);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        continue;
                    }
                    break;
                }
                if (_model.Winner != 0)
                {
                    PrintField(_model.Field);
                    Console.WriteLine("The player {0} has won", (_model.Winner == 1) ? 'X' : '0');
                    return;
                }
            }
        }