// DELETE api/Leafletapi/5 public void Delete(int id) { Leaflet Leaflet = _db.Leaflets.Find(id); _db.Leaflets.Remove(Leaflet); _db.SaveChanges(); }
private MedicineLeafletViewModel GetLeafletViewModel([NotNull] Leaflet leaflet) { if (leaflet == null) { throw new ArgumentNullException("leaflet"); } Func <string, bool> canLeafletBeVisualized = url => url.ToLower().EndsWith(".pdf") || url.ToLower().EndsWith(".doc") || url.ToLower().EndsWith(".docx") || url.ToLower().EndsWith(".txt"); return(new MedicineLeafletViewModel() { Id = leaflet.Id, Description = leaflet.Description, Url = leaflet.Url, MedicineId = leaflet.Medicines.First().Id, MedicineName = leaflet.Medicines.First().Name, ViewerUrl = canLeafletBeVisualized(leaflet.Url) ? Url.Action("ViewLeaflet", new { id = leaflet.Id }) : null, GoogleDocsUrl = canLeafletBeVisualized(leaflet.Url) ? string.Format("http://docs.google.com/viewer?url={0}", leaflet.Url) : null, GoogleDocsEmbeddedUrl = canLeafletBeVisualized(leaflet.Url) ? string.Format("http://docs.google.com/viewer?embedded=true&url={0}", leaflet.Url) : null, }); }
public void updateLeaflet(int n, Leaflet l) { switch (n) { case 0: leaflet1[0] = l.getRequired("Red"); leaflet1[1] = l.getRequired("Green"); leaflet1[2] = l.getRequired("Blue"); leaflet1[3] = l.getRequired("Yellow"); leaflet1[4] = l.getRequired("Magenta"); leaflet1[5] = l.getRequired("White"); break; case 1: leaflet2[0] = l.getRequired("Red"); leaflet2[1] = l.getRequired("Green"); leaflet2[2] = l.getRequired("Blue"); leaflet2[3] = l.getRequired("Yellow"); leaflet2[4] = l.getRequired("Magenta"); leaflet2[5] = l.getRequired("White"); break; case 2: leaflet3[0] = l.getRequired("Red"); leaflet3[1] = l.getRequired("Green"); leaflet3[2] = l.getRequired("Blue"); leaflet3[3] = l.getRequired("Yellow"); leaflet3[4] = l.getRequired("Magenta"); leaflet3[5] = l.getRequired("White"); break; default: break; } }
protected bool Equals(Leaflet other) { return(string.Equals(RawContent, other.RawContent) && string.Equals(SideEffects, other.SideEffects) && string.Equals(Information, other.Information) && string.Equals(Posology, other.Posology) && string.Equals(Description, other.Description)); }
public ActionResult Delete(int id) { Leaflet Leaflet = _db.Leaflets.Find(id); _db.Leaflets.Remove(Leaflet); _db.SaveChanges(); return(RedirectToAction("List")); }
private bool leafletNeedsJewel(Leaflet l, Thing jewel) { LeafletItem li = l.items.Where(item => (item.itemKey == jewel.Material.Color)).FirstOrDefault(); if (li == null) { return(false); } return(li.collected < li.totalNumber); }
//can make a prefab, with itemtype as a fillin, //then do a switch statement to add the right type? //private string itemType = "Leaflet"; private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { //print("Colliding"); Leaflet leaflet = (Leaflet)Instantiate(InventoryScript.MyInstance.items[1]); InventoryScript.MyInstance.AddItem(leaflet); //remove item from world... destroy script? Destroy(gameObject); } }
// PUT api/Leafletapi/5 public void Put(int id, [FromBody] string json) { Leaflet model = Json.Decode <Leaflet>(json); Leaflet leaflet = _db.Leaflets.Find(id); leaflet.LeafletTitle = model.LeafletTitle; leaflet.Content = model.Content; leaflet.Colour = model.Colour; leaflet.Width = model.Width; leaflet.Height = model.Height; this._db.SaveChanges(); }
public ActionResult EditPost(int id) { Leaflet leaflet = _db.Leaflets.Find(id); if (TryUpdateModel(leaflet, "", new string[] { "LeafletTitle", "Content", "Colour", "Width", "Height" })) { this._db.SaveChanges(); TempData["message"] = "Edytowano ulotkę."; return(RedirectToAction("list")); } else { return(View(leaflet)); } }
public void updateLeaflet(int n, Leaflet l) { switch (n) { case 0: leaflet1[0] = l.getRequired("Red") - l.getCollected("Red"); leaflet1[1] = l.getRequired("Green") - l.getCollected("Green"); leaflet1[2] = l.getRequired("Blue") - l.getCollected("Blue"); leaflet1[3] = l.getRequired("Yellow") - l.getCollected("Red"); leaflet1[4] = l.getRequired("Magenta") - l.getCollected("Magenta"); leaflet1[5] = l.getRequired("White") - l.getCollected("White"); break; case 1: leaflet2[0] = l.getRequired("Red") - l.getCollected("Red"); leaflet2[1] = l.getRequired("Green") - l.getCollected("Green"); leaflet2[2] = l.getRequired("Blue") - l.getCollected("Blue"); leaflet2[3] = l.getRequired("Yellow") - l.getCollected("Red"); leaflet2[4] = l.getRequired("Magenta") - l.getCollected("Magenta"); leaflet2[5] = l.getRequired("White") - l.getCollected("White"); break; case 2: leaflet3[0] = l.getRequired("Red") - l.getCollected("Red"); leaflet3[1] = l.getRequired("Green") - l.getCollected("Green"); leaflet3[2] = l.getRequired("Blue") - l.getCollected("Blue"); leaflet3[3] = l.getRequired("Yellow") - l.getCollected("Red"); leaflet3[4] = l.getRequired("Magenta") - l.getCollected("Magenta"); leaflet3[5] = l.getRequired("White") - l.getCollected("White"); break; default: break; } // FMT verifying negatives for (int i = 0; i < 5; i++) { if (leaflet1[i] < 0) { leaflet1[i] = 0; } if (leaflet2[i] < 0) { leaflet2[i] = 0; } if (leaflet3[i] < 0) { leaflet3[i] = 0; } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { //check for each item available and add. //there must be a more efficient way, but I haven't //thought of it. //print("Colliding"); if (itemType == "Leaflet") { Leaflet leaflet = (Leaflet)Instantiate(InventoryScript.MyInstance.items[1]); InventoryScript.MyInstance.AddItem(leaflet); } //continue with other objects, sword, sack etc... //remove item from world... destroy script? Destroy(gameObject); } }
// POST api/Leafletapi public HttpResponseMessage Post([FromBody] string json) { Leaflet model = Json.Decode <Leaflet>(json); if (ModelState.IsValid) { this._db.Leaflets.Add(model); this._db.SaveChanges(); var response = Request.CreateResponse <Leaflet>(HttpStatusCode.Created, model); string url = Url.Route(null, new { id = model.Id }); response.Headers.Location = new Uri(Request.RequestUri, url); return(response); } else { var response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); return(response); } }
public void loadLeaflet(Leaflet lf1, Leaflet lf2, Leaflet lf3) { //Console.WriteLine ("Load leaflet"); foreach (LeafletItem li in lf1.items) { for (int i = 0; i < leafletMap.Length; i++) { //Console.WriteLine ("map: " + leafletMap [i]); if (leafletMap [i] == li.itemKey) { leaflet1_t [i] += li.totalNumber; //Console.WriteLine ("Mind - Load added lf1: " + li.itemKey); } } } foreach (LeafletItem li in lf2.items) { for (int i = 0; i < leafletMap.Length; i++) { //Console.WriteLine ("map: " + leafletMap [i]); if (leafletMap [i] == li.itemKey) { leaflet2_t [i] += li.totalNumber; //Console.WriteLine ("Mind - Load added lf2: " + li.itemKey); } } } foreach (LeafletItem li in lf3.items) { for (int i = 0; i < leafletMap.Length; i++) { //Console.WriteLine ("map: " + leafletMap [i]); if (leafletMap [i] == li.itemKey) { leaflet3_t [i] += li.totalNumber; //Console.WriteLine ("Mind - Load added lf3: " + li.itemKey); } } } }
//debug private void Update() { if (Input.GetKeyDown(KeyCode.L)) { //could I call this on collision? /* * Bag bag = (Bag)Instantiate(items[0]); * bag.Initialize(16); * bag.Use();*/ Leaflet leaflet = (Leaflet)Instantiate(items[1]); AddItem(leaflet); } if (Input.GetKeyDown(KeyCode.K)) { Bag bag = (Bag)Instantiate(items[0]); //print(bag); bag.Initialize(16); AddItem(bag); } }
public ActionResult Add(Leaflet model) { if (ModelState.IsValid) { this._db.Leaflets.Add(model); try { this._db.SaveChanges(); TempData["message"] = "Dodano ulotkę."; return(RedirectToAction("list")); } catch (Exception ex) { TempData["message"] = "Nie dodano ulotki - prawdopodobnie produkt o podanym ID nie istnieje"; return(View(model)); } } else { return(View(model)); } }
private void processLeafletControl() { // Update Visual Leaflet data // // Prepare leaflet list Leaflet leaflet1 = new Leaflet(); leaflet1.items = new List <LeafletItem>(); leaflet1.items.Add(new LeafletItem("Red", 1 - leafletRemainingJewelRed, 0)); leaflet1.items.Add(new LeafletItem("Green", 0, 0)); leaflet1.items.Add(new LeafletItem("Blue", 0, 0)); leaflet1.items.Add(new LeafletItem("Yellow", 0, 0)); leaflet1.items.Add(new LeafletItem("Magenta", 0, 0)); leaflet1.items.Add(new LeafletItem("White", 2 - leafletRemainingJewelWhite, 0)); Leaflet leaflet2 = new Leaflet(); leaflet2.items = new List <LeafletItem>(); leaflet2.items.Add(new LeafletItem("Red", 0, 0)); leaflet2.items.Add(new LeafletItem("Green", 0, 0)); leaflet2.items.Add(new LeafletItem("Blue", 2 - leafletRemainingJewelBlue, 0)); leaflet2.items.Add(new LeafletItem("Yellow", 1 - leafletRemainingJewelYellow, 0)); leaflet2.items.Add(new LeafletItem("Magenta", 0, 0)); leaflet2.items.Add(new LeafletItem("White", 0, 0)); Leaflet leaflet3 = new Leaflet(); leaflet3.items = new List <LeafletItem>(); leaflet3.items.Add(new LeafletItem("Red", 0, 0)); leaflet3.items.Add(new LeafletItem("Green", 1 - leafletRemainingJewelGreen, 0)); leaflet3.items.Add(new LeafletItem("Blue", 0, 0)); leaflet3.items.Add(new LeafletItem("Yellow", 0, 0)); leaflet3.items.Add(new LeafletItem("Magenta", 2 - leafletRemainingJewelMagenta, 0)); leaflet3.items.Add(new LeafletItem("White", 0, 0)); // Update leaflets to be showed in UI view mind.updateLeaflet(0, leaflet1); mind.updateLeaflet(1, leaflet2); mind.updateLeaflet(2, leaflet3); }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { //check for each item available and add. //itemtype references the item array found under the inventoryScript //gameobject. //check if full so we can add the items if (InventoryScript.MyInstance.MyEmptySlotCount > 0) { if (itemType == "Leaflet") { Leaflet leaflet = (Leaflet)Instantiate(InventoryScript.MyInstance.items[1]); InventoryScript.MyInstance.AddItem(leaflet); } else if (itemType == "Egg") { Egg egg = (Egg)Instantiate(InventoryScript.MyInstance.items[2]); InventoryScript.MyInstance.AddItem(egg); } else if (itemType == "Sword") { Sword sword = (Sword)Instantiate(InventoryScript.MyInstance.items[3]); InventoryScript.MyInstance.AddItem(sword); } else if (itemType == "Trident") { Trident trident = (Trident)Instantiate(InventoryScript.MyInstance.items[4]); InventoryScript.MyInstance.AddItem(trident); } else if (itemType == "Airpump") { AirPump ap = (AirPump)Instantiate(InventoryScript.MyInstance.items[5]); InventoryScript.MyInstance.AddItem(ap); } else if (itemType == "Bar") { PlatinumBar bar = (PlatinumBar)Instantiate(InventoryScript.MyInstance.items[6]); InventoryScript.MyInstance.AddItem(bar); } else if (itemType == "Knife") { Knife knife = (Knife)Instantiate(InventoryScript.MyInstance.items[7]); InventoryScript.MyInstance.AddItem(knife); } else if (itemType == "Rope") { Rope rope = (Rope)Instantiate(InventoryScript.MyInstance.items[8]); InventoryScript.MyInstance.AddItem(rope); } else if (itemType == "Skull") { Skull skull = (Skull)Instantiate(InventoryScript.MyInstance.items[9]); InventoryScript.MyInstance.AddItem(skull); } else if (itemType == "Sack") { Sack sack = (Sack)Instantiate(InventoryScript.MyInstance.items[10]); InventoryScript.MyInstance.AddItem(sack); } else if (itemType == "Lantern") { Lantern lantern = (Lantern)Instantiate(InventoryScript.MyInstance.items[11]); InventoryScript.MyInstance.AddItem(lantern); } else if (itemType == "Bottle") { Bottle bottle = (Bottle)Instantiate(InventoryScript.MyInstance.items[12]); InventoryScript.MyInstance.AddItem(bottle); } else if (itemType == "Candle") { Candle candle = (Candle)Instantiate(InventoryScript.MyInstance.items[13]); InventoryScript.MyInstance.AddItem(candle); } else if (itemType == "BlackBook") { BlkBook book = (BlkBook)Instantiate(InventoryScript.MyInstance.items[14]); InventoryScript.MyInstance.AddItem(book); } else if (itemType == "PlasticPile") { PlasticPile plastic = (PlasticPile)Instantiate(InventoryScript.MyInstance.items[15]); InventoryScript.MyInstance.AddItem(plastic); } else if (itemType == "Buoy") { Buoy buoy = (Buoy)Instantiate(InventoryScript.MyInstance.items[16]); InventoryScript.MyInstance.AddItem(buoy); } else if (itemType == "Shovel") { Shovel shovel = (Shovel)Instantiate(InventoryScript.MyInstance.items[17]); InventoryScript.MyInstance.AddItem(shovel); } else if (itemType == "Scarab") { Scarab scarab = (Scarab)Instantiate(InventoryScript.MyInstance.items[18]); InventoryScript.MyInstance.AddItem(scarab); } else if (itemType == "PotOfGold") { PotOfGold gold = (PotOfGold)Instantiate(InventoryScript.MyInstance.items[19]); InventoryScript.MyInstance.AddItem(gold); } else if (itemType == "Bracelet") { Bracelet bracelet = (Bracelet)Instantiate(InventoryScript.MyInstance.items[20]); InventoryScript.MyInstance.AddItem(bracelet); } else if (itemType == "Coal") { Coal coal = (Coal)Instantiate(InventoryScript.MyInstance.items[21]); InventoryScript.MyInstance.AddItem(coal); } else if (itemType == "Figurine") { Figurine fig = (Figurine)Instantiate(InventoryScript.MyInstance.items[22]); InventoryScript.MyInstance.AddItem(fig); } else if (itemType == "Diamond") { Diamond diamond = (Diamond)Instantiate(InventoryScript.MyInstance.items[23]); InventoryScript.MyInstance.AddItem(diamond); } else if (itemType == "Torch") { Torch torch = (Torch)Instantiate(InventoryScript.MyInstance.items[24]); InventoryScript.MyInstance.AddItem(torch); } else if (itemType == "Coins") { Coins coins = (Coins)Instantiate(InventoryScript.MyInstance.items[25]); InventoryScript.MyInstance.AddItem(coins); } else if (itemType == "Key") { Key key = (Key)Instantiate(InventoryScript.MyInstance.items[26]); InventoryScript.MyInstance.AddItem(key); } else if (itemType == "Matches") { Matches matches = (Matches)Instantiate(InventoryScript.MyInstance.items[27]); InventoryScript.MyInstance.AddItem(matches); } else if (itemType == "Wrench") { Wrench wrench = (Wrench)Instantiate(InventoryScript.MyInstance.items[28]); InventoryScript.MyInstance.AddItem(wrench); } else if (itemType == "Screwdriver") { Screwdriver sd = (Screwdriver)Instantiate(InventoryScript.MyInstance.items[29]); InventoryScript.MyInstance.AddItem(sd); } else if (itemType == "Jewels") { Jewels jewels = (Jewels)Instantiate(InventoryScript.MyInstance.items[30]); InventoryScript.MyInstance.AddItem(jewels); } else if (itemType == "Coffin") { Coffin coffin = (Coffin)Instantiate(InventoryScript.MyInstance.items[31]); InventoryScript.MyInstance.AddItem(coffin); } else if (itemType == "Chalice") { Chalice chalice = (Chalice)Instantiate(InventoryScript.MyInstance.items[32]); InventoryScript.MyInstance.AddItem(chalice); } //the following items should not be displayed in the world //but going to add just in case we revamp how these items //are obtained. else if(itemType == "Garlic") { Garlic garlic = (Garlic)Instantiate(InventoryScript.MyInstance.items[33]); InventoryScript.MyInstance.AddItem(garlic); } else if(itemType == "Sceptre") { Sceptre sep = (Sceptre)Instantiate(InventoryScript.MyInstance.items[34]); InventoryScript.MyInstance.AddItem(sep); } Destroy(gameObject); } //probably want to utilize CLI popup here else { Debug.Log("Bag full"); } } }
public MainClass(string [] args) { Application.Init(); Console.WriteLine("IA941 - Clarion - Activity"); try { ws = new WSProxy("localhost", 4011); String message = ws.Connect(); if (ws != null && ws.IsConnected) { Console.Out.WriteLine("[SUCCESS] " + message + "\n"); if (args.Length > 1) { if (args [1] == "reset") { ws.SendWorldReset(); } } else { ws.SendWorldReset(); } ws.NewCreature(100, 500, 0, out creatureId, out creatureName); // Start >>> Leaflet process preparation // String leaflets_raw = ws.SendCreateLeaflet(); string [] leaflets_arr = leaflets_raw.Split(' '); //Console.WriteLine ("Leaflets: " + leaflets_raw); Leaflet leaflet1 = new Leaflet(); leaflet1.items = new List <LeafletItem> (); Leaflet leaflet2 = new Leaflet(); leaflet2.items = new List <LeafletItem> (); Leaflet leaflet3 = new Leaflet(); leaflet3.items = new List <LeafletItem> (); int leafNum = 1; int lf1T = 0; int lf2T = 0; int lf3T = 0; for (int i = 0; i < leaflets_arr.Length; i++) { if (leaflets_arr [i] != "") { if (leaflets_arr [i] == "false") { leafNum++; } else if (leaflets_arr [i].Length > 3) { switch (leafNum) { case 1: leaflet1.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0)); lf1T = lf1T + Int32.Parse(leaflets_arr [i + 2]); i = i + 2; break; case 2: leaflet2.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0)); lf2T = lf2T + Int32.Parse(leaflets_arr [i + 2]); i = i + 2; break; case 3: leaflet3.items.Add(new LeafletItem(leaflets_arr [i], Int32.Parse(leaflets_arr [i + 2]), 0)); lf3T = lf3T + Int32.Parse(leaflets_arr [i + 2]); i = i + 2; break; default: break; } } } } //Console.WriteLine ("Leaflet 1 items: "); //foreach(LeafletItem lt in leaflet1.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} //Console.WriteLine ("Leaflet 2 items: "); //foreach (LeafletItem lt in leaflet2.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} //Console.WriteLine ("Leaflet 3 items: "); //foreach (LeafletItem lt in leaflet3.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} // In case the leaflets sum have less than 9 jewels, then add remaining int remJewels = 9 - (lf1T + lf2T + lf3T); //Console.WriteLine ("Rem Jewels: " + remJewels); //Console.WriteLine ("count lf1: " + leaflet1.items.Count); if (remJewels > 0) { for (int i = 0; i < remJewels; i++) { if (lf1T < 3) { leaflet1.items.Add(new LeafletItem("Red", 1, 0)); lf1T++; //Console.WriteLine ("Added rem Jewel - Leaflet 1"); } else if (lf2T < 3) { leaflet2.items.Add(new LeafletItem("Red", 1, 0)); lf2T++; //Console.WriteLine ("Added rem Jewel - Leaflet 2"); } else if (lf3T < 3) { leaflet3.items.Add(new LeafletItem("Red", 1, 0)); lf3T++; //Console.WriteLine ("Added rem Jewel - Leaflet 3"); } } } //Console.WriteLine ("Double check: "); //Console.WriteLine ("Leaflet 1 items: "); //foreach (LeafletItem lt in leaflet1.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} //Console.WriteLine ("Leaflet 2 items: "); //foreach (LeafletItem lt in leaflet2.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} //Console.WriteLine ("Leaflet 3 items: "); //foreach (LeafletItem lt in leaflet3.items) { // Console.WriteLine ("Jewel: " + lt.itemKey); // Console.WriteLine ("Total: " + lt.totalNumber); //} // End >>> Leaflet process preparation // ws.SendNewWayPoint(700, 500); if (args.Length > 1) { if (args [3] == "grow") { //ws.NewBrick (4, 747, 2, 800, 567); //ws.NewBrick (4, 50, -4, 747, 47); //ws.NewBrick (4, 49, 562, 796, 599); //ws.NewBrick (4, -2, 6, 50, 599); Random x = new Random(); Random y = new Random(); Random z = new Random(); int minX = 100; int maxX = 600; int minY = 100; int maxY = 500; int xNew = 0; int yNew = 0; // Random Jewels for (int j = 0; j < 7; j++) { for (int i = 0; i < 5; i++) { xNew = x.Next(minX, maxX); yNew = y.Next(minY, maxY); if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50))) { x.Next(minX + z.Next(1, 50), maxX); if (i > 0) { i--; } } else { ws.NewJewel(j, xNew, yNew); x.Next(minX + z.Next(1, 50), maxX); } } } // Random food for (int j = 0; j < 2; j++) { for (int i = 0; i < 2; i++) { xNew = x.Next(minX, maxX); yNew = y.Next(minY, maxY); if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440))))) { ws.NewFood(j, xNew, yNew); x.Next(minX + i, maxX); } else { x.Next(minX + i, maxX); if (i > 0) { i--; } } } } } } else { //ws.NewBrick (4, 747, 2, 800, 567); //ws.NewBrick (4, 50, -4, 747, 47); //ws.NewBrick (4, 49, 562, 796, 599); //ws.NewBrick (4, -2, 6, 50, 599); Random x = new Random(); Random y = new Random(); Random z = new Random(); int minX = 100; int maxX = 600; int minY = 100; int maxY = 500; int xNew = 0; int yNew = 0; // Random Jewels for (int j = 0; j < 7; j++) { for (int i = 0; i < 5; i++) { xNew = x.Next(minX, maxX); yNew = y.Next(minY, maxY); if (((mod(xNew, 100) < 50) && (mod(yNew, 100) < 50)) || ((mod(xNew, 100) < 50) && (mod(yNew, 500) < 50))) { x.Next(minX + z.Next(1, 50), maxX); if (i > 0) { i--; } } else { ws.NewJewel(j, xNew, yNew); x.Next(minX + z.Next(1, 50), maxX); } } } // Random food for (int j = 0; j < 2; j++) { for (int i = 0; i < 2; i++) { xNew = x.Next(minX, maxX); yNew = y.Next(minY, maxY); if (!(((xNew > 60) && (xNew < 140)) || (((xNew > 360) && (xNew < 440))))) { ws.NewFood(j, xNew, yNew); x.Next(minX + i, maxX); } else { x.Next(minX + i, maxX); if (i > 0) { i--; } } } } } // ---- Start - Leaflet Generation --- // IList <Thing> response = null; if (ws != null && ws.IsConnected) { response = ws.SendGetCreatureState(creatureName); if (leaflet1.leafletID == 0 && leaflet2.leafletID == 0 && leaflet3.leafletID == 0) { Creature cc = (Creature)response [0]; //leaflet1.leafletID = cc.leaflets [0].leafletID; //leaflet2.leafletID = cc.leaflets [1].leafletID; //leaflet3.leafletID = cc.leaflets [2].leafletID; leaflet1 = cc.leaflets [0]; leaflet2 = cc.leaflets [1]; leaflet3 = cc.leaflets [2]; //Console.WriteLine ("Creature found: " + cc.Name); //Console.WriteLine ("LF1: " + cc.leaflets [0].leafletID); //Console.WriteLine ("LF2: " + cc.leaflets [1].leafletID); //Console.WriteLine ("LF3: " + cc.leaflets [2].leafletID); } } List <Leaflet> leafletList = new List <Leaflet> (); leafletList.Add(leaflet1); leafletList.Add(leaflet2); leafletList.Add(leaflet3); // ---- Finish - Leaflet generation --- // if (!String.IsNullOrWhiteSpace(creatureId)) { ws.SendStartCamera(creatureId); ws.SendStartCreature(creatureId); } if (args.Length > 0) { Console.Out.WriteLine("Sleep time: " + Convert.ToInt32(args [0])); Thread.Sleep(Convert.ToInt32(args [0])); } else { Thread.Sleep(500); } Console.Out.WriteLine("Creature created with name: " + creatureId + "\n"); agent = new ClarionAgent(ws, creatureId, creatureName, leafletList); agent.Run(); Console.Out.WriteLine("Running Simulation ...\n"); } else { Console.Out.WriteLine("The WorldServer3D engine was not found ! You must start WorldServer3D before running this application !"); System.Environment.Exit(1); } } catch (WorldServerInvalidArgument invalidArtgument) { Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message)); } catch (WorldServerConnectionError serverError) { Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message)); } catch (Exception ex) { Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message)); } Application.Run(); }
private void loadLeafletsControl(List <Leaflet> list) { this.leaflet1 = list [0]; this.leaflet2 = list [1]; this.leaflet3 = list [2]; var jewelMap = new Dictionary <string, bool> (); jewelMap.Add("White", false); jewelMap.Add("Red", false); jewelMap.Add("Blue", false); jewelMap.Add("Yellow", false); jewelMap.Add("Magenta", false); jewelMap.Add("Green", false); jewelMap.Add("Orange", false); jewelMap.Add("DarkGray_Spoiled", false); int control = 0; foreach (Leaflet lf in list) { control++; //Console.WriteLine ("Leaflet: " + control); foreach (LeafletItem li in lf.items) { jewelMap [li.itemKey] = true; if (li.itemKey == "White") { leafletRemainingJewelWhite += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Red") { leafletRemainingJewelRed += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Blue") { leafletRemainingJewelBlue += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Yellow") { leafletRemainingJewelYellow += li.totalNumber; Console.WriteLine(li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Magenta") { leafletRemainingJewelMagenta += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Green") { leafletRemainingJewelGreen += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "Orange") { leafletRemainingJewelOrange += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } else if (li.itemKey == "DarkGray_Spoiled") { leafletRemainingJewelDarkGray_Spoiled += li.totalNumber; //Console.WriteLine (li.itemKey + " - " + li.totalNumber); } } } // Defining out of scope jewels foreach (var pair in jewelMap) { if (pair.Value == false) { jewelOutOfScope.Add(pair.Key); //Console.WriteLine ("Jewel out of scope: " + pair.Key); } } }
private Boolean hasToGetJewelForLeaflet(String color, Leaflet leaflet) { return(leaflet.getRequired(color) > leaflet.getCollected(color)); }
private void processLeafletControl(String color) { if (color.Equals("White")) { if (leafletRemainingJewelWhite > 0) { leafletRemainingJewelWhite--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } else if (color.Equals("Red")) { if (leafletRemainingJewelRed > 0) { leafletRemainingJewelRed--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } else if (color.Equals("Blue")) { if (leafletRemainingJewelBlue > 0) { leafletRemainingJewelBlue--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } else if (color.Equals("Yellow")) { if (leafletRemainingJewelYellow > 0) { leafletRemainingJewelYellow--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } else if (color.Equals("Magenta")) { if (leafletRemainingJewelMagenta > 0) { leafletRemainingJewelMagenta--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } else if (color.Equals("Green")) { if (leafletRemainingJewelGreen > 0) { leafletRemainingJewelGreen--; } else if (isDesiredJewel(color)) { jewelOutOfScope.Add(color); } } // Update Visual Leaflet data // // Prepare leaflet list Leaflet leaflet1 = new Leaflet(); leaflet1.items = new List <LeafletItem>(); leaflet1.items.Add(new LeafletItem("Red", 1 - leafletRemainingJewelRed, 0)); leaflet1.items.Add(new LeafletItem("Green", 0, 0)); leaflet1.items.Add(new LeafletItem("Blue", 0, 0)); leaflet1.items.Add(new LeafletItem("Yellow", 0, 0)); leaflet1.items.Add(new LeafletItem("Magenta", 0, 0)); leaflet1.items.Add(new LeafletItem("White", 2 - leafletRemainingJewelWhite, 0)); Leaflet leaflet2 = new Leaflet(); leaflet2.items = new List <LeafletItem>(); leaflet2.items.Add(new LeafletItem("Red", 0, 0)); leaflet2.items.Add(new LeafletItem("Green", 0, 0)); leaflet2.items.Add(new LeafletItem("Blue", 2 - leafletRemainingJewelBlue, 0)); leaflet2.items.Add(new LeafletItem("Yellow", 1 - leafletRemainingJewelYellow, 0)); leaflet2.items.Add(new LeafletItem("Magenta", 0, 0)); leaflet2.items.Add(new LeafletItem("White", 0, 0)); Leaflet leaflet3 = new Leaflet(); leaflet3.items = new List <LeafletItem>(); leaflet3.items.Add(new LeafletItem("Red", 0, 0)); leaflet3.items.Add(new LeafletItem("Green", 1 - leafletRemainingJewelGreen, 0)); leaflet3.items.Add(new LeafletItem("Blue", 0, 0)); leaflet3.items.Add(new LeafletItem("Yellow", 0, 0)); leaflet3.items.Add(new LeafletItem("Magenta", 2 - leafletRemainingJewelMagenta, 0)); leaflet3.items.Add(new LeafletItem("White", 0, 0)); // Update leaflets to be showed in UI view mind.updateLeaflet(0, leaflet1); mind.updateLeaflet(1, leaflet2); mind.updateLeaflet(2, leaflet3); //Console.WriteLine("processLeafletControl: " + color); }
public ActionResult Edit(int id) { Leaflet Leaflet = _db.Leaflets.Find(id); return(View(Leaflet)); }
// GET api/Leafletapi/5 public String Get(int id) { Leaflet Leaflet = _db.Leaflets.Find(id); return(Json.Encode(Leaflet)); }
/// <summary> /// Process the response and parse elements /// </summary> /// <param name="response">The response provided by the server.</param> /// <param name="ignoredTokens">The ignored tokens. They will not be processed.</param> /// <returns>A list of parsed things</returns> private List <Thing> ParseGetCreatureStateResponse(string response, string[] ignoredTokens) { List <Thing> returnValue = null; //Console.WriteLine (response); try { if (!String.IsNullOrWhiteSpace(response)) { string[] tokens = response.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] tokensProcessed = null; // Remove unecessary tokens if (ignoredTokens != null && ignoredTokens.Length > 0) { IList <String> processed = new List <String>(); for (int i = 0; i < tokens.Length; i++) { if (!ignoredTokens.Contains(tokens[i])) { processed.Add(tokens[i]); } } tokensProcessed = processed.ToArray(); } else { tokensProcessed = tokens; } // Parse tokens if (tokensProcessed != null && tokensProcessed.Length > 0) { // Things list to return returnValue = new List <Thing>(); // Get Current Enumerator var enumerator = tokensProcessed.GetEnumerator(); // First Parse the creature Creature creature = new Creature(); creature.Material = new Material3d(); //X Y size pitch motorSys wheel speed fuel color camera // Set Creature Attributes SetAttribute(creature, "Name", enumerator); SetAttribute(creature, "index", enumerator); SetAttribute(creature, "X1", enumerator); SetAttribute(creature, "Y1", enumerator); SetAttribute(creature, "Size", enumerator); SetAttribute(creature, "Pitch", enumerator); SetAttribute(creature, "MotorSystem", enumerator); SetAttribute(creature, "Wheel", enumerator); SetAttribute(creature, "Speed", enumerator); SetAttribute(creature, "Fuel", enumerator); SetAttribute(creature, "serotonin", enumerator); SetAttribute(creature, "endorphine", enumerator); SetAttribute(creature, "score", enumerator); SetAttribute(creature, "XX1", enumerator); SetAttribute(creature, "YY1", enumerator); SetAttribute(creature, "XX2", enumerator); SetAttribute(creature, "YY2", enumerator); SetAttribute(creature.Material, "Color", enumerator); SetAttribute(creature, "actionData", enumerator); SetAttribute(creature, "HasCollided", enumerator); SetAttribute(creature, "HasLeaflet", enumerator); // parsing of leaflets if (creature.HasLeaflet) { creature.leaflets = new List <Leaflet>(); SetAttribute(creature, "NumberOfLeaflets", enumerator); for (int i = 0; i < creature.NumberOfLeaflets; i++) { Leaflet l = new Leaflet(); SetAttribute(l, "leafletID", enumerator); SetAttribute(l, "NumberOfLeafletItems", enumerator); l.items = new List <LeafletItem>(); for (int j = 0; j < l.NumberOfLeafletItems; j++) { LeafletItem li = new LeafletItem(); SetAttribute(li, "itemKey", enumerator); SetAttribute(li, "totalNumber", enumerator); SetAttribute(li, "collected", enumerator); l.items.Add(li); } //28 payment int SetAttribute(l, "payment", enumerator); SetAttribute(l, "situation", enumerator); creature.leaflets.Add(l); } } // Add Creature returnValue.Add(creature); // Get Things Quantity in visual sensor Int32 thingsQuantity = 0; if (enumerator != null && enumerator.MoveNext()) { String currentToken = enumerator.Current as String; thingsQuantity = Convert.ToInt32(currentToken, new CultureInfo("en-US")); } else { throw new WorldServerErrorProcessingResponse("Could not evaluate property: things quantity"); } // Parse Objects for (int i = 0; i < thingsQuantity; i++) { Thing thing = new Thing(); thing.Material = new Material3d(); SetAttribute(thing, "Name", enumerator); SetAttribute(thing, "CategoryId", enumerator); SetAttribute(thing, "IsOccluded", enumerator); SetAttribute(thing, "X1", enumerator); SetAttribute(thing, "X2", enumerator); SetAttribute(thing, "Y1", enumerator); SetAttribute(thing, "Y2", enumerator); SetAttribute(thing, "Pitch", enumerator); SetAttribute(thing.Material, "Hardness", enumerator); SetAttribute(thing.Material, "Energy", enumerator); SetAttribute(thing.Material, "Taste", enumerator); SetAttribute(thing.Material, "Color", enumerator); SetAttribute(thing, "comX", enumerator); SetAttribute(thing, "comY", enumerator); thing.DistanceToCreature = CalculateDistanceToCreature(thing, creature); returnValue.Add(thing); } } else { throw new WorldServerErrorProcessingResponse("Tokens from server are null or empty"); } } } catch (WorldServerErrorProcessingResponse exRes) { throw exRes; } catch (Exception ex) { throw new WorldServerErrorProcessingResponse("Error while parsing GetFullStatus3d", ex); } return(returnValue); }