本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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
//.........这里部分代码省略.........
示例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;
}
示例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");
}
示例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);
}
示例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);
}
示例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" ));
}
示例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)
);
}
示例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);
}