Allow players to save the new AllowedWords back into aqawords.txt
The first thing you should do is find the method which loads the AllowedWords:
private static void LoadAllowedWords(ref List<string> AllowedWords)
{
try
{
StreamReader FileReader = new StreamReader("aqawords.txt");
while (!FileReader.EndOfStream)
{
AllowedWords.Add(FileReader.ReadLine().Trim().ToUpper());
}
FileReader.Close();
}
catch (Exception)
{
AllowedWords.Clear();
}
}
We are going to follow this structure but change everything to write instead of reading the files. Firstly create a new method:
private static void SaveAllowedWords(ref List<string> AllowedWords)
{
}
Now to setup the file writer:
private static void SaveAllowedWords(ref List<string> AllowedWords)
{
StreamWriter FileWriter = new StreamWriter("aqawords.txt");
FileReader.Close();
}
Now we need a loop to cycle through each allowed word, and write it to the file:
private static void SaveAllowedWords(ref List<string> AllowedWords)
{
StreamWriter FileWriter = new StreamWriter("aqawords.txt");
foreach (string word in AllowedWords)
{
FileWriter.WriteLine(word);
}
FileWriter.Close();
}