示例#1
0
        public static void Main()
        {
            Console.WriteLine("Please enter a Queen x coordinate 1-7");
            string queenXLocation = Console.ReadLine();
            int    queenX         = int.Parse(queenXLocation);

            Console.WriteLine("Please enter a Queen y coordinate 1-7");
            string queenYLocation = Console.ReadLine();
            int    queenY         = int.Parse(queenYLocation);

            Console.WriteLine("Please enter an opponent x coordinate 1-7");
            string computerXLocation = Console.ReadLine();
            int    computerX         = int.Parse(computerXLocation);

            Console.WriteLine("Please enter an opponent y coordinate 1-7");
            string computerYLocation = Console.ReadLine();
            int    computerY         = int.Parse(computerYLocation);


            bool result = Queen.Attack(queenX, queenY, computerX, computerY);

            if (result)
            {
                Console.WriteLine("can attack");
            }
            else
            {
                Console.WriteLine("cannot attack");
            }
        }
示例#2
0
        public static void Main()
        {
            int x;

            Console.WriteLine("Insert X for Queen: ");
            bool success = int.TryParse(Console.ReadLine(), out x);

            if (success)
            {
            }
            else
            {
                Console.WriteLine("Please enter a valid number");
                Main();
            }
            Console.WriteLine("Insert Y for Queen: ");
            int y = int.Parse(Console.ReadLine());

            Console.WriteLine("Insert X for a piece: ");
            int xU = int.Parse(Console.ReadLine());

            Console.WriteLine("Insert Y for a piece: ");
            int yU = int.Parse(Console.ReadLine());

            if (x < 1 || y < 1 || xU < 1 || yU < 1 || x > 8 || y > 8 || xU > 8 || yU > 8)
            {
                Console.WriteLine("Invalid input");
                Main();
            }

            Queen queen = new Queen(x, y);

            if (queen.Attack(xU, yU))
            {
                Console.WriteLine("Queen will attack you!");
            }
            else
            {
                Console.WriteLine("Queen can't attack this field!");
            }
        }