Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
            while (true)
            {
                try
                {
                    ChessCell cell1 = CellInput();                       //inicialization of first cell
                    Console.WriteLine($"{cell1} is {cell1.GetColor()}"); //output the color of the first cell

                    ChessCell cell2 = CellInput();                       //inicialization of second cell
                    Console.WriteLine($"{cell2} is {cell2.GetColor()}"); //output the color of the second cell

                    RelativePositionResercher resercher = new RelativePositionResercher();
                    Console.WriteLine(resercher.RelativePositionResearch(cell1, cell2));//comparing positions of first and second cell
                    break;
                }
                catch (InvalidFormatOfChessCell ex)
                {
                    Console.WriteLine(ex.Message + "Try again.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + "Try again.");
                }
            }
        }
Ejemplo n.º 2
0
        private static ChessCell CellInput()//method for new cell input
        {
            Console.Write("Enter cell: ");
            string cellInput = Console.ReadLine();

            CheckInputString(cellInput);
            ChessCell cell = new ChessCell(cellInput);

            return(cell);
        }
Ejemplo n.º 3
0
 public string RelativePositionResearch(ChessCell cell1, ChessCell cell2)//method for reserching relative position of two cells
 {
     if (cell1.Equals(cell2))
     {
         return($"{cell1} and {cell2} is the same cell.");
     }
     if (cell1.Column == cell2.Column)
     {
         return($"{cell1} and {cell2} lies in one column.");
     }
     if (cell1.Row == cell2.Row)
     {
         return($"{cell1} and {cell2} lies in one row.");
     }
     if (Math.Abs(cell1.Column - cell2.Column) == Math.Abs(cell1.Row - cell2.Row))
     {
         return($"{cell1} and {cell2} lies in one diagonal.");
     }
     else
     {
         return($"Positions of {cell1} and {cell2} do not relate.");
     }
 }