跳到主要内容

游戏管理器与单例模式

示例

public class GameManager
{
private static GameManager instance;
private GameManager() { }
public static GameManager Instance
{
get
{
if (instance == null)
{
instance = new GameManager();
}
return instance;
}
}
private int bulletNumber;

public int ConsumeBullet(int capacity)
{
if(bulletNumber >= capacity)
{
bulletNumber -= capacity;
return capacity;
}
int tem = bulletNumber;
bulletNumber = 0;
return tem;
}
}