private bool RunSimpleTestSingleHeroGroup() { MonsterMatcher matcher = new MonsterMatcher(1, new Random(DateTime.Now.Millisecond)); IEntityManager entityMgr = (IEntityManager)matcher; entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(1))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(1))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(2))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(4))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(8))); var heroList = new List <IEntityTemplate>() { new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(2)), new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(3)), new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(4)) }; var heroGroup = new EntiyGroupTemplate(heroList); IEnemyGroupMaker maker = (IEnemyGroupMaker)matcher; EntiyGroupTemplate mob = new EntiyGroupTemplate(maker.MakeEnemyGroup(heroGroup)); int mobRating = mob.GetThreat(heroGroup); int heroRatingMax = heroGroup.GetThreat(mob) + 1; return(mobRating <= heroRatingMax); }
public override void Add() { try { Console.WriteLine("Create medicament :"); var name = EnterProperty <string>("name"); var description = EnterProperty <string>("description"); var price = EnterProperty <decimal>("price"); var serialNumber = EnterProperty <string>("serialNumber(000-000-00)"); var medicament = new Medicament() { Name = name, Description = description, Price = price, SerialNumber = serialNumber }; _medicamentManager.Add(medicament); var medicamentPriceHistory = new MedicamentPriceHistory() { Price = medicament.Price, ModifiedDate = DateTime.Now, Medicament = medicament }; _medicamentPriceHistoryManager.Add(medicamentPriceHistory); } catch (Exception) { Console.WriteLine("Invalid input!"); } }
public override void Add() { try { Console.WriteLine("Create pharmacy :"); var address = EnterProperty <string>("address"); var number = EnterProperty <int>("number"); var phone = EnterProperty <string>("phone"); var openDate = EnterProperty <DateTime>("openDate"); var pharmacy = new Core.Pharmacy() { Address = address, Number = number, Phone = phone, OpenDate = openDate }; _manager.Add(pharmacy); } catch (Exception) { Console.WriteLine("Invalid input!"); } }
public override void Add() { try { Console.WriteLine("Create storage :"); var pharmacy = GetEntity <Core.Pharmacy>(); if (pharmacy == null) { return; } var medicament = GetEntity <Medicament>(); if (medicament == null) { return; } var quantity = EnterProperty <int>("quantity"); var storage = new Storage() { Pharmacy = pharmacy, Medicament = medicament, Quantity = quantity }; _manager.Add(storage); } catch (Exception) { Console.WriteLine("Invalid input!"); } }
private bool RunSimpleTestSingleMajorHero() { TraitManager traitManager = CreateTraitManager(); ITrait fire = traitManager.GetTraitByName("fire"); ITrait water = traitManager.GetTraitByName("water"); ITrait earth = traitManager.GetTraitByName("earth"); ITrait air = traitManager.GetTraitByName("air"); MonsterMatcher matcher = new MonsterMatcher(2, new Random(1), traitManager); IEntityManager entityMgr = (IEntityManager)matcher; entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(1, new List <ITrait>() { }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(1, new List <ITrait>() { water, fire }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(2, new List <ITrait>() { air }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(3, new List <ITrait>() { water }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(4, new List <ITrait>() { fire }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(5, new List <ITrait>() { earth, fire }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(6, new List <ITrait>() { water, water }))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(7, new List <ITrait>() { air, fire }))); var hero = new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(10, new List <ITrait>() { water })); IEnemyGroupMaker maker = (IEnemyGroupMaker)matcher; var group = maker.MakeEnemyGroup(hero); return(group.Count > 0); }
// // tests // private bool RunSimpleTestSingleHero() { MonsterMatcher matcher = new MonsterMatcher(1, new Random(DateTime.Now.Millisecond)); IEntityManager entityMgr = (IEntityManager)matcher; entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(1))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(1))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(2))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(4))); entityMgr.Add(new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Monster), new EntityRating(8))); var hero = new EntityTemplate(new EntityFaction(EntityFaction.FactionKind.Hero), new EntityRating(2)); IEnemyGroupMaker maker = (IEnemyGroupMaker)matcher; var group = maker.MakeEnemyGroup(hero); return(group.Count > 0); }
public void InitializeScene(IEntityManager entityStore, Game game) { Entity musicEntity = new Entity(); MusicComponent music = new MusicComponent(); music.music = game.Content.Load<Song>("sound/gameMusic"); music.repeat = true; musicEntity.AddComponent(music); entityStore.Add(musicEntity); }
public ActionResult Create(PharmacyViewModel pharmacyViewModel) { if (!ModelState.IsValid) { return(View()); } var pharmacy = Mapper.Map <PharmacyViewModel, Pharmacy.Core.Pharmacy>(pharmacyViewModel); _manager.Add(pharmacy); return(RedirectToAction("Index")); }
private void generateStar(IEntityManager entityStore, Game game, Texture2D bigStarTex, Texture2D littleStarTex, Frustum generationVolume, double speedAtUnitDepth, double screenDepth, double screenWidth, double screenHeight) { //sample a 3d location for the star Vector3 starLoc = generationVolume.samplePoint(rand); //determine the speed as a function of the depth double speed = speedAtUnitDepth / starLoc.Z * screenDepth * screenDepth; //determine the depth/speed of the star Entity star = new Entity(); //Component: Has a position, determined by starLoc PositionComponent pos = new PositionComponent(); Vector3 starLoc2 = generationVolume.TransformFromEuclideanSpaceToPseudoSphericalSpace(starLoc); pos.Position = new Vector2(starLoc2.X * game.GraphicsDevice.Viewport.Width, starLoc2.Y * game.GraphicsDevice.Viewport.Height); star.AddComponent(pos); //Component: Moves at a constant speed LinearMovementComponent movementStrat = new LinearMovementComponent(); star.AddComponent(movementStrat); //Component: Has a move speed MoveSpeedComponent speedComponent = new MoveSpeedComponent(); speedComponent.MoveSpeed = (float)speed; star.AddComponent(speedComponent); //Component: Wraps around the screen ScreenWrappingComponent wrapper = new ScreenWrappingComponent(); star.AddComponent(wrapper); //Component: Has a texture. This should be little star for far away/slow stars, big otherwise TextureComponent tex = new TextureComponent(); tex.Texture = (speed > -2.5) ? littleStarTex : bigStarTex; tex.SourceRect = tex.Texture.Bounds; star.AddComponent(tex); //Component: Has a bounding box AABBComponent aabb = new AABBComponent(); aabb.Width = tex.Texture.Width; aabb.Height = tex.Texture.Height; star.AddComponent(aabb); //Component: Is rendered at a specific layer (just above the background) RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 1; star.AddComponent(layer); entityStore.Add(star); }
public ActionResult Create(CreateOrderViewModel createOrderViewModel) { if (!ModelState.IsValid) { var tempCreateOrderViewModel = _builder.BuildCreateOrderViewModel(); createOrderViewModel.Pharmacies = tempCreateOrderViewModel.Pharmacies; return(View(createOrderViewModel)); } var order = Mapper.Map <CreateOrderViewModel, Order>(createOrderViewModel); order.Date = DateTime.Now; _manager.Add(order); return(RedirectToAction("Index")); }
public ActionResult Create(CreateStorageViewModel createStorageViewModel) { if (!ModelState.IsValid) { var tempCreateStorageViewModel = _builder.BuildCreateStorageViewModel(); createStorageViewModel.Pharmacies = tempCreateStorageViewModel.Pharmacies; createStorageViewModel.Medicaments = tempCreateStorageViewModel.Medicaments; return(View(createStorageViewModel)); } var storage = Mapper.Map <CreateStorageViewModel, Storage>(createStorageViewModel); _manager.Add(storage); return(RedirectToAction("Index")); }
public ActionResult Create(CreateOrderDetailsViewModel createOrderDetailsViewModel) { if (!ModelState.IsValid) { var tempCreateOrderDetailsViewModel = _builder.BuildCreateOrderDetailsViewModel(); createOrderDetailsViewModel.Orders = tempCreateOrderDetailsViewModel.Orders; createOrderDetailsViewModel.Medicaments = tempCreateOrderDetailsViewModel.Medicaments; return(View(createOrderDetailsViewModel)); } var orderDetails = Mapper.Map <CreateOrderDetailsViewModel, OrderDetails>(createOrderDetailsViewModel); _manager.Add(orderDetails); return(RedirectToAction("Index")); }
public override void Add() { try { Console.WriteLine("Create order :"); var date = EnterProperty <DateTime>("date"); Console.Write("type(1 or 2) : "); var t = Console.ReadKey().KeyChar; if (t != '1' && t != '2') { return; } OperationType type; Enum.TryParse(t.ToString(), out type); var pharmacy = GetEntity <Core.Pharmacy>(); if (pharmacy == null) { return; } var order = new Order() { Date = date, Type = type, Pharmacy = pharmacy }; _manager.Add(order); } catch (Exception) { Console.WriteLine("Invalid input"); } }
//Note: timerPhaseAngle is expected to be in the interval [0, 1] private void createPlayerGun(IEntityManager entityStore, Entity player, Entity bullet, float offsetProportion, float timerPhaseAngle) { //compute the gun's offset from the player, then create the gun AABBComponent bulletBox = (AABBComponent)bullet.components[typeof(AABBComponent)]; AABBComponent playerBox = (AABBComponent)player.components[typeof(AABBComponent)]; Entity gun = createPositionSlavedEntity(player, new Vector2(playerBox.Width + 0.1f, playerBox.Height * offsetProportion - bulletBox.Height / 2.0f)); //The gun now has a position coupled to that of the player //So spawn bullets at the gun! SpawnEntityComponent spawner = new SpawnEntityComponent(); spawner.Factory = new ComposedEntityFactory(new List<IEntityFactory>() { new CloneEntityFactory(bullet), new InheritParentComponentEntityFactory(typeof(PositionComponent)) }); //Bullets should be spawned periodically PeriodicAddComponentComponent timer = new PeriodicAddComponentComponent(); timer.Period = 200.0f; timer.TimeSinceLastFiring = timer.Period * timerPhaseAngle; timer.ComponentToAdd = spawner; gun.AddComponent(timer); //The gun should be removed from the world when the player dies DestroyedOnParentDestroyedComponent existentialDependency = new DestroyedOnParentDestroyedComponent(); existentialDependency.parent = player; gun.AddComponent(existentialDependency); //finally, add the gun to the world entityStore.Add(gun); }
private void initializePurpleBackground(IEntityManager entityStore, Game game) { Entity bg = new Entity(); //Component: Has a position PositionComponent pos = new PositionComponent(); pos.Position = new Vector2(0, 0); bg.AddComponent(pos); //Component: Has an AABB AABBComponent aabb = new AABBComponent(); aabb.Width = game.GraphicsDevice.Viewport.Width; aabb.Height = game.GraphicsDevice.Viewport.Height; bg.AddComponent(aabb); //Component: Has a texture TextureComponent tex = new TextureComponent(); tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/Background/backgroundColor"); tex.SourceRect = tex.Texture.Bounds; bg.AddComponent(tex); //Component: Is rendered at a specific layer (the backmost one!) RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 0; bg.AddComponent(layer); entityStore.Add(bg); }
public Auction CreateAuction(Auction auction) { return(_entityManager.Add <Auction, Bl.Auction>(auction)); }
//Create the player entity and its associated entities private void initializePlayer(IEntityManager entityStore, Game game) { Entity player = new Entity(); //give the player health HealthComponent hp = new HealthComponent(); hp.Health = 100; player.AddComponent(hp); //Give the player a position PositionComponent pos = new PositionComponent(); Vector2 playerPosition = new Vector2(game.GraphicsDevice.Viewport.TitleSafeArea.X, game.GraphicsDevice.Viewport.TitleSafeArea.Y + game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); pos.Position = playerPosition; player.AddComponent(pos); //And a texture TextureComponent tex = new TextureComponent(); tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/player"); tex.SourceRect = tex.Texture.Bounds; player.AddComponent(tex); //And the ability to react to inputs PlayerMovementComponent inputManager = new PlayerMovementComponent(); player.AddComponent(inputManager); //And a constant movement speed MoveSpeedComponent speed = new MoveSpeedComponent(); speed.MoveSpeed = 8.0f; player.AddComponent(speed); //And a bounding box for clamping (and collisions in the future!) AABBComponent aabb = new AABBComponent(); aabb.Width = tex.Texture.Width; aabb.Height = tex.Texture.Height; player.AddComponent(aabb); //And render layer information. We'll have the player render at level 10 for now. RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 10; player.AddComponent(layer); //And a component to indicate the the player needs to be clamped to the screen ScreenClampedComponent clamper = new ScreenClampedComponent(); player.AddComponent(clamper); //And a component that indicates that the player can be destroyed if it runs out of health DestroyedWhenNoHealthComponent destruct = new DestroyedWhenNoHealthComponent(); player.AddComponent(destruct); //And the ability to damage entities on contact with them DamageOnContactComponent damager = new DamageOnContactComponent(); damager.Damage = 10; player.AddComponent(damager); entityStore.Add(player); //also create the player's gun initializePlayerGuns(entityStore, game, player); }
private void initializeMinefield(IEntityManager entityStore, Game game) { //Create a mine-spawning entity that spawns mines in random positions every once in a while Entity minespawner = new Entity(); //Component: Spawn an entity SpawnEntityComponent spawnComponent = new SpawnEntityComponent(); spawnComponent.Factory = createAsteroidFactory(game); //Component: Periodically add a spawn entity component PeriodicAddComponentComponent timer = new PeriodicAddComponentComponent(); timer.ComponentToAdd = spawnComponent; timer.Period = 500; timer.TimeSinceLastFiring = 0.0f; minespawner.AddComponent(timer); //Add the minefield to the entity store entityStore.Add(minespawner); }
public override void Add() { try { Console.WriteLine("Create orderDetail :"); var order = GetEntity <Order>(); if (order == null) { return; } var medicament = GetEntity <Medicament>(); if (medicament == null) { return; } var quantity = EnterProperty <int>("quantity"); var orderDetail = new OrderDetails() { Order = order, Medicament = medicament, Quantity = quantity, Price = medicament.Price }; if (_storageManager.GetByPrimaryKey(order.PharmacyId, medicament.Id) == null) { _storageManager.Add(new Storage() { Medicament = medicament, Pharmacy = order.Pharmacy, Quantity = 0 }); } if (order.Type == OperationType.Sale) { if (_storageManager.GetByPrimaryKey(order.PharmacyId, medicament.Id).Quantity < orderDetail.Quantity) { return; } _storageManager.GetByPrimaryKey(order.PharmacyId, medicament.Id).Quantity -= orderDetail.Quantity; } else { _storageManager.GetByPrimaryKey(order.PharmacyId, medicament.Id).Quantity += orderDetail.Quantity; } _orderDetailsManager.Add(orderDetail); } catch (Exception) { Console.WriteLine("Invalid input!"); } }
public void TreeScan(string sDir) { foreach (string f in Directory.GetFiles(sDir)) { using (var session = driver.Session()) { soundFileManager = new SoundFileManager(session); try { SoundFile sf = null; TagLib.File file = null; Console.WriteLine("Processing " + f); file = TagLib.File.Create(f); double length = file.Properties.Duration.TotalSeconds; sf = new SoundFile() { Title = file.Tag.Title, Filename = f, Directory = sDir, Comment = file.Tag.Comment, Rating = 0, Filesize = "", Year = (int)file.Tag.Year, Genre = file.Tag.JoinedGenres, Lyrics = file.Tag.Lyrics, Album = file.Tag.Album, Artist = file.Tag.JoinedAlbumArtists, Duration = (int)length, Mime = file.MimeType }; if (file.Tag.Pictures.Any()) { var artwork = file.Tag.Pictures.First(); using (MemoryStream m = new MemoryStream()) { byte[] imageBytes = artwork.Data.Data; // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); sf.Artwork = base64String; imageBytes = null; } } soundFileManager.Add(sf); file = null; sf = null; } catch (Exception uex) { continue; //todo - log and give report } } } foreach (string d in Directory.GetDirectories(sDir)) { TreeScan(d); } }