Esempio n. 1
0
        public void LoggerTest()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);

            typeO = TypeO.Create <TestGame>(GameName)
                    .SetLogger(LogLevel.None) as TypeO;
            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);
            Assert.Equal(LogLevel.None, typeO.Context.Logger.LogLevel);

            typeO = TypeO.Create <TestGame>(GameName)
                    .SetLogger <TestLogger>(LogLevel.None) as TypeO;
            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <TestLogger>(typeO.Context.Logger);
            Assert.Equal(LogLevel.None, typeO.Context.Logger.LogLevel);
        }
Esempio n. 2
0
        public void CreateWindowService()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .AddHardware <IWindowHardware, TestWindowHardware>()
                        .AddService <IWindowService, TestWindowService>() as TypeO;

            typeO.Start();

            var testGame = typeO.Context.Game as TestGame;

            Assert.NotNull(testGame.WindowService);
            Assert.IsType <TestWindowService>(testGame.WindowService);

            Assert.NotNull((testGame.WindowService as TestWindowService)?.WindowHardware);
            Assert.IsType <TestWindowHardware>((testGame.WindowService as TestWindowService)?.WindowHardware);

            var window = testGame.WindowService.CreateWindow();

            Assert.NotNull(window);
            Assert.IsType <TestWindow>(window);

            var canvas = testGame.WindowService.CreateCanvas(window);

            Assert.NotNull(canvas);
            Assert.IsType <TestCanvas>(canvas);

            var contentLoader = testGame.WindowService.CreateContentLoader(canvas);

            Assert.NotNull(contentLoader);
            Assert.IsType <TestContentLoader>(contentLoader);
        }
Esempio n. 3
0
        public void AddModule()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .LoadModule <TestModule>() as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(TestModule)) as TestModule;

            Assert.NotNull(module);
            Assert.IsType <TestModule>(module);
            Assert.NotEmpty(typeO.Context.Modules);
            Assert.Null(module.TestService);
            Assert.Null(module.TestHardware);

            typeO
            .AddHardware <ITestHardware, TestHardware>()
            .AddService <ITestService, TestServiceWithHardware>();

            typeO.Start();

            Assert.NotNull(module.TestService);
            Assert.NotNull(module.TestHardware);

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.RequireModule <TestModule>(new TypeOEngine.Typedeaf.Core.Engine.Version(1, 0, 0));
            Assert.Throws <InvalidOperationException>(() => typeO.Start());

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.LoadModule <TestRefModule>();
            Assert.Throws <InvalidOperationException>(() => typeO.Start());

            typeO = TypeO.Create <TestGameWithService>(GameName) as TypeO;
            typeO.LoadModule <TestRefModule>();
            typeO.LoadModule <TestModule>();
            Assert.Throws <InvalidOperationException>(() => typeO.Start());
        }
Esempio n. 4
0
        public void CreateGame()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            Assert.NotNull(typeO);
            Assert.NotNull(typeO.Context);
            Assert.NotNull(typeO.Context.Game);
            Assert.IsType <TestGame>(typeO.Context.Game);
        }
Esempio n. 5
0
        public void LoadDesktopModule()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .LoadModule <DesktopModule>() as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(DesktopModule)) as DesktopModule;

            Assert.NotNull(module);
            Assert.IsType <DesktopModule>(module);
            Assert.NotEmpty(typeO.Context.Modules);
        }
Esempio n. 6
0
        public void BindContent()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .BindContent <BaseContent, SubContent>() as TypeO;

            typeO.Start();

            Assert.NotEmpty(typeO.Context.ContentBinding);
            Assert.NotNull(typeO.Context.ContentBinding[typeof(BaseContent)]);
        }
Esempio n. 7
0
 public static void Main()
 {
     TypeO.Create <SpaceInvaderGame>("Space invader")
     .LoadModule <DesktopModule>(new DesktopModuleOption()
     {
         SaveLogsToDisk = false
     })
     .LoadModule <SDLModule>()
     .SetLogger(LogLevel.Info)
     .Start();
 }
Esempio n. 8
0
 static void Main()
 {
     TypeO.Create <BreakoutGame>("Breakout")
     .LoadModule <DesktopModule>(new DesktopModuleOption()
     {
         SaveLogsToDisk = false
     })
     .LoadModule <SDLModule>()
     .SetLogger(LogLevel.Info)
     .Start();
 }
Esempio n. 9
0
        public void AddHardware()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .AddHardware <ITestHardware, TestHardware>()
                        .AddService <ITestService, TestServiceWithHardware>() as TypeO;

            typeO.Start();

            var game = typeO.Context.Game as TestGameWithService;

            Assert.NotNull((game.TestService as TestServiceWithHardware)?.TestHardware);
            Assert.IsType <TestHardware>((game.TestService as TestServiceWithHardware)?.TestHardware);
            Assert.NotEmpty(typeO.Context.Hardwares);
        }
Esempio n. 10
0
        public void TestDefaultLogger()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .LoadModule <DesktopModule>(new DesktopModuleOption()
            {
                LogPath = "test"
            }, false) as TypeO;
            var module = typeO.Context.Modules.FirstOrDefault(m => m.GetType() == typeof(DesktopModule)) as DesktopModule;

            typeO.Start();

            Assert.NotNull(typeO.Context.Logger);
            Assert.IsType <DefaultLogger>(typeO.Context.Logger);
            Assert.Equal("test", (typeO.Context.Logger as DefaultLogger).LogPath);
        }
Esempio n. 11
0
        public void CreateKeyboardInputService()
        {
            var typeO = TypeO.Create <TestGame>(GameName)
                        .AddHardware <IKeyboardHardware, TestKeyboardHardware>()
                        .AddService <IKeyboardInputService, TestKeyboardInputService>() as TypeO;

            typeO.Start();

            var testGame = typeO.Context.Game as TestGame;

            Assert.NotNull(testGame.KeyboardInputService);
            Assert.IsType <TestKeyboardInputService>(testGame.KeyboardInputService);

            Assert.NotNull((testGame.KeyboardInputService as TestKeyboardInputService)?.KeyboardHardware);
            Assert.IsType <TestKeyboardHardware>((testGame.KeyboardInputService as TestKeyboardInputService)?.KeyboardHardware);
        }
Esempio n. 12
0
        public void AddService()
        {
            var typeO = TypeO.Create <TestGameWithService>(GameName)
                        .AddService <ITestService, TestService>() as TypeO;

            typeO.Start();

            var game = typeO.Context.Game as TestGameWithService;

            Assert.NotNull(game.TestService);
            Assert.IsType <TestService>(game.TestService);
            Assert.NotEmpty(typeO.Context.Services);

            typeO = TypeO.Create <TestGameWithService>(GameName)
                    .AddService <ITestService, TestServiceWithHardware>() as TypeO;
            Assert.Throws <InvalidOperationException>(() => typeO.Start());
        }
Esempio n. 13
0
        public void SwitchScene()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.LoadModule <DesktopModule>()
            .LoadModule <SDLModule>()
            .Start();

            var testGame = (typeO.Context.Game as TestGame);

            testGame.Scenes.SetScene <TestScene1>();

            Assert.NotNull(testGame.Scenes.CurrentScene);
            Assert.IsType <TestScene1>(testGame.Scenes.CurrentScene);

            var testScene = testGame.Scenes.CurrentScene as TestScene1;

            Assert.NotNull(testScene.Logger);
            Assert.IsType <DefaultLogger>(testScene.Logger);

            Assert.NotNull(testScene.WindowService);
            Assert.NotNull((testScene.WindowService as WindowService).WindowHardware);
            Assert.IsType <SDLWindowHardware>((testScene.WindowService as WindowService).WindowHardware);

            Assert.NotNull(testScene.KeyboardInputService);
            Assert.NotNull((testScene.KeyboardInputService as KeyboardInputService).KeyboardHardware);
            Assert.IsType <SDLKeyboardHardware>((testScene.KeyboardInputService as KeyboardInputService).KeyboardHardware);

            Assert.NotNull(testScene.Scenes);

            Assert.NotNull(testScene.Scenes.Window);
            Assert.IsType <SDLWindow>(testScene.Scenes.Window);

            Assert.NotNull(testScene.Scenes.Canvas);
            Assert.IsType <SDLCanvas>(testScene.Scenes.Canvas);

            Assert.NotNull(testScene.Scenes.ContentLoader);
            Assert.IsType <SDLContentLoader>(testScene.Scenes.ContentLoader);

            testGame.Scenes.SetScene <TestScene2>();
            Assert.NotNull(testGame.Scenes.CurrentScene);
            Assert.IsType <TestScene2>(testGame.Scenes.CurrentScene);
        }
Esempio n. 14
0
        public void LoadDefaults()
        {
            var typeO = TypeO.Create <TestGame>(GameName) as TypeO;

            typeO.LoadModule <DesktopModule>()
            .LoadModule <SDLModule>()
            .Start();

            Assert.NotEmpty(typeO.Context.ContentBinding);
            Assert.NotEmpty(typeO.Context.Hardwares);
            Assert.NotEmpty(typeO.Context.Services);

            var testGame = (typeO.Context.Game as TestGame);

            Assert.NotNull(testGame.Logger);
            Assert.IsType <DefaultLogger>(testGame.Logger);

            Assert.NotNull(testGame.WindowService);
            Assert.NotNull((testGame.WindowService as WindowService).WindowHardware);
            Assert.IsType <SDLWindowHardware>((testGame.WindowService as WindowService).WindowHardware);

            Assert.NotNull(testGame.KeyboardInputService);
            Assert.NotNull((testGame.KeyboardInputService as KeyboardInputService).KeyboardHardware);
            Assert.IsType <SDLKeyboardHardware>((testGame.KeyboardInputService as KeyboardInputService).KeyboardHardware);

            Assert.NotNull(testGame.Scenes);

            Assert.NotNull(testGame.Scenes.Window);
            Assert.IsType <SDLWindow>(testGame.Scenes.Window);

            Assert.NotNull(testGame.Scenes.Canvas);
            Assert.IsType <SDLCanvas>(testGame.Scenes.Canvas);

            Assert.NotNull(testGame.Scenes.ContentLoader);
            Assert.IsType <SDLContentLoader>(testGame.Scenes.ContentLoader);
        }