if ((ParseIsSuccessfull = int.TryParse(P1STRtextbox.Text, out result)) == true)//Try parsing the STR text box;If it parses successfully
{
PlayerOne[P1ClassNumber].Strength = 0;//These couple lines reset the value of strength initially
int SumOfAllStatPoints = PlayerOne[P1ClassNumber].Strength + //Without these couple lines the user cannot enter their total number of points into this text field
PlayerOne[P1ClassNumber].Dexterity + PlayerOne[P1ClassNumber].Vigor + //
PlayerOne[P1ClassNumber].RedMagic + PlayerOne[P1ClassNumber].BlueMagic;//
P1RemainingStatPointsLabel.Text = (PlayerOne[P1ClassNumber].TotalStatPoints - SumOfAllStatPoints).ToString();//Recalculate the remaining stat points each time the text is changed
PlayerOne[P1ClassNumber].Strength = int.Parse(P1STRtextbox.Text);//Store the parsed value into PlayerOnes Strength Value
if (PlayerOne[P1ClassNumber].Strength > int.Parse(P1RemainingStatPointsLabel.Text))//If PlayerOnes Strength Input is greater than the remaining stat points
{
MessageBox.Show("You have enter a number larger than your remaining stat points!");//Prompt the user to enter a valid number
}
else if (PlayerOne[P1ClassNumber].Strength < int.Parse(P1RemainingStatPointsLabel.Text))//If PlayerOnes Strength Input is less than the remaining stat points
{
PlayerOne[P1ClassNumber].Strength = int.Parse(P1STRtextbox.Text);//Store the STR input in an integer value
SumOfAllStatPoints = PlayerOne[P1ClassNumber].Strength + //Total up All of player ones stats that the user has the option to input a number for
PlayerOne[P1ClassNumber].Dexterity + PlayerOne[P1ClassNumber].Vigor + //In this case STR/DEX/VIG/RM/BM
PlayerOne[P1ClassNumber].RedMagic + PlayerOne[P1ClassNumber].BlueMagic;
PlayerOne[P1ClassNumber].RemainingStatPoints = (PlayerOne[P1ClassNumber].TotalStatPoints - SumOfAllStatPoints);
P1RemainingStatPointsLabel.Text = PlayerOne[P1ClassNumber].RemainingStatPoints.ToString();//Display the updated stat points in the remaining stat points label
}
}
else if ((ParseIsSuccessfull = int.TryParse(P1STRtextbox.Text, out result)) == true)//If the parse is unsuccessfull
{
MessageBox.Show("Please enter numbers only!");//Display an error message
}
功能的快速定义:玩家选择可玩的角色类,输入他们的等级(全部在&#34;类选择&#34;图片中的标签中完成)。在这样做后,他们输入他们的水平。获得该等级并乘以10以给予玩家他们可以分配给他们角色的总数量的统计点数。最初TotalStatPoints = RemainingStatPoints。然后用户转到&#34;输入统计数据&#34;选项卡,他们将分配他们的统计数据。每次用户更改文本框中的值时,都会更新其统计信息的值。
我的问题:一切正常,但是当我输入3000(这是我的总统计分数)时,显示我的剩余统计分数的字段显示3000而不是0.我想在我的代码中的某处它弄乱了并设置了剩余的stat points变量为3000,因为显示剩余点的Label已本地化。
问题:这里的问题似乎是什么?你能给出任何合理的建议吗?感谢您提前花时间和精力。
答案 0 :(得分:3)
代码错过了强度等于剩余统计点的条件 即使用&lt; =而不是&lt;