我正在为我的学校作业编写一个小游戏,该游戏是带有怪物,物品和子弹的简单2D游戏。基本上,您跑来跑去并试图收集所有物品硬币,怪物试图阻止您,您可以用收集的子弹将它们击落。很简单的。
问题是,我已将怪物,物品,墙壁,玩家和子弹添加到名为LiveObjects的静态类中,然后可以从代码中的任何位置访问这些对象。这是不好的做法吗?有什么选择?(它不是多线程的)
LiveObjects.cs
internal static class LiveObjects
{
public static List<Item> items = new List<Item>(); // List with all the items
public static List<Monster> monsters = new List<Monster>(); // List with all present monsters
public static List<Wall> walls = new List<Wall>(); // List with the walls
public static List<Bullet> bullets = new List<Bullet>(); // List with the bullets
public static Player player = new Player(0, 0); // The player object
}
Run Code Online (Sandbox Code Playgroud)
我使用许多不同的类来处理LiveObjects中的数据,然后避免传递整个List,我可以直接在任何方法中调用它。