示例#1
0
        public IGame CreateGame(string gameDir, GameMode mode, GameMap map)
        {
            MyTraceContext.ThreadTraceContext = new MyTraceContext("Server");

            WorldTickMethod tickMethod;

            switch (mode)
            {
                case GameMode.Fortress:
                    tickMethod = WorldTickMethod.Simultaneous;
                    break;

                case GameMode.Adventure:
                    tickMethod = WorldTickMethod.Sequential;
                    break;

                default:
                    throw new Exception();
            }

            var world = new World(mode, tickMethod);

            Action<World> worldCreator;

            switch (map)
            {
                case GameMap.Fortress:
                    worldCreator = Fortress.MountainWorldCreator.InitializeWorld;
                    break;

                case GameMap.Adventure:
                    var dwc = new Fortress.DungeonWorldCreator(world);
                    worldCreator = dwc.InitializeWorld;
                    break;

                case GameMap.Arena:
                    throw new Exception();

                default:
                    throw new Exception();
            }

            world.Initialize(delegate
            {
                worldCreator(world);
            });

            var engine = new GameEngine(world, mode);

            InitGame(engine, gameDir);

            return engine;
        }