예제 #1
0
 private static string SignText(string strOverwrite)
 {
     if (strOverwrite.ToLower().StartsWith("[nb]") ||
         strOverwrite.ToLower().StartsWith("[nb1]") ||
         strOverwrite.ToLower().StartsWith("[nb2]"))
     {
         return(NoticeBoard.GenerateNoticeboardSign(strOverwrite));
     }
     if (strOverwrite.ToLower().Contains("[house]"))
     {
         _intHouseNumber++;
         do
         {
             string strName = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt")).Trim();
             strName      = strName.Substring(0, 1).ToUpper() + strName.Substring(1, strName.Length - 1);
             strOverwrite = RandomHelper.RandomFileLine(Path.Combine("Resources", "HouseTypes.txt")) + " of~" +
                            RandomHelper.RandomFileLine(Path.Combine("Resources", "Titles.txt")) +
                            " " + strName + "~- " + _intHouseNumber + " -";
         } while (!Utils.IsValidSign(strOverwrite));
     }
     else
     {
         Regex           reSquareBrackets = new Regex(@"(\[).*?(\])");
         MatchCollection mcSquareBrackets = reSquareBrackets.Matches(strOverwrite);
         for (int intIndex = mcSquareBrackets.Count - 1; intIndex >= 0; intIndex--)
         {
             string strCurrentWord = strOverwrite.Substring(mcSquareBrackets[intIndex].Index + 1,
                                                            mcSquareBrackets[intIndex].Length - 2);
             if (File.Exists(Path.Combine("Resources", strCurrentWord + ".txt")))
             {
                 strCurrentWord = RandomHelper.RandomFileLine(Path.Combine("Resources", strCurrentWord + ".txt"));
             }
             else
             {
                 strCurrentWord = "?" + strCurrentWord + "?";
                 Debug.Fail("Could not find a file for " + strCurrentWord);
             }
             strOverwrite = strOverwrite.Remove(mcSquareBrackets[intIndex].Index, mcSquareBrackets[intIndex].Length);
             strOverwrite = strOverwrite.Insert(mcSquareBrackets[intIndex].Index, strCurrentWord);
         }
     }
     return(strOverwrite);
 }
예제 #2
0
        private static string SignText(string strOverwrite)
        {
            if (strOverwrite.ToLower().StartsWith("[nb]") ||
                strOverwrite.ToLower().StartsWith("[nb1]") ||
                strOverwrite.ToLower().StartsWith("[nb2]"))
            {
                return(NoticeBoard.GenerateNoticeboardSign(strOverwrite));
            }
            if (strOverwrite.ToLower().Contains("[house]"))
            {
                intHouseNumber++;
            }
            Regex           reSquareBrackets = new Regex(@"(\[).*?(\])");
            MatchCollection mcSquareBrackets = reSquareBrackets.Matches(strOverwrite);

            // go backwards, because that way the indexes don't get messed up
            for (int intIndex = mcSquareBrackets.Count - 1; intIndex >= 0; intIndex--)
            {
                string strCurrentWord = strOverwrite.Substring(mcSquareBrackets[intIndex].Index + 1, mcSquareBrackets[intIndex].Length - 2);
                if (strCurrentWord.ToLower() == "house")
                {
                    strCurrentWord = "House " + intHouseNumber;
                }
                else if (File.Exists(Path.Combine("Resources", strCurrentWord + ".txt")))
                {
                    strCurrentWord = RandomHelper.RandomFileLine(Path.Combine("Resources", strCurrentWord + ".txt"));
                }
                else
                {
                    strCurrentWord = "?" + strCurrentWord + "?";
                }
                strOverwrite = strOverwrite.Remove(mcSquareBrackets[intIndex].Index, mcSquareBrackets[intIndex].Length);
                strOverwrite = strOverwrite.Insert(mcSquareBrackets[intIndex].Index, strCurrentWord);
            }
            return(strOverwrite);
        }