当前位置: 首页>>代码示例>>C#>>正文


C# Game.AddPrototype方法代码示例

本文整理汇总了C#中Game.AddPrototype方法的典型用法代码示例。如果您正苦于以下问题:C# Game.AddPrototype方法的具体用法?C# Game.AddPrototype怎么用?C# Game.AddPrototype使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Game的用法示例。


在下文中一共展示了Game.AddPrototype方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddComponentWithExistingDefine

        public void AddComponentWithExistingDefine()
        {
            Game game = new Game("Test Game");

            Using use = new Using() { File = Path.GetFileName(typeof(TransformComponent).Assembly.Location) };
            game.AddUsing(use);

            Define define = new Define(TransformComponentShort, TransformComponentType);
            use.AddDefine(define);

            Entity entity = new Entity() { Name = "entity" };

            Component component = new Component(game.GetPlugin(TransformComponentShort));
            entity.AddComponent(component);
            game.AddPrototype(entity);

            Assert.AreEqual(1, game.Usings.Count);
            Assert.AreEqual(1, game.Usings.Single().Defines.Count(x => x.Name == TransformComponentShort && x.Class == TransformComponentType));
            Assert.AreEqual(TransformComponentShort, component.Type);
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:20,代码来源:GameTests.cs

示例2: AddComponentWithoutExistingDefine

        public void AddComponentWithoutExistingDefine()
        {
            bool firedPluginUsed = false;
            bool firedDefineAdded = false;

            Game game = new Game("Test Game");
            game.AddHandler<PluginUsed>(n => firedPluginUsed = true);
            game.AddHandler<DefineAdded>(n => firedDefineAdded = true);

            Entity entity = new Entity() { Name = "entity" };
            game.AddPrototype(entity);

            Component component = new Component(game.GetPlugin(TransformComponentType));
            entity.AddComponent(component);

            Assert.IsTrue(firedPluginUsed);
            Assert.IsTrue(firedDefineAdded);
            Assert.AreEqual(1, game.Usings.Count);
            Assert.AreEqual(1, game.Usings.Single().Defines.Count(x => x.Name == TransformComponentShort && x.Class == TransformComponentType));
            Assert.AreEqual(TransformComponentShort, component.Type);
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:21,代码来源:GameTests.cs

示例3: CreateTestGame

        // Multiple inheritance tests
        private static Game CreateTestGame()
        {
            var game = new Game("Test Game");

            var prototypeA0 = new Entity() { Name = "prototypeA0" };
            game.AddPrototype(prototypeA0);
            var prototypeB0 = new Entity() { Name = "prototypeB0" };
            game.AddPrototype(prototypeB0);
            var prototypeC0 = new Entity() { Name = "prototypeC0" };
            game.AddPrototype(prototypeC0);

            var prototypeA1 = new Entity() { Name = "prototypeA1" };
            prototypeA1.AddPrototype(prototypeA0);
            game.AddPrototype(prototypeA1);

            var prototypeB1 = new Entity() { Name = "prototypeB1" };
            prototypeB1.AddPrototype(prototypeB0);
            prototypeB1.AddPrototype(prototypeC0);
            game.AddPrototype(prototypeB1);

            var scene = new Scene("Test Scene");
            game.FirstScene = scene;
            var testEntity = new Entity() { Name = "testEntity" };
            scene.AddEntity(testEntity);
            testEntity.AddPrototype(prototypeA1);
            testEntity.AddPrototype(prototypeB1);

            return game;
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:30,代码来源:AttributeTests.cs

示例4: GameViewModel

        public GameViewModel(Game game)
        {
            this.game = game;

            game.PropertyChanged += Game_PropertyChanged;

            Prototypes = new ComputedObservableCollection<Entity, EntityViewModel>(game.Prototypes, (prototype) => new EntityViewModel(prototype));
            Scenes = new ComputedObservableCollection<Scene, SceneViewModel>(game.Scenes, (scene) => new SceneViewModel(scene));

            AddPrototypeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = new Entity();

                    DialogService.ShowDialog(DialogService.Constants.EntityDialog, prototype,
                        (result) =>
                        {
                            if (result == true)
                            {
                                game.AddPrototype(prototype);
                            }
                        }
                    );
                }
            );

            RemovePrototypeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = parameter as Entity;
                    game.RemovePrototype(prototype);
                }
            );

            AddSceneCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Scene scene = game.CreateScene();

                    DialogService.ShowDialog(DialogService.Constants.SceneDialog, scene,
                        (result) =>
                        {
                            if (result == true)
                            {
                                game.AddScene(scene);
                            }
                        }
                    );
                }
            );

            RemoveSceneCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Scene scene = parameter as Scene;
                    game.RemoveScene(scene);
                }
            );

            AddAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    game.CreateAttribute();
                }
            );

            RemoveAttributeCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Attribute attribute = parameter as Attribute;
                    game.RemoveAttribute(attribute);
                }
            );

            AddAssetCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    // TODO: File Chooser
                    Asset asset = new Asset("An Asset");
                    game.AddAsset(asset);
                }
            );

            RemoveAssetCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Asset asset = parameter as Asset;
                    game.RemoveAsset(asset);
                }
            );

            RemoveItemCommand = new DelegateCommand(null,
                (parameter) =>
                {
                    Entity prototype = parameter as Entity;
                    if (null != prototype)
                    {
                        game.RemovePrototype(prototype);
                    }
                    else
//.........这里部分代码省略.........
开发者ID:kinectitude,项目名称:kinectitude,代码行数:101,代码来源:GameViewModel.cs

示例5: LoadGame

        public Game LoadGame()
        {
            Parser parser = new Parser(grammar);
            src = File.ReadAllText(FileName.FullName);
            ParseTree parseTree = parser.Parse(src, FileName.FullName);

            if (parseTree.HasErrors())
            {
                throw new StorageException(BuildErrorMessage(parseTree.ParserMessages, FileName.Name));
            }

            root = parseTree.Root;
            var nameProperty = GetProperties(root).First(x => x.Item1 == "Name");
            var name = getStrVal((ParseTreeNode)nameProperty.Item2);
            game = new Game(new Value(name).GetStringValue());
            AddDefaultUsings(game);
            IEnumerable<ParseTreeNode> usings = grammar.GetOfType(root, grammar.Uses);

            foreach(ParseTreeNode node in usings)
            {
                Using use = CreateUsing(node);
                game.AddUsing(use);
            }

            foreach (Tuple<string, object> attribute in GetProperties(root))
            {
                ParseTreeNode attributeNode = (ParseTreeNode)attribute.Item2;
                if (attribute.Item1 != "Name")
                {
                    game.AddAttribute(new Attribute(attribute.Item1) { Value = new Value(getStrVal(attributeNode)) });
                }
            }

            foreach (ParseTreeNode prototype in grammar.GetOfType(root, grammar.Prototype))
            {
                Entity entity = CreateEntity(prototype, null, true);
                game.AddPrototype(entity);
            }

            foreach (ParseTreeNode serviceNode in grammar.GetOfType(root, grammar.Service))
            {
                Service service = CreateService(serviceNode);
                game.AddService(service);
            }

            foreach (ParseTreeNode sceneNode in grammar.GetOfType(root, grammar.Scene))
            {
                Scene scene = CreateScene(sceneNode);
                game.AddScene(scene);
            }

            var firstScene = game.GetAttribute("FirstScene");
            game.FirstScene = game.GetScene(firstScene.Value.GetStringValue());
            game.RemoveAttribute(firstScene);

            return game;
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:57,代码来源:KglGameStorage.cs

示例6: AddPrototype

        public void AddPrototype()
        {
            bool collectionChanged = false;

            Game game = new Game("Test Game");
            game.Prototypes.CollectionChanged += (o, e) => collectionChanged = true;

            Entity entity = new Entity() { Name = "TestPrototype" };
            game.AddPrototype(entity);

            Assert.IsTrue(collectionChanged);
            Assert.AreEqual(game.Prototypes.Count(), 1);
            Assert.AreEqual(game.Prototypes.First().Name, "TestPrototype");
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:14,代码来源:GameTests.cs

示例7: RemovePrototype

        public void RemovePrototype()
        {
            int eventsFired = 0;

            Game game = new Game("Test Game");
            game.Prototypes.CollectionChanged += (o, e) => eventsFired++;

            Entity entity = new Entity() { Name = "TestPrototype" };
            game.AddPrototype(entity);
            game.RemovePrototype(entity);

            Assert.AreEqual(2, eventsFired);
            Assert.AreEqual(game.Prototypes.Count(), 0);
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:14,代码来源:GameTests.cs

示例8: PrototypeMustHaveName

        public void PrototypeMustHaveName()
        {
            bool collectionChanged = false;

            Game game = new Game("Test Game");
            game.Prototypes.CollectionChanged += (o, e) => collectionChanged = true;

            game.AddPrototype(new Entity());

            Assert.IsFalse(collectionChanged);
            Assert.AreEqual(0, game.Prototypes.Count);
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:12,代码来源:GameTests.cs

示例9: CannotAddDuplicatePrototypeName

        public void CannotAddDuplicatePrototypeName()
        {
            int eventsFired = 0;

            Game game = new Game("Test Game");
            game.Prototypes.CollectionChanged += (o, e) => eventsFired++;

            game.AddPrototype(new Entity() { Name = "prototype" });
            game.AddPrototype(new Entity() { Name = "prototype" });

            Assert.AreEqual(1, eventsFired);
            Assert.AreEqual(1, game.Prototypes.Count(x => x.Name == "prototype" ));
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:13,代码来源:GameTests.cs

示例10: Game_RemoveItem

        public void Game_RemoveItem()
        {
            var game = new Game("Test Game");
            var scene = new Scene("Test Scene");
            game.AddScene(scene);

            CommandHelper.TestUndoableCommand(
                () => Assert.AreEqual(1, game.Scenes.Count),
                () => game.RemoveItemCommand.Execute(scene),
                () => Assert.AreEqual(0, game.Scenes.Count)
            );

            var prototype = new Entity() { Name = "Prototype" };
            game.AddPrototype(prototype);

            CommandHelper.TestUndoableCommand(
                () => Assert.AreEqual(1, game.Prototypes.Count),
                () => game.RemoveItemCommand.Execute(prototype),
                () => Assert.AreEqual(0, game.Prototypes.Count)
            );
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:21,代码来源:CommandTests.cs

示例11: CannotRenameToDuplicateNameInSameScope

        public void CannotRenameToDuplicateNameInSameScope()
        {
            Game game = new Game("Test Game");
            game.AddPrototype(new Entity() { Name = "TestEntity" });

            Scene scene = new Scene("Test Scene");

            Entity entity = new Entity() { Name = "TestEntity2" };
            scene.AddEntity(entity);

            game.AddScene(scene);

            entity.Name = "TestEntity";

            Assert.AreEqual(1, scene.Entities.Count);
            Assert.AreEqual("TestEntity2", entity.Name);
        }
开发者ID:kinectitude,项目名称:kinectitude,代码行数:17,代码来源:EntityTests.cs


注:本文中的Game.AddPrototype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。