主要用于游戏角色以及单例的游戏体
class SingleObject { //单例设计模式 //1.构造函数私有化 private SingleObject() { } //2.声明全局唯一对象 private static SingleObject _single = null; //3.提供一个函数用于返回唯一一个对象 public static SingleObject GetSingle() { if(_single==null) { _single = new SingleObject(); } return _single; } //生成get set方法 public BackGround BG { get; set; } public PlaneHero PH { get; set; } //写一个函数,将游戏对象,添加到窗体中 public void AddGameObject(GameObject go) { if(go is BackGround) { this.BG = go as BackGround; } else if(go is PlaneHero) { this.PH = PH as PlaneHero; } } public void Draw(Graphics g) { this.BG.Draw(g); this.PH.Draw(g); } }