public void OnBuy(SharePacket request, int quantity, decimal price) { SharePacket SP1 = new SharePacket(); { SP1.CompanyName = request.CompanyName; SP1.Price = price; SP1.CurrentQuantity = quantity; SP1.Owner = "BUY"; } SharePacket SP2 = new SharePacket(); { SP2.CompanyName = request.CompanyName; SP2.CurrentQuantity = quantity; } //decimal temp = request.Price; //request.Owner = "BUY"; //request.CurrentQuantity = quantity; for (int i = 0; i < Player.Current.History.List.Count; i++) { if (Player.Current.History.List[i].Owner == "REQUEST" && Player.Current.History.List[i].CompanyName == request.CompanyName && Player.Current.History.List[i].Price == request.Price) { //request.Price = price; Player.Current.Money += (Player.Current.History.List[i].Price - price); Player.Current.History.List[i].CurrentQuantity -= quantity; Player.Current.History.RemoveEmptyEntries(); //request.Price = temp; } } //request.Price = price; Player.Current.History.List.Add(SP1); Player.Current.Pocket.List.Add(SP2); //request.Price = temp; }
public void ReadCompaniesList() { String readLine; StreamReader fileRead = new StreamReader("CompaniesList.txt"); readLine = fileRead.ReadLine(); while (readLine != null) { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[4]), Int32.Parse(substrings[3]), substrings[1], substrings[2]); Market.Current.CompaniesList.List.Add(sp); readLine = fileRead.ReadLine(); } fileRead.Close(); }
public void ReadCompaniesList() { String readLine; StreamReader fileRead = new StreamReader("CompaniesList.txt"); //"открыть файл" readLine = fileRead.ReadLine(); //Чтение первой строки. Начинать сразу в вайле - нельзя while (readLine != null) { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[4]), Int32.Parse(substrings[3]), substrings[1], substrings[2]); Market.Current.CompaniesList.List.Add(sp); readLine = fileRead.ReadLine(); } fileRead.Close(); // Закрыть файл }
public decimal CheckReferences(SharePacket cmp)//!!!Обрабоать невозможность создания 2 одинаковых инвентов + перейти к новому формату ивентов!!! { decimal coeff = 1; for (int i = 0; i < CurrentEvents.Count; i++) { String[] substrings1 = CurrentEvents[i].CompanyType.Split(new char[] { ',' }); String[] substrings2 = CurrentEvents[i].Influence.Split(new char[] { ',' }); String[] substrings3 = CurrentEvents[i].Location.Split(new char[] { ',' }); string companyName = CurrentEvents[i].CompanyName; coeff *= EventTypeComparer(cmp, substrings2, substrings1, substrings3, companyName); } return(coeff); }
public decimal CheckReferences(SharePacket cmp) { decimal coeff = 1; for (int i = 0; i < CurrentEvents.Count; i++) { String[] substrings1 = CurrentEvents[i].CompanyType.Split(new char[] { ',' }); String[] substrings2 = CurrentEvents[i].Influence.Split(new char[] { '$' }); String[] substrings3 = CurrentEvents[i].Location.Split(new char[] { ',' }); string companyName = CurrentEvents[i].CompanyName; coeff *= EventTypeComparer(cmp, substrings2, substrings1, substrings3, companyName); } return(coeff); }
public void OnSell(SharePacket offer, int quantity, decimal price) { Player.Current.Money += quantity * offer.Price; SharePacket pack = new SharePacket(); { pack.CompanyName = offer.CompanyName; pack.Price = price; pack.CurrentQuantity = quantity; pack.Owner = "SELL"; } Player.Current.History.List.Add(pack); for (int i = 0; i < Player.Current.History.List.Count; i++) { if (Player.Current.History.List[i].Owner == "OFFER" && Player.Current.History.List[i].CompanyName == offer.CompanyName && Player.Current.History.List[i].Price == offer.Price) { Player.Current.History.List[i].CurrentQuantity -= quantity; Player.Current.History.RemoveEmptyEntries(); } } }
public decimal EventTypeComparer(SharePacket cmp, string[] influences, string[] companyTypes, string[] locations, string companyName) { decimal eventInfluence; decimal.TryParse(influences[0], NumberStyles.Any, new CultureInfo("en-US"), out eventInfluence); decimal coef = 1; int i = 0; int j = 0; if (eventInfluence > 0) { if (companyName != null && cmp.CompanyName == companyName) { coef *= eventInfluence; return(coef); } while (i < locations.Count()) { if (locations[i] == "All" || locations[i] == cmp.Location) { while (j < companyTypes.Count()) { if (companyTypes[j] == "All" || companyTypes[j] == cmp.CompanyType) { coef *= eventInfluence; } j++; } } i++; } } else { Console.WriteLine("Influence was corrupt"); } return(coef); }
public void GenerateBuyOffering(string name, decimal price, int quantity, string owner) { SharePacket SP = new SharePacket { CompanyName = name, Price = price, CurrentQuantity = quantity, Owner = owner }; BuyList.List.Add(SP); if (owner != null) { SharePacket SP2 = new SharePacket { CompanyName = name, Price = price, CurrentQuantity = quantity, Owner = "REQUEST" }; Player.Current.History.List.Add(SP2); } }
public List <SharePacket> GetPackets(string companyName) { List <SharePacket> list = new List <SharePacket>(); foreach (var packet in List) { if (packet.CompanyName == companyName) { SharePacket packet1 = new SharePacket { Age = packet.Age, Quantity = packet.Quantity, CurrentQuantity = packet.CurrentQuantity, Price = packet.Price, Owner = packet.Owner, CompanyName = packet.CompanyName }; list.Add(packet1); packet.CurrentQuantity = 0; } } RemoveEmptyEntries(); return(list); }
public void CancelOfferings() { if (Player.Current.History.List.Count == 0) { return; } Console.WriteLine("Do you want to cancel your offer/request?"); Console.Write('$'); string command = Console.ReadLine(); ListActions Temp = new ListActions(); Temp.Initialize(); if (command.ToLower() == "y") { int j = 1; for (int i = 0; i < Player.Current.History.List.Count; i++) { if (Player.Current.History.List[i].Owner == "REQUEST" || Player.Current.History.List[i].Owner == "OFFER") { Temp.List.Add(Player.Current.History.List[i]); Console.WriteLine("{0} {1} {2} {3}", j, Player.Current.History.List[i].CompanyName, Player.Current.History.List[i].CurrentQuantity, Player.Current.History.List[i].Price); Player.Current.History.List.RemoveAt(i); i--; j++; } } if (j != 1) { int number; Console.WriteLine("Enter number of one that you want to cancel:"); Int32.TryParse(Console.ReadLine(), out number); number--; if (number > 0 && Temp.List.Count >= number && Temp.List[number].Owner == "REQUEST") { Player.Current.Money += Temp.List[number].Price * Temp.List[number].CurrentQuantity; int pointToDelete = Market.Current.BuyList.FindNumber(Temp.List[number].CompanyName, Temp.List[number].Price, Temp.List[number].CurrentQuantity); Market.Current.BuyList.List.RemoveAt(pointToDelete); Temp.List.RemoveAt(number); foreach (var packet in Temp.List) { Player.Current.History.List.Add(packet); } } else if (number > 0 && Temp.List.Count >= number && Temp.List[number].Owner == "OFFER") { SharePacket pack = new SharePacket { Price = Temp.List[number].Price, CurrentQuantity = Temp.List[number].CurrentQuantity, CompanyName = Temp.List[number].CompanyName }; Player.Current.Pocket.List.Add(pack); int pointToDelete = Market.Current.SellList.FindNumber(Temp.List[number].CompanyName, Temp.List[number].Price, Temp.List[number].CurrentQuantity); Market.Current.SellList.List.RemoveAt(pointToDelete); Temp.List.RemoveAt(number); foreach (var packet in Temp.List) { Player.Current.History.List.Add(packet); } } } else { Console.WriteLine("You don't have any requests or offers"); } } }
public void Load() { Market.Current.BuyList.List.Clear(); Market.Current.SellList.List.Clear(); Console.WriteLine("Enter save's name"); string save = Console.ReadLine(); save += ".save"; String readLine; StreamReader fileRead = new StreamReader(save); readLine = fileRead.ReadLine(); Market.Current.Difficulty = readLine; readLine = fileRead.ReadLine(); Market.Current.ShowToolTips = bool.Parse(readLine); readLine = fileRead.ReadLine(); Market.Current.DayCounter = Int32.Parse(readLine); readLine = fileRead.ReadLine(); Player.Current.Name = readLine; readLine = fileRead.ReadLine(); Player.Current.Money = decimal.Parse(readLine); readLine = fileRead.ReadLine(); while (readLine != "History") { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[2]), Int32.Parse(substrings[1])); sp.Owner = Player.Current.Name; Player.Current.Pocket.List.Add(sp); readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "BuyList") { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[2]), Int32.Parse(substrings[1])); sp.Owner = substrings[3]; Player.Current.History.List.Add(sp); readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "SellList") { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[3]), Int32.Parse(substrings[2]), Int32.Parse(substrings[1])); if (4 < substrings.Count()) { sp.Owner = substrings[4]; } Market.Current.BuyList.List.Add(sp); readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "Events") { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[3]), Int32.Parse(substrings[2]), Int32.Parse(substrings[1])); if (4 < substrings.Count()) { sp.Owner = substrings[4]; } Market.Current.SellList.List.Add(sp); readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != null) { Event evnt = new Event(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); evnt.Location = substrings[0]; evnt.CompanyType = substrings[1]; evnt.Influence = substrings[2]; evnt.Duration = Int32.Parse(substrings[3]); if (4 < substrings.Count()) { evnt.CompanyName = substrings[4]; } Market.Current.CurrentEvents.Add(evnt); readLine = fileRead.ReadLine(); } foreach (SharePacket cmp in Market.Current.CompaniesList.List) { string cmpname = cmp.CompanyName; int number = Player.Current.Pocket.FindNumber(cmp.CompanyName); if (number != -1) { cmp.CurrentQuantity = cmp.Quantity - Market.Current.SellList.GetAmountOfShares(cmpname) - Player.Current.Pocket.List[number].CurrentQuantity; } else { cmp.CurrentQuantity = cmp.Quantity - Market.Current.SellList.GetAmountOfShares(cmpname); } } fileRead.Close(); }
public void FindandAddEvent(Event evnt, string findevent) { string readline; StreamReader sr = new StreamReader("Events.txt"); readline = sr.ReadLine(); while (readline != findevent) { readline = sr.ReadLine(); } readline = sr.ReadLine(); if (readline == "Random") { Random rand = new Random(); string type; StreamReader reader = new StreamReader("IDKHowToName.txt"); type = reader.ReadLine(); String[] types = type.Split(new[] { ", " }, StringSplitOptions.None); evnt.CompanyType = types[rand.Next(types.Length)]; evnt.WhatRandom = "Type"; } else if (readline != "") { evnt.CompanyType = readline; } readline = sr.ReadLine(); if (readline == "Random") { if (evnt.CompanyType != null) { SharePacket cmp = new SharePacket(); List <SharePacket> listwType = new List <SharePacket>(); int i = 0; foreach (SharePacket packet in Market.Current.CompaniesList.List) { if (Market.Current.CompaniesList.List[i].CompanyType == cmp.CompanyType) { listwType.Add(packet); } i++; } Random rand = new Random(); cmp = listwType.ElementAt(rand.Next(listwType.Count())); evnt.Location = cmp.Location; } else { Random rand = new Random(); string loc; StreamReader reader = new StreamReader("IDKHowToName.txt"); reader.ReadLine(); loc = reader.ReadLine(); String[] locs = loc.Split(new[] { ", " }, StringSplitOptions.None); evnt.Location = locs[rand.Next(locs.Length)]; } evnt.WhatRandom = "Location"; } else if (readline != "") { evnt.Location = readline; } readline = sr.ReadLine(); if (readline == "Random") { SharePacket cmp = new SharePacket(); Random rand = new Random(); cmp = Market.Current.CompaniesList.List.ElementAt(rand.Next(Market.Current.CompaniesList.List.Count())); evnt.CompanyName = cmp.CompanyName; evnt.WhatRandom = "Company"; evnt.CompanyType = cmp.CompanyType; evnt.Location = cmp.Location; } else if (readline != "") { evnt.CompanyName = readline; } readline = sr.ReadLine(); String[] array = readline.Split(new[] { "-" }, StringSplitOptions.None); if (array.Count() == 2) { Random rand = new Random(); double Min = Double.Parse(array[0], CultureInfo.InvariantCulture); double Max = Double.Parse(array[1], CultureInfo.InvariantCulture); double Res = rand.NextDouble() * (Max - Min) + Min; evnt.Influence += Res; } else { evnt.Influence = readline; } readline = sr.ReadLine(); if (readline == "forever") { evnt.Duration = -1; } else { evnt.Duration = Int32.Parse(readline); } readline = sr.ReadLine(); evnt.Description = readline; if (evnt.WhatRandom != null) { switch (evnt.WhatRandom) { case "Type": { evnt.Description += (evnt.CompanyType + "*"); } break; case "Location": { evnt.Description += (evnt.Location + "*"); } break; case "Company": { evnt.Description += (evnt.CompanyName + "*"); } break; default: break; } } readline = sr.ReadLine(); String[] array1 = readline.Split(new[] { "!" }, StringSplitOptions.None); if (array1.Count() > 1) { switch (evnt.WhatRandom) { case "Location": { evnt.EndMessage += (array1[0] + evnt.Location + array1[1]); } break; case "Company": { evnt.EndMessage += (array1[0] + evnt.CompanyName + array1[1]); } break; default: break; } } else { evnt.EndMessage += (array1[0]); } Market.Current.CurrentEvents.Add(evnt); Console.WriteLine("Event happened:\n {0}", evnt.Description); readline = sr.ReadLine(); if (Market.Current.ShowToolTips == true) { evnt.Tooltips = readline; Console.WriteLine(evnt.Tooltips); } Console.ReadKey(); sr.Close(); }
// ЗАГРУЗКА public void Load() { Market.Current.BuyList.List.Clear(); Market.Current.SellList.List.Clear(); Console.WriteLine("Enter save's name"); string save = Console.ReadLine(); save += ".save"; String readLine; StreamReader fileRead = new StreamReader(save); //"открыть файл" readLine = fileRead.ReadLine(); Market.Current.Difficult = readLine; readLine = fileRead.ReadLine(); Market.Current.ShowTooltips = bool.Parse(readLine); readLine = fileRead.ReadLine(); Market.Current.DayCounter = Int32.Parse(readLine); //Какой день readLine = fileRead.ReadLine(); Player.Current.Name = readLine; //Чтение имени игрока readLine = fileRead.ReadLine(); Player.Current.Money = decimal.Parse(readLine); //Чтение кол-ва денег readLine = fileRead.ReadLine(); while (readLine != "History") //Чтение инвентаря { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[2]), Int32.Parse(substrings[1])); //инициация sp имя, цена, кол-во sp.Owner = Player.Current.Name; //владелец - игрок Player.Current.Pocket.List.Add(sp); //закинуть в инвентарь readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "BuyList") //Чтение истории { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[2]), Int32.Parse(substrings[1])); //инициация sp имя, цена, кол-во sp.Owner = substrings[3]; //чтение buy или sell Player.Current.History.List.Add(sp); //закинуть в историю readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "SellList") //Чтение BuyList { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[3]), Int32.Parse(substrings[2]), Int32.Parse(substrings[1])); //инициация sp имя, цена, кол-во, возраст if (4 < substrings.Count()) //если есть владелец (игрок) присвоить владельца { sp.Owner = substrings[4]; } Market.Current.BuyList.List.Add(sp); //закинуть в BuyList readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != "Events") //Чтение SellList { SharePacket sp = new SharePacket(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); sp.InitSharePacket(substrings[0], decimal.Parse(substrings[3]), Int32.Parse(substrings[2]), Int32.Parse(substrings[1])); //инициация sp имя, цена, кол-во, возраст if (4 < substrings.Count()) //если есть владелец (игрок) присвоить владельца { sp.Owner = substrings[4]; } Market.Current.SellList.List.Add(sp); //закинуть в SellList readLine = fileRead.ReadLine(); } readLine = fileRead.ReadLine(); while (readLine != null) //Чтение ивентов { Event evnt = new Event(); String[] substrings = readLine.Split(new[] { ", " }, StringSplitOptions.None); evnt.Location = substrings[0]; //локация evnt.CompanyType = substrings[1]; //тип evnt.Influence = substrings[2]; //множитель evnt.Duration = Int32.Parse(substrings[3]); //длительность if (4 < substrings.Count()) { evnt.CompanyName = substrings[4]; //имя компании если есть } Market.Current.CurrentEvents.Add(evnt); readLine = fileRead.ReadLine(); } foreach (SharePacket cmp in Market.Current.CompaniesList.List) //задать текущее колл-во акций исходя из кол-ва в селку !и кол-ва в инвентаре у игрока! { string cmpname = cmp.CompanyName; int number = Player.Current.Pocket.FindNumber(cmp.CompanyName); if (number != -1) { cmp.CurrentQuantity = cmp.Quantity - Market.Current.SellList.GetAmountOfShares(cmpname) - Player.Current.Pocket.List[number].CurrentQuantity; } else { cmp.CurrentQuantity = cmp.Quantity - Market.Current.SellList.GetAmountOfShares(cmpname); } } fileRead.Close(); // Закрыть файл }
public void FindandAddEvent(Event evnt, string findevent) { string readline; StreamReader sr = new StreamReader("Events.txt");//должно быть try {sr} finally {sr.close;} readline = sr.ReadLine(); while (readline != findevent) //поиск рандомного ивента { readline = sr.ReadLine(); } readline = sr.ReadLine(); //чтение типа компании if (readline == "Random") { Random rand = new Random(); string type; StreamReader reader = new StreamReader("IDKHowToName.txt"); //открыли список типов и локаций type = reader.ReadLine(); String[] types = type.Split(new[] { ", " }, StringSplitOptions.None); //получили список всех типов evnt.CompanyType = types[rand.Next(types.Length)]; //присвоили рандомный тип evnt.WhatRandom = "Type"; } else if (readline != "") { evnt.CompanyType = readline; } readline = sr.ReadLine(); //чтение локации if (readline == "Random") //рандомная локация { if (evnt.CompanyType != null) //если есть тип { SharePacket cmp = new SharePacket(); List <SharePacket> listwType = new List <SharePacket>(); listwType = FindType(evnt.CompanyType); // список пакетов нужного типа Random rand = new Random(); cmp = listwType.ElementAt(rand.Next(listwType.Count())); evnt.Location = cmp.Location; //присвоили рандомную локацию } else //если нет типа { Random rand = new Random(); string loc; StreamReader reader = new StreamReader("IDKHowToName.txt"); //открыли список типов и локаций reader.ReadLine(); loc = reader.ReadLine(); String[] locs = loc.Split(new[] { ", " }, StringSplitOptions.None); //получили список всех локаций evnt.Location = locs[rand.Next(locs.Length)]; //присвоили рандомную локацию } evnt.WhatRandom = "Location"; } else if (readline != "") //не рандомная локация { evnt.Location = readline; } readline = sr.ReadLine(); // чтение названия компании if (readline == "Random") { SharePacket cmp = new SharePacket(); Random rand = new Random(); cmp = Market.Current.CompaniesList.List.ElementAt(rand.Next(Market.Current.CompaniesList.List.Count())); evnt.CompanyName = cmp.CompanyName; evnt.WhatRandom = "Company"; evnt.CompanyType = cmp.CompanyType; evnt.Location = cmp.Location; } else if (readline != "") { evnt.CompanyName = readline; } readline = sr.ReadLine(); //чтение множителя String[] array = readline.Split(new[] { "-" }, StringSplitOptions.None); if (array.Count() == 2) { Random rand = new Random(); double Min = Double.Parse(array[0]); double Max = Double.Parse(array[1]); // String[] firstnumb = array[0].Split(new[] { "." }, StringSplitOptions.None); // String[] secondnumb = array[1].Split(new[] { "." }, StringSplitOptions.None); double Res = rand.NextDouble() * (Max - Min) + Min; evnt.Influence += Res; // int fractoffirst = Int32.Parse(firstnumb[1]); // int fractofsecond = Int32.Parse(secondnumb[1]); // evnt.Influence += "."; // if (fractoffirst < fractofsecond) // { // evnt.Influence += rand.Next(fractoffirst, fractofsecond + 1); // } // else if (fractoffirst > fractofsecond) // { // evnt.Influence += rand.Next(fractofsecond, fractoffirst + 1); // } // else // { // evnt.Influence += fractoffirst; // } } else { evnt.Influence = readline; } readline = sr.ReadLine(); //чтение длительности if (readline == "forever") { evnt.Duration = -1; } else { evnt.Duration = Int32.Parse(readline); } readline = sr.ReadLine(); evnt.Description = readline; if (evnt.WhatRandom != null) //если был рандом { switch (evnt.WhatRandom) { case "Type": { evnt.Description += (" " + evnt.CompanyType); } break; case "Location": { evnt.Description += (" " + evnt.Location); } break; case "Company": { evnt.Description += (" " + evnt.CompanyName); } break; } } readline = sr.ReadLine(); String[] array1 = readline.Split(new[] { "!" }, StringSplitOptions.None); if (array1.Count() == 2) //DODELAT { evnt.EndMessage += (array1[0] + evnt.CompanyName); } evnt.EndMessage = readline; Market.Current.CurrentEvents.Add(evnt); //добавили в current events Console.WriteLine("Event happened\n {0}", evnt.Description); if (Market.Current.ShowTooltips == true) { readline = sr.ReadLine(); evnt.Tooltips = readline; Console.WriteLine(evnt.Tooltips); } Console.ReadKey(); sr.Close(); }