使用Get and Set C#的舍入计数器



Im使用Get;和Set;当用户输入"圆"、"分钟"one_answers"秒"时,我正在尝试制作一个圆计数器。我设法用Get创建了按钮和输入;设置问题是,当时间达到0分秒时,它不会将分秒重置为用户第一次输入的原始值,只是将其保持在0…请帮助。。我没有添加按钮或定时器启动代码,所有的工作只是设置问题

class User
{
public static int Rounds { get; set; } 
public static int InputRounds { get; set; }
public static int Sec { get; set; }
public static int Min { get; set; }
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e){
User.sec--;
if(User.sec <= 0) 
{
User.Min--;
}
if(User.Min <= 0) 
{
User.Rounds++;
}
if(User.Rounds >= User.InputRounds) // User.Input is the first value the user input 
{
User.Min = ????; // This is my problem with the question marks
User.Sec = ????; // Im trying to set the value back to the users value entered
User.Rounds++;   // then add 1 round
}
}

也许您只需要重构User类,除非必要,否则请不要使用静态属性。

public class User
{
private int oMin;
private int oSec;
public User(int min, int sec, int maxRounds)
{
Min = min;
oMin = min; // Saving Original Values
Sec = sec;
oSec = sec; // Saving Original Values
MaxRounds = maxRounds;
}
public int Rounds { get; private set; }
public int MaxRounds { get; }
public int Sec { get; private set; }
public int Min { get; private set; }
public void ReduceSec()
{
Sec--;
if (Sec <= 0)
{
Min--;
}
if (Min <= 0)
{
Rounds++;
}
if (Rounds >= MaxRounds)
{
Min = oMin;
Sec = oSec;
Rounds++;
}
}
}

最新更新