Example #1
0
        public void CombineEquals(ListActions List)
        {
            List <int> Numbers = new List <int>();

            foreach (SharePacket cmp in CompaniesList.List)
            {
                int number = 0;
                Numbers.Clear();
                foreach (SharePacket packet in List.List)
                {
                    if (List.List[number].CompanyName == cmp.CompanyName)
                    {
                        Numbers.Add(number);
                    }
                    number++;
                }
                for (int i = 0; i < Numbers.Count - 1; i++)
                {
                    if (List.List[Numbers[i]].Price == List.List[Numbers[i + 1]].Price)
                    {
                        List.List[Numbers[i]].CurrentQuantity = List.List[Numbers[i]].CurrentQuantity + List.List[Numbers[i + 1]].CurrentQuantity;
                        List.List.RemoveAt(Numbers[i + 1]);
                        Numbers.RemoveAt(Numbers.Count - 1);
                        i--;
                    }
                }
            }
        }
Example #2
0
        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");
                }
            }
        }