我正在为我的学校作业编写一个小游戏,该游戏是一个简单的 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
}
我使用很多不同的类来操作 LiveObjects 内的数据,然后为了避免传递整个列表,我可以直接在任何方法内调用它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)