Beispiel #1
0
    public static void Main()
    {
        Queen queen = new Queen();

        Console.WriteLine("Welcome to Queen Attack, a program that checks chessboard coordinates to determine whether a Queen may attack another piece.");

        Console.WriteLine("Enter an X-axis coordinate letter from the following: a, b, c, d, e, f, g, h");
        queen.XPosition = Console.ReadLine();

        Console.WriteLine("Enter a Y-axis coordinate number from the following: 1, 2, 3, 4, 5, 6, 7, 8");
        queen.YPosition = (int.Parse(Console.ReadLine()));

        Console.WriteLine("Your Queen is placed at " + queen.XPosition + queen.YPosition.ToString());
        Console.WriteLine("Now, where shall we place her quarry?");

        Console.WriteLine("Enter an X-axis coordinate letter from the following: a, b, c, d, e, f, g, h");
        string victimX = Console.ReadLine();

        Console.WriteLine("Enter a Y-axis coordinate number from the following: 1, 2, 3, 4, 5, 6, 7, 8");
        int victimY = int.Parse(Console.ReadLine());

        Console.WriteLine("Your Queen's quarry is placed at " + victimX + victimY.ToString());

        if (queen.Attack(victimX, victimY))
        {
            Console.WriteLine("Queen " + queen.XPosition + queen.YPosition.ToString() + " can attack quarry " + victimX + victimY.ToString());
        }
        else
        {
            Console.WriteLine("Queen " + queen.XPosition + queen.YPosition.ToString() + " cannot attack quarry " + victimX + victimY.ToString());
        }
    }
        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");
            }
        }
    static void Main()
    {
        bool  repeat = true;
        Queen queen  = new Queen();

        while (repeat)
        {
            Console.WriteLine("Enter coordinates for the Queen");
            Console.WriteLine("X coordinate");
            string queenXString = Console.ReadLine();
            Console.WriteLine("Y coordinate");
            string queenYString = Console.ReadLine();
            int    queenX       = -1;
            int    queenY       = -1;
            try{
                queenX = int.Parse(queenXString);
                queenY = int.Parse(queenYString);
            } catch (FormatException) {
                Console.WriteLine("Values are not whole numbers. Please try again.");
            }
            if (!(queenX >= 0 || queenY >= 0) || (queenX > 8 && queenY > 8))
            {
                Console.WriteLine("Values are not inside the chess board boundaries [0-7]. Please try again.");
            }
            else
            {
                queen.x = queenX;
                queen.y = queenY;
                repeat  = false;
            }
        }

        repeat = true;
        int otherX = -1;
        int otherY = -1;

        while (repeat)
        {
            Console.WriteLine("Where is the other piece?");
            Console.WriteLine("X coordinate");
            string otherXString = Console.ReadLine();
            Console.WriteLine("Y coordinate");
            string otherYString = Console.ReadLine();

            try{
                otherX = int.Parse(otherXString);
                otherY = int.Parse(otherYString);
            } catch (FormatException) {
                Console.WriteLine("Values are not whole numbers. Please try again.");
            }
            if (!(otherX >= 0 || otherY >= 0) || (otherX > 8 && otherY > 8))
            {
                Console.WriteLine("Values are not inside the chess board boundaries [0-7]. Please try again.");
            }
            else
            {
                repeat = false;
            }
        }
        if (queen.Attack(otherX, otherY))
        {
            Console.WriteLine("Attack successful!");
        }
        else
        {
            Console.WriteLine("She missed!");
        }
    }