P
P
pechenushka212019-05-27 22:19:15
C++ / C#
pechenushka21, 2019-05-27 22:19:15

How to record the player's result after each play through the game in a text file?

i have the name of the player (the name is entered at the beginning of the game) and for how long he found all the words in the picture (this is already a game), but if you go through the second time, then the record in the file instead of the first result is replaced by the result of the second player
how to do it the result of the second player was written below the first result in a line in the file?
here is the code with writing to a file (you need to redo it to write the result of each new player to the file from a new line):

if (IsAllClicked())
{
        SaveRecord();
        File.WriteAllLines(@"C:\results.txt", records.Select(x => $"Username: {x.Username}, TimeInSeconds: {x.TimeInSeconds}"));
}
private List<Record> records = new List<Record>();

public void SaveRecord()
{
    var record = new Record();
    record.TimeInSeconds = 180 - i;
    record.Username = textBox1.Text;
    records.Add(record);

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2019-05-27
@pechenushka21

File.AppendAllLines

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question