我正在尝试为我的游戏编写一种天空盒系统。它将在某个时间开始变暗,并在某个时间开始变亮(在变暗之后)。我在寻找的是如何检查服务器时间是否在这些时间框架之间?
using System.Collections.Generic;
namespace Game.GameEnvironment
{
class GameEnvironmentHandler
{
/// <summary>
/// List of dark times.
/// </summary>
private List<string> _darkTimes;
/// <summary>
/// List of light times.
/// </summary>
private List<string> _lightTimes;
public GameEnvironmentHandler()
{
// any time before 19:00 and after 08:00 is also light.
_darkTimes = new List<string>
{
"19:00", // getting dark
"19:30",
"20:00",
"20:30",
"21:00" // fully dark
};
_lightTimes = new List<string>
{
"06:00", // getting light
"06:30",
"07:00",
"07:30",
"08:00" // fully light
};
}
/// <summary>
/// Checks if its hit the first stage of dark times.
/// </summary>
/// <returns></returns>
public bool IsGettingDark()
{
}
/// <summary>
/// Checks if its hit the first stage of light times.
/// </summary>
/// <returns></returns>
public bool IsGettingLight()
{
}
/// <summary>
/// Gets what stage of getting dark or light its at (1-5)
/// </summary>
/// <returns></returns>
public int GetTimeStage()
{
return 0;
}
}
}
答案 0 :(得分:1)
如果您能提供当前时间:
int darkeningStart = 19;
int darkeningEnd = 21;
int brighteningStart = 6;
int brighteningEnd = 8;
[...]
public bool IsGettingLight(int hour)
{
return (hour >= brighteningStart && hour < brighteningEnd);
}
IsGettingDark()也是如此。
如果您还可以提供当前时间的分钟,则可以实施阶段,但我不知道您的游戏是如何设置的。