c#比较int值(在文本框和文本块中)

c#比较int值(在文本框和文本块中),c#,C#,我正在创建一个排名系统(在c#Windows 8应用程序中),其工作原理如下: 示例:比赛分数=2-1 玩家A:预测=1-1(输入1个正确的分数输入得1分) 球员B:预测=0-2(0分) 球员C:Forecast=3-0(球队获胜得3分) 球员D:Forecast=2-0(4分:表示球队获胜的3分+1分正确的分数输入) 球员E:Forecast=2-1(5分:表示球队获胜的3分+2分正确的分数输入 在2文本框中输入比赛分数(MatchScore1和MatchScore2) 玩家的预测在2个文本块

我正在创建一个排名系统(在c#Windows 8应用程序中),其工作原理如下:

示例:比赛分数=2-1

玩家A:预测=1-1(输入1个正确的分数输入得1分)

球员B:预测=0-2(0分)

球员C:Forecast=3-0(球队获胜得3分)

球员D:Forecast=2-0(4分:表示球队获胜的3分+1分正确的分数输入)

球员E:Forecast=2-1(5分:表示球队获胜的3分+2分正确的分数输入

在2文本框中输入比赛分数(MatchScore1和MatchScore2) 玩家的预测在2个文本块中(预测1和预测2) 单击按钮时,它计算分数并将其显示在文本块(AmountPoints)中

我目前所做的:

  private void btnBereken_Click(object sender, RoutedEventArgs e)
    {
        int score = 0;
        // Check: Correct input score
        if (Forecast1.Text == MatchScore1.Text)
        {
           score += 1;
           AmountPoints.Text = score.ToString();
        }
        // Check: Correct input score
        if (Forecast2.Text == MatchScore2.Text)
        {
            score += 1;
            AmountPoints.Text = score.ToString();
        }
        // nothing correct
        else
        {
            AmountPoints.Text = score.ToString();
        }
    }
你知道如何检查预测是否进入了正确的队伍以赢得比赛吗??
如果一场比赛的比分是平局,那么玩家也应该得到3分,我该怎么做呢?

首先,将文本框中的数字移出。你应该将你的用户界面与你的业务逻辑分开。这将导致你有一个函数来做“数学”您的用户界面必须调用该函数。通过将文本转换为数字,您可以将这些数字与
进行比较,以查看谁赢了

int foreCast1 = int.Parse(Forecast1.Text);
int foreCast2 = int.Parse(Forecast2.Text);
int matchScore1 = int.Parse(MatchScore1.Text);
int matchScore2 = int.Parse(MatchScore2.Text);
AmountPoints.Text = DoTheMath(foreCast1, foreCast2, amountPoints1, amountPoints2).ToString();
...
public int DoTheMath(int foreCast1, int foreCast2, int matchScore1 , int matchScore2 )
{
    int score = 0;
    if (forecast1 == matchScore1)
        score++;
    if (forecast2 == matchScore2)
        score++;
    if (matchScore1 > matchScore2 && foreCast1 > foreCast2)
        score += 3;
    if (matchScore1 < matchScore2 && foreCast1 < foreCast2)
        score += 3;
    return score;
}
intforecast1=int.Parse(foreCast1.Text);
int foreCast2=int.Parse(foreCast2.Text);
int matchScore1=int.Parse(matchScore1.Text);
int matchScore2=int.Parse(matchScore2.Text);
AmountPoints.Text=DoTheMath(foreCast1、foreCast2、amountPoints1、amountPoints2).ToString();
...
公共int-DoTheMath(int-foreCast1、int-foreCast2、int-matchScore1、int-matchScore2)
{
智力得分=0;
如果(预测1==matchScore1)
分数++;
如果(预测2==matchScore2)
分数++;
if(matchScore1>matchScore2&&foreCast1>foreCast2)
分数+=3分;
if(matchScore1
1-正确标记您的问题。2-在基于XAML的技术中,不要在过程代码中操纵UI元素。UI不是数据。学习MVVM,这是正确的编码方式。