Exemple #1
0
        public TitleWorld(
            I2DRenderUtilities twodRenderUtilities,
            IAssetManagerProvider assetManagerProvider,
            IBackgroundCubeEntityFactory backgroundCubeEntityFactory,
            ISkin skin)
            : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin)
        {
            this.Title = this.AssetManager.Get<LanguageAsset>("language.TYCHAIA");

            this.AddMenuItem(
                this.AssetManager.Get<LanguageAsset>("language.SINGLEPLAYER"),
                () =>
                {
                    this.TargetWorld = this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateConnectWorld(true, GetLANIPAddress(), 9091));
                });
            this.AddMenuItem(
                this.AssetManager.Get<LanguageAsset>("language.MULTIPLAYER"),
                () =>
                {
                    this.TargetWorld = this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateMultiplayerWorld());
                });
            this.AddMenuItem(
                this.AssetManager.Get<LanguageAsset>("language.EXIT"),
                () =>
                {
                    if (this.GameContext != null)
                        this.GameContext.Game.Exit();
                });
        }
 public ScatterBackground(
     IBackgroundCubeEntityFactory backgroundCubeEntityFactory,
     IWorld world)
 {
     this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory;
     while (world.Entities.Count(x => x is BackgroundCubeEntity) < 100)
     {
         world.Entities.Add(this.m_BackgroundCubeEntityFactory.CreateBackgroundCubeEntity(false));
     }
 }
Exemple #3
0
        public LoadWorld(
            I2DRenderUtilities twodRenderUtilities,
            IAssetManagerProvider assetManagerProvider,
            IBackgroundCubeEntityFactory backgroundCubeEntityFactory,
            ILevelAPI levelAPI,
            ISkin skin)
            : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin)
        {
            var assetManager = assetManagerProvider.GetAssetManager();
            var returnText = assetManager.Get<LanguageAsset>("language.RETURN");

            this.AddMenuItem(returnText, () => { this.TargetWorld = this.GameContext.CreateWorld<TitleWorld>(); });

            // Get all available levels.
            foreach (var levelRef in levelAPI.GetAvailableLevels())
            {
                this.AddMenuItem(
                    new LanguageAsset(levelRef, levelRef),
                    () => { this.TargetWorld = this.GameContext.CreateWorld<TychaiaGameWorld>(); });
            }
        }
Exemple #4
0
        public MenuWorld(
            I2DRenderUtilities twodRenderUtilities, 
            IAssetManagerProvider assetManagerProvider, 
            IBackgroundCubeEntityFactory backgroundCubeEntityFactory, 
            ISkin skin)
        {
            this.m_2DRenderUtilities = twodRenderUtilities;
            this.AssetManager = assetManagerProvider.GetAssetManager();
            this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory;
            this.m_TitleFont = this.AssetManager.Get<FontAsset>("font.Title");
            this.m_PlayerModel = this.AssetManager.Get<ModelAsset>("model.Character");
            this.m_PlayerModelTexture = this.AssetManager.Get<TextureAsset>("model.CharacterTex");

            this.Entities = new List<IEntity>();

            this.m_CanvasEntity = new CanvasEntity(skin) { Canvas = new Canvas() };
            this.m_CanvasEntity.Canvas.SetChild(this.m_TitleMenu = new TitleMenu());

            // Don't add the canvas to the entities list; that way we can explicitly
            // order it's depth.
        }
Exemple #5
0
        public ConnectWorld(
            IKernel kernel, 
            I2DRenderUtilities twodRenderUtilities, 
            IAssetManagerProvider assetManagerProvider, 
            IBackgroundCubeEntityFactory backgroundCubeEntityFactory, 
            ISkin skin, 
            IProfiler profiler,
            IPersistentStorage persistentStorage,
            bool startServer, 
            IPAddress address, 
            int port)
            : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin)
        {
            this.m_2DRenderUtilities = twodRenderUtilities;
            this.m_PersistentStorage = persistentStorage;

            this.m_DefaultFont = assetManagerProvider.GetAssetManager().Get<FontAsset>("font.Default");
            this.m_Address = address;
            this.m_Port = port;
            TychaiaClient client = null;
            byte[] initial = null;
            Action cleanup = () =>
            {
                kernel.Unbind<INetworkAPI>();
                kernel.Unbind<IClientNetworkAPI>();
                if (client != null)
                {
                    client.Close();
                }

                this.TerminateExistingProcess();
            };

            if (startServer)
            {
                this.m_Actions = new Action[]
                {
                    () => this.m_Message = "Closing old process...", () => this.TerminateExistingProcess(),
                    () => this.m_Message = "Starting server...", () => this.StartServer(),
                    () => this.m_Message = "Creating client...", () => client = new TychaiaClient(port + 2, port + 3),
                    () => client.AttachProfiler(profiler),
                    () => this.m_Message = "Connecting to server...",
                    () => client.Connect(new DualIPEndPoint(address, port, port + 1)),
                    () => this.m_Message = "Binding node to kernel...",
                    () => kernel.Bind<INetworkAPI>().ToMethod(x => client),
                    () => kernel.Bind<IClientNetworkAPI>().ToMethod(x => client), () => this.m_Message = "Joining game...",
                    () => this.m_UniqueClientIdentifier = this.JoinGame(client), () => this.m_Message = "Retrieving initial game state...",
                    () => initial = client.LoadInitialState(), () => this.m_Message = "Starting client...",
                    () => this.m_PerformFinalAction = true
                };
            }
            else
            {
                this.m_Actions = new Action[]
                {
                    () => this.m_Message = "Creating client...", () => client = new TychaiaClient(port + 2, port + 3),
                    () => client.AttachProfiler(profiler),
                    () => this.m_Message = "Connecting to server...",
                    () => client.Connect(new DualIPEndPoint(address, port, port + 1)),
                    () => this.m_Message = "Binding node to kernel...",
                    () => kernel.Bind<INetworkAPI>().ToMethod(x => client),
                    () => kernel.Bind<IClientNetworkAPI>().ToMethod(x => client),
                    () => this.m_Message = "Joining game...",
                    () => this.m_UniqueClientIdentifier = this.JoinGame(client), () => this.m_Message = "Retrieving initial game state...",
                    () => initial = client.LoadInitialState(), () => this.m_Message = "Starting client...",
                    () => this.m_PerformFinalAction = true
                };
            }

            this.m_FinalAction =
                () =>
                this.TargetWorld =
                this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateTychaiaGameWorld(this.m_UniqueClientIdentifier, cleanup));

            var thread = new Thread(this.Run) { IsBackground = true };
            thread.Start();

            AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
            {
                if (this.m_Process != null)
                {
                    try
                    {
                        this.m_Process.Kill();
                        this.m_Process = null;
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
            };
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                if (this.m_Process != null)
                {
                    try
                    {
                        this.m_Process.Kill();
                        this.m_Process = null;
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
            };
        }