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();
        }
Beispiel #2
0
        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 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();
        }
Beispiel #4
0
        // ЗАГРУЗКА
        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(); // Закрыть файл
        }