Esempio n. 1
0
        public static string ValidatePostion(PlayerInfoModel player, string position)
        {
            string output = position;

            // Validate string
            string pattern = @"(^[A-Ea-e][1-5]$)";
            Regex  reg     = new Regex(pattern);

            // Validate if spot is free
            bool isFreeSpot = false;
            bool checkSpot  = false;

            do
            {
                if (reg.IsMatch(output) == false)
                {
                    Console.Write(" Invalid position. Please try again: ");
                    output = Console.ReadLine();
                }
                else if (reg.IsMatch(output) == true && checkSpot == false)
                {
                    isFreeSpot = GameLogic.ValidateShipSpot(player, output);
                    checkSpot  = true;
                }
                else if (isFreeSpot == false)
                {
                    Console.Write(" There is already a ship in that position. Please try again: ");
                    output    = Console.ReadLine();
                    checkSpot = false;
                }
                else if (reg.IsMatch(output) == true && checkSpot == true)
                {
                    isFreeSpot = true;
                }
            } while (reg.IsMatch(output) == false || isFreeSpot == false);

            return(output);
        }