Pregunta

I am making a little word guessing game, and I'd like for the user to be able to guess the words. I have the following code, and it loads words from a text file located at string filename into a list box. However, I would like for the words to appear one by one in a textbox. The catch does not throw any errors out at all, the textbox is simply empty. Is this possible and could you show me some code so I can have a play please? Cheers!

I can then hide this word using one textbox, and trigger some code to move onto the next word if the typed word into the second, visible textbox is correct.

async private void LoadWords(string filename)
{
    var wordList = new List<String>();
    Windows.Storage.StorageFolder localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

    try
    {

        Windows.Storage.StorageFile sampleFile = await localFolder.GetFileAsync(filename);
        var words = await Windows.Storage.FileIO.ReadLinesAsync(sampleFile);

        foreach (var word in words)
        {
            wordList.Add(word); 
        } 

        HiddenWordBox.Text = string.Join(Environment.NewLine, wordList);
        }

        catch (Exception e)
        {
            MessageDialog CatchMsg = new MessageDialog(e.Message);
        }

    }
¿Fue útil?

Solución

Forgive me for my stupid question but isn't the following code required for it to be seen?

await CatchMsg.ShowAsync();

Not necessarily with the await operator.

Otros consejos

Change

HiddenWordBox.Text = string.Join(Environment.NewLine, wordList);

To

HiddenWordBox.Text = string.Join(Environment.NewLine, wordList.ToArray());

and the output should be as follows: http://ideone.com/DmFI0Z

(There's no constructor for string.Join involving List)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top