static void Main(string[] args) { try { Horse Bobby = new Horse(152, 12, "four", "Venison"); Bobby.YearsOld(); Bobby.Legs(); Bobby.TypesofMeat(); pigs Tommy = new pigs(76, 4, "five", "Bacon, Porkchops"); Tommy.YearsOld(); Tommy.Legs(); Tommy.TypesofMeat(); Cows Randy = new Cows(200, 5, "three", "Steak"); Randy.YearsOld(); Randy.Legs(); Randy.TypesofMeat(); dog Jacob = new dog(50, 3, "four", "dog meat"); Jacob.YearsOld(); Jacob.Legs(); Jacob.TypesofMeat(); } catch (FormatException Fex) { Console.WriteLine(Fex.Message); Console.ReadKey(); } }
/// <summary> /// Method that will return any possible mills that will be made by a player by placing or moving a cow to 'pos' (excluding any mills they already have) /// </summary> /// <param name="pos">Position that will potentially make a mill</param> /// <returns>List of mills made represented as Array of Positions</returns> /* * NOTE: This method needs to be called before a cow is added to a players cow list so as to check if any mills will be made by the player this makes it so that * there is no need to keep track of the players previous state and next state. */ public IEnumerable <IEnumerable <IPosition> > GetMills(IPosition p) { Position Pos = (Position)p; List <Position[]> possibleMills = (List <Position[]>)tmpPos.GetPossibleMills(Pos.pos); List <Position[]> finalMills = new List <Position[]>(); //filter out mills i already have foreach (var mill in possibleMills) { if (!(MyMills.Contains(mill))) { finalMills.Add(mill); } } Cows.Add(Pos); //temporarily add cow to accurrately filter cows //filter out mills that i don't have the cows for foreach (var mill in possibleMills) { if (!(Cows.Contains(mill[0]) && Cows.Contains(mill[1]) && Cows.Contains(mill[2]))) { finalMills.Remove(mill); } } Cows.Remove(Pos); //remove temporary cow return(finalMills); }
/// <summary> /// Initializes from list. /// </summary> /// <param name="player"></param> /// <param name="controller"></param> public override void Initialize(Player player, GameController controller) { cows = new List <Cow>(); foreach (var cowInfo in AppCore.AttackSettings.Cows) { if (string.IsNullOrEmpty(cowInfo.UserName)) { continue; } var farmCows = ObjectProvider.Instance.GetCowsByName(cowInfo.UserName); if (farmCows.Count == 0) { farmCows = AddNewCow(cowInfo.UserName, controller, player); } foreach (var cow in farmCows) { cow.MilkingCoulomb = cowInfo.Coulomb; cow.RivalHealth = 1000; cow.RivalInjuryHealth = 1000; Cows.Add(cow); } } FillResults(controller); }
private void AddPotentioal(LevelFilter filter) { try { var poterial = ObjectProvider.Instance.GetPotentialCows(filter, AppCore.AttackSettings.MinBenefit). Where(e => e.AverageBenefit > AppCore.AttackSettings.MinBenefit).ToArray(); var cowsIds = (from p in Cows select p.UserID).ToList(); var toUpdate = (from p in poterial where cowsIds.Contains(p.UserID) select p).ToArray(); foreach (var cowU in toUpdate) { var updated = (from c in Cows where c.UserID == cowU.UserID select c).FirstOrDefault(); if (updated != null) { updated.AverageBenefit = (updated.AverageBenefit + cowU.AverageBenefit) / 2; } } var toAdd = (from p in poterial where !cowsIds.Contains(p.UserID) select p).ToArray(); Cows.AddRange(toAdd); } catch (Exception ex) { AppCore.LogSystem.Warn("Проблемы в инициалиции фермы", ex); } }
/// <summary> /// Method that 'moves cows' by taking in two positions (Old position and New Position) and removes oldPos from players current cows and adds newPos to players current cows /// </summary> /// <param name="oldPos">Cow to remove </param> /// <param name="newPos">Cow to add</param> public void MoveCow(IPosition oPos, IPosition nPos) { Position oldPos = (Position)oPos; Position newPos = (Position)nPos; ShootCow(oldPos); Cows.Add(newPos); }
private decimal?GetMaxAverageBenefit() { try { return(Cows.Where(c => c.State == CowState.Ready).Max(c => c.AverageBenefit)); } catch { return((decimal?)null); } }
private int?GetMaxLastBenefit() { try { return(Cows.Where(c => c.State == CowState.Ready).Max(c => c.LastBenefit)); } catch { return((int?)null); } }
private bool AreAllCowsInMills(Color ID) { IMill[] PlayerOwnedMills = Mills.Where(x => x.color == ID).ToArray(); ICow[] PlayerOwnedCows = Cows.Where(x => x.Color == ID).ToArray(); for (int i = 0; i < PlayerOwnedCows.Length; i++) { if (!CowInAMill(ID, PlayerOwnedCows[i].Position)) { return(false); } } return(true); }
public void makeCowsFly(Color c) { Cows = Cows.Select(x => { if (x.Color == c) { return(new FlyingCow(x.Position, Color.Black)); } else { return(x); } } ).ToArray(); }
/// <summary> /// Gets the best cow. /// </summary> /// <returns></returns> public override Cow GetBestCow() { RefreshState(); var maxLastBenefit = GetMaxLastBenefit(); if (maxLastBenefit.HasValue && maxLastBenefit > AppCore.AttackSettings.MinBenefit) { var result = Cows.Where(c => c.State == CowState.Ready && c.LastBenefit == maxLastBenefit.Value).FirstOrDefault(); if (result != null) { return(result); } } var maxAverageBenefit = GetMaxAverageBenefit(); if (maxAverageBenefit.HasValue && maxAverageBenefit > AppCore.AttackSettings.MinBenefit) { return(Cows.Where(c => c.State == CowState.Ready && c.AverageBenefit == maxAverageBenefit.Value).FirstOrDefault()); } return(null); }
/// <summary> /// Gets the best cow. /// </summary> /// <returns></returns> public override Cow GetBestCow() { RefreshState(); Cow bestCow = null; decimal maxBenefit = -1; var readyCows = Cows.Where(c => c.State == CowState.Ready).ToArray(); foreach (var cow in readyCows) { var cristalBenefit = (cow.MilkingCount > 0 && cow.Cristals > 0) ? (cow.Cristals / cow.MilkingCount) * 800 : 0; var benefit = cow.RivalHealth + cow.RivalInjuryHealth + cow.AverageBenefit + cristalBenefit; if (benefit <= maxBenefit) { continue; } bestCow = cow; maxBenefit = benefit; } return(bestCow); }
public bool CanPlaceAt(int Position) { return(Cows.ElementAt(Position).Color == Color.Black); }
public bool isCowAt(int pos) { return(Cows.ElementAt(pos).Color != Color.Black); }
static void Main(string[] args) { Console.WriteLine("Setup variables..."); Statistic = new Dictionary <dynamic, double>(); Console.WriteLine("Wait for ready..."); LoadCowData(); //try //{ Console.WriteLine("Clearing old data..."); DataProvider.ExecuteNonQuery("delete chamsoc"); DataProvider.ExecuteNonQuery("delete tinhtrangbo"); DataProvider.ExecuteNonQuery("update counter set index_chamsoc = 0"); Console.WriteLine("Seeding data..."); var PCs = DataProvider.ExecuteReader <dynamic>((SqlDataReader row) => { return(new { id = row.GetValueDefault <string>(0), userid = row.GetValueDefault <string>(1), barnid = row.GetValueDefault <string>(2), start = row.GetValueDefault <DateTime>(3), end = row.GetValueDefault <DateTime>(4), daysOfWeek = row.GetValueDefault <string>(5).Replace("CN", "1"), areaId = row.GetValueDefault <string>(1).Split(new string[] { "NV" }, 2, StringSplitOptions.RemoveEmptyEntries)[0], }); }, "select maphancong, manv, machuong, ngaybatdau, ngayketthuc, ngaytrongtuan from phancong"); DateTime run = START_DATE; while (run.CompareTo(DateTime.Now) == -1) { foreach (var eachPC in PCs) { if (run.CompareTo(eachPC.start) == 1 && run.CompareTo(eachPC.end) == -1 && eachPC.daysOfWeek.Contains(((int)run.DayOfWeek + 1).ToString())) { foreach (var cow in Cows.Where(x => x.machuong == eachPC.barnid && x.daxoa == "0")) { string newId = createId(eachPC.areaId); bool milk = false; double milkValue = 0d; if (new Random().NextDouble() > 0.6) { milk = true; milkValue = (double)(new Random().Next(500, 1000)) / 100d; AddMilk(cow.machinhanh, milkValue); } DataProvider.ExecuteNonQuery( string.Format("insert into chamsoc(machamsoc, ngayghinhan, tinhtrangcongviec, luongsua, dachoan, dadonvesinh, davatsua, maphancong, mabo, machinhanh)" + " values ('{0}', '{1}', N'{2}', {3}, '{4}', '{5}', '{6}', '{7}', '{8}', '{9}')", newId, run, "Đã hoàn thành.", milkValue, true, true, milk, eachPC.id, cow.mabo, cow.machinhanh)); //loop 2-4 times DateTime a = new DateTime(run.Year, run.Month, run.Day, 7, 0, 0); for (int i = 0; i < new Random().Next(2, 4); i++) { a = a.Add(new TimeSpan(new Random().Next(1, 2), new Random().Next(1, 59), new Random().Next(1, 59))); if ((int)DataProvider.ExecuteScalar(string.Format("select count(mabo) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo)) > 0) { double maxWeight = (double)DataProvider.ExecuteScalar(string.Format("select max(a.cannang) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo)); double maxHeight = (double)DataProvider.ExecuteScalar(string.Format("select max(a.chieucao) from tinhtrangbo a, chamsoc b where a.machamsoc = b.machamsoc and b.mabo = '{0}'", cow.mabo)); DataProvider.ExecuteNonQuery( string.Format("insert into tinhtrangbo(machamsoc, thoigianghinhan, cannang, chieucao)" + " values ('{0}', '{1}', {2}, {3})", newId, a, maxWeight + (new Random().NextDouble() > 0.6 ? (double)(new Random().Next(3, 9)) / 100d : 0d), maxHeight + (new Random().NextDouble() > 0.6 ? (double)(new Random().Next(0, 3)) / 10000d : 0d))); } else { DataProvider.ExecuteNonQuery( string.Format("insert into tinhtrangbo(machamsoc, thoigianghinhan, cannang, chieucao)" + " values ('{0}', '{1}', {2}, {3})", newId, a, (double)(new Random().Next(8000, 12000)) / 100d, (double)(new Random().Next(100, 120)) / 100d)); } } } } } run = run.AddDays(1); } //} //catch (Exception ex) //{ // throw ex; //} Console.WriteLine("Wait for write statistic to file..."); WriteStatisticData(); Console.WriteLine("Finish! Press any to exit..."); Console.Read(); }
public void InitAnimal(Cows cow) { this.cow = cow; }
public IEnumerable <ICow> getCowsByPlayer(Color c) { return(Cows.Where(x => x.Color == c)); }
static void LoadPlayerSaveFile() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"./Content/Save/PlayerSave.xml"); XmlNode root = xmlDoc.SelectSingleNode("CV"); XmlNodeList rootList = root.ChildNodes; foreach (XmlNode rootNode in rootList) { switch (rootNode.Name) { case "Global": XmlNodeList rootGlobalList = rootNode.ChildNodes; foreach (XmlNode rootGlobalNode in rootGlobalList) { switch (rootGlobalNode.Name) { case "Time": GlobalController.Time = float.Parse(rootGlobalNode.InnerText); break; case "Year": GlobalController.Year = int.Parse(rootGlobalNode.InnerText); break; case "Season": GlobalController.Season = int.Parse(rootGlobalNode.InnerText); break; case "Date": GlobalController.Date = int.Parse(rootGlobalNode.InnerText); break; case "WeekDay": GlobalController.WeekDay = int.Parse(rootGlobalNode.InnerText); break; case "Weather": GlobalController.Weather = rootGlobalNode.InnerText; break; case "IsShipment": GlobalController.isShipment = bool.Parse(rootGlobalNode.InnerText); break; default: break; } } break; case "Player": XmlNodeList rootPlayerList = rootNode.ChildNodes; foreach (XmlNode rootPlayerNode in rootPlayerList) { switch (rootPlayerNode.Name) { case "Map": GlobalController.CStatus = new GlobalController.Cs { cName = rootPlayerNode.InnerText, func = 0 }; break; case "Position": GlobalController.PlayerWithoutInit.Position = new Vector2(float.Parse(rootPlayerNode.InnerText.Split('|')[0]), float.Parse(rootPlayerNode.InnerText.Split('|')[1])); break; case "Name": GlobalController.PlayerWithoutInit.Name = rootPlayerNode.InnerText; break; case "Character": XmlNodeList elementList = rootPlayerNode.ChildNodes; CharacterTile[] cTile = new CharacterTile[8]; for (int i = 0; i < 8; i++) { string context = elementList[i].InnerText; string[] inner = context.Split('|'); cTile[i] = new CharacterTile(int.Parse(inner[0]), int.Parse(inner[1]), inner[2], inner[4], inner[6], inner[8], inner[10], inner[12], inner[14], inner[16], inner[18], inner[20], inner[22], inner[24], int.Parse(inner[3].Split(',')[0]), int.Parse(inner[3].Split(',')[1]), int.Parse(inner[5].Split(',')[0]), int.Parse(inner[5].Split(',')[1]), int.Parse(inner[7].Split(',')[0]), int.Parse(inner[7].Split(',')[1]), int.Parse(inner[9].Split(',')[0]), int.Parse(inner[9].Split(',')[1]), int.Parse(inner[11].Split(',')[0]), int.Parse(inner[11].Split(',')[1]), int.Parse(inner[13].Split(',')[0]), int.Parse(inner[13].Split(',')[1]), int.Parse(inner[15].Split(',')[0]), int.Parse(inner[15].Split(',')[1]), int.Parse(inner[17].Split(',')[0]), int.Parse(inner[17].Split(',')[1]), int.Parse(inner[19].Split(',')[0]), int.Parse(inner[19].Split(',')[1]), int.Parse(inner[21].Split(',')[0]), int.Parse(inner[21].Split(',')[1]), int.Parse(inner[23].Split(',')[0]), int.Parse(inner[23].Split(',')[1]), int.Parse(inner[25].Split(',')[0]), int.Parse(inner[25].Split(',')[1])); } GlobalController.PlayerWithoutInit.CTile = cTile; break; case "Speed": GlobalController.PlayerWithoutInit.Speed = float.Parse(rootPlayerNode.InnerText); break; case "Gender": GlobalController.PlayerWithoutInit.Gender = bool.Parse(rootPlayerNode.InnerText); break; case "HasLight": GlobalController.PlayerWithoutInit.HasLight = bool.Parse(rootPlayerNode.InnerText); break; case "HpUpper": GlobalController.PlayerWithoutInit.HpUpper = float.Parse(rootPlayerNode.InnerText); break; case "Hp": GlobalController.PlayerWithoutInit.Hp = float.Parse(rootPlayerNode.InnerText); break; case "EnergyUpper": GlobalController.PlayerWithoutInit.EnergyUpper = float.Parse(rootPlayerNode.InnerText); break; case "Energy": GlobalController.PlayerWithoutInit.Energy = float.Parse(rootPlayerNode.InnerText); break; case "Habitus": GlobalController.PlayerWithoutInit.Habitus = float.Parse(rootPlayerNode.InnerText); break; case "Hunger": GlobalController.PlayerWithoutInit.Hunger = float.Parse(rootPlayerNode.InnerText); break; case "Gold": GlobalController.PlayerWithoutInit.Gold = int.Parse(rootPlayerNode.InnerText); break; case "IsDisease": GlobalController.PlayerWithoutInit.IsDisease = bool.Parse(rootPlayerNode.InnerText); break; case "Inventory": XmlNodeList inventoryList = rootPlayerNode.ChildNodes; for (int i = 0; i < inventoryList.Count; i++) { if (i == 0) { GlobalController.InventoryCount = int.Parse(inventoryList[i].InnerText); for (int j = 0; j < GlobalController.InventoryCount; j++) { GlobalController.InventoryList.Add(new Inventory(null, true, j + 1, 0)); } } else { GlobalController.InventoryList[i - 1].AddItem(Item.ItemCreateFactory(inventoryList[i].InnerText.Substring(0, 6)), int.Parse(inventoryList[i].InnerText.Substring(7, inventoryList[i].InnerText.Length - 7))); } } break; case "RapidRoom": XmlNodeList RapidRoomList = rootPlayerNode.ChildNodes; for (int i = 0; i < RapidRoomList.Count; i++) { if (i == 0) { GlobalController.RapidRoomCount = int.Parse(RapidRoomList[i].InnerText); for (int j = 0; j < GlobalController.RapidRoomCount; j++) { GlobalController.RapidRoomList.Add(new Inventory(null, true, j + 1, 0)); } } else { GlobalController.RapidRoomList[i - 1].AddItem(Item.ItemCreateFactory(RapidRoomList[i].InnerText.Substring(0, 6)), int.Parse(RapidRoomList[i].InnerText.Substring(7, RapidRoomList[i].InnerText.Length - 7))); } } break; case "SelectingRapidRoom": XmlNodeList SelectingRapidRoom = rootPlayerNode.ChildNodes; GlobalController.SelectingRapidRoomItem = new Inventory(null, true, 0, 0); if (SelectingRapidRoom.Count > 0) { GlobalController.SelectingRapidRoomItem.AddItem(Item.ItemCreateFactory(SelectingRapidRoom[0].InnerText.Substring(0, 6)), int.Parse(SelectingRapidRoom[0].InnerText.Substring(7, SelectingRapidRoom[0].InnerText.Length - 7))); } break; default: break; } } break; case "Shop": XmlNodeList rootShopList = rootNode.ChildNodes; foreach (XmlNode node in rootShopList) { Shops shop = new Shops(ResourceController.UI_ordinary, ResourceController.UI_logos, Map.Null, node.Name); foreach (XmlNode item in node) { string[] inner = item.InnerText.Split('|'); shop.AddGoods(new Goods(Item.ItemCreateFactory(inner[0]), int.Parse(inner[1]), float.Parse(inner[2]))); } GlobalController.Global_Shops.Add(shop); } break; case "PlayerScene": XmlNodeList rootPlayerSceneList = rootNode.ChildNodes; foreach (XmlNode rootPlayerSceneNode in rootPlayerSceneList) { switch (rootPlayerSceneNode.Name) { case "Chest": string[] contextChest = rootPlayerSceneNode.InnerText.Split('|'); Chest chest = new Chest(new Map(contextChest[0]), new Vector2(int.Parse(contextChest[1]), int.Parse(contextChest[2])), ResourceController.Scenes_chest, int.Parse(contextChest[3])); for (int i = 4; i < contextChest.Length; i++) { string[] contextChestItem = contextChest[i].Split('^'); chest.Inventries[int.Parse(contextChestItem[2])].AddItem(Item.ItemCreateFactory(contextChestItem[0]), int.Parse(contextChestItem[1])); } GlobalController.PlayerSceneList.Add(chest); break; case "Soil": string[] contextSoil = rootPlayerSceneNode.InnerText.Split('|'); if (contextSoil[4] == "True") { Soil soil = new Soil(ResourceController.Scenes_soil, new Map(contextSoil[0]), new Vector2(int.Parse(contextSoil[1]), int.Parse(contextSoil[2])), float.Parse(contextSoil[3]), Item.ItemCreateFactory(contextSoil[5]) as Seeds, true); soil.Seed.LoadingSeeds(float.Parse(contextSoil[6]), bool.Parse(contextSoil[7]), bool.Parse(contextSoil[8]), bool.Parse(contextSoil[9]), float.Parse(contextSoil[10]), float.Parse(contextSoil[11]), float.Parse(contextSoil[12]), float.Parse(contextSoil[13]), float.Parse(contextSoil[14]), float.Parse(contextSoil[15]), float.Parse(contextSoil[16]), float.Parse(contextSoil[17])); GlobalController.SoilList.Add(soil); } else { Soil soil = new Soil(ResourceController.Scenes_soil, new Map(contextSoil[0]), new Vector2(int.Parse(contextSoil[1]), int.Parse(contextSoil[2])), float.Parse(contextSoil[3]), Seeds.Null, false); GlobalController.SoilList.Add(soil); } break; case "PterocarpinTree": string[] contextPTree = rootPlayerSceneNode.InnerText.Split('|'); PterocarpinTree ptree = new PterocarpinTree(new Map(contextPTree[0]), new Vector2(int.Parse(contextPTree [1]), int.Parse(contextPTree[2])), ResourceController.Decorats_spring_tree, ResourceController.Decorats_tree_shadow, true); ptree.GrowTime = float.Parse(contextPTree[3]); GlobalController.PlayerSceneList.Add(ptree); break; case "Furniture": string[] contextFurniture = rootPlayerSceneNode.InnerText.Split('|'); GlobalController.PlayerSceneList.Add(Furniture.CreateFurnitureFactory(new Map(contextFurniture[0]), new Vector2(int.Parse(contextFurniture [1]), int.Parse(contextFurniture[2])), contextFurniture[3])); break; case "Construction": string[] contextConstruction = rootPlayerSceneNode.InnerText.Split('|'); if (contextConstruction[3] == "cowhouse") { CowHouse cowHouse = Construction.CreateConstructionFactory(new Map(contextConstruction[0]), new Vector2(int.Parse(contextConstruction [1]), int.Parse(contextConstruction[2])), contextConstruction[3]) as CowHouse; cowHouse.Init(bool.Parse(contextConstruction[4]), int.Parse(contextConstruction[5]), bool.Parse(contextConstruction[6])); GlobalController.PlayerSceneList.Add(cowHouse); } break; case "Animals": string[] contextAnimal = rootPlayerSceneNode.InnerText.Split('|'); if (contextAnimal[3] == "cow") { Cows cow = Animals.CreateAnimalsFactory(new Map(contextAnimal[0]), new Vector2(int.Parse(contextAnimal [1]), int.Parse(contextAnimal[2])), contextAnimal[3], int.Parse(contextAnimal[5]), float.Parse(contextAnimal[6])) as Cows; cow.Init(float.Parse(contextAnimal[4])); GlobalController.AnimalsList.Add(cow); } break; default: break; } } break; default: break; } } foreach (IPlayerScene ipS in GlobalController.PlayerSceneList) { if (ipS.GetIntanceType() == "Construction") { if ((ipS.GetInstance() as Construction).Name == "cowhouse") { CowHouse ch = ipS.GetInstance() as CowHouse; GlobalController.AnimalsList.ForEach(u => { if (u.GetIntanceType() == "Cows") { if ((u.GetInstance() as Cows).Id == ch.Id) { ch.InitAnimal((u.GetInstance() as Cows)); } } }); } } } //GlobalController.OutdoorItemsList.Add(new OutDoorItem(new Map("village_suburb_west"),new Vector2(2400,1700), new Item("1", new Map("village_suburb_west"), new Vector2(1800, 1300), "water1", Content.Load<Texture2D>("Items/items"), 100))); }