コード例 #1
0
        public override int[] GetShotPlacementInfo()
        {
            bool inputIsInt;
            int  ColNum;
            int  RowNum;
            bool hasLooped = false;

            do
            {
                Console.Clear();
                MyEnemyBoard.PrintBoard();
                if (hasLooped)
                {
                    Console.WriteLine("You already guessed that square, try again.");
                }
                do
                {
                    Console.WriteLine($"{Name}:Enter a Row number :");
                    inputIsInt = int.TryParse(Console.ReadLine(), out RowNum);
                } while (!inputIsInt || RowNum < 1 || RowNum > BoardSize);
                do
                {
                    Console.WriteLine($"{Name}:Enter a Column number :");


                    inputIsInt = int.TryParse(Console.ReadLine(), out ColNum);
                } while (!inputIsInt || ColNum < 1 || ColNum > BoardSize);
                hasLooped = true;
            } while (MyEnemyBoard.Matrix[RowNum][ColNum].HasBeenGuessed);
            return(new int[] { RowNum, ColNum });
        }
コード例 #2
0
        private void ViewEnemyBoard()
        {
            bool   hasCompletedTurn = false;
            string input;

            do
            {
                Console.Clear();
                MyEnemyBoard.PrintBoard();
                PrintShipsIveSunk();
                Console.WriteLine(Name);
                Console.WriteLine("1:Choose a square to shoot.");
                Console.WriteLine("2:Return to previous screen.");
                Console.WriteLine("Enter 1 to choose a square to shoot, 2 to return to the previous screen.");
                input = (Console.ReadLine());
                switch (input)
                {
                case "1":
                    TakeShot();
                    hasCompletedTurn = true;
                    break;

                case "2":
                    TakeTurn();
                    hasCompletedTurn = true;
                    break;

                default:
                    hasCompletedTurn = false;
                    break;
                }
            } while (!hasCompletedTurn);
        }