我正在玩著名的石头剪刀布游戏。如果您在 10 轮后赢得比赛,则会显示一个窗口,并要求输入用户名。如果没有给出,则显示“ANONIEM”。因此,每次我开始新游戏并在对计算机的 10 轮比赛中获胜时,都会显示下一个窗口,再次要求输入用户名,并将日志添加到 TextBlock
。所以我的代码像其他系统正常工作一样从上到下放置它。
我的问题是:
我现在拥有的是:
我需要它做的是:
我的代码:
if (ronde > 0)
{
if (txtGebruikersnaam.Text.Length == 0)
{
txtScoreLog5.Text += "ANONIEM" + " - PC " + scorespeler + " - " + scorepc + " (" + DateTime.Now.ToString("HH:mm:ss") + ")" + "\r\n";
}
else if (txtGebruikersnaam.Text.Length > 0)
{
txtScoreLog5.Text += txtGebruikersnaam.Text + " - PC " + scorespeler + " - " + scorepc + " (" + DateTime.Now.ToString("HH:mm:ss") + ")" + "\r\n";
}
}
答案 0 :(得分:1)
只需将新文本添加到 TextBlock 文本的开头,如下所示:
if (ronde > 0)
{
string result = txtGebruikersnaam.Text.Length == 0 ? "ANONIEM" : txtGebruikersnaam.Text
txtScoreLog5.Text = result + " - PC " + scorespeler + " - " + scorepc + " (" + DateTime.Now.ToString("HH:mm:ss") + ")" + "\r\n" + txtScoreLog5.Text;
}