Пример #1
0
        /// <summary>
        /// Generates a number of ships that is within a range
        /// </summary>
        public void GenerateShips()
        {
            RandomizerHelper         randomDictionary = new RandomizerHelper();
            DictionaryStorage        listOfShips      = new DictionaryStorage();
            UniqueList               uniqueList       = new UniqueList();
            Dictionary <string, int> dict             = new Dictionary <string, int>();

            Ships = new Dictionary <string, string>();

            numbers = arrayOfNumbers.ToList();

            if (CurrentFaction == "Scum")
            {
                dict = listOfShips.ScumShips;
            }

            if (CurrentFaction == "Imperial")
            {
                dict = listOfShips.ImperialShips;
            }

            int    shipAudit   = 0;
            int    pointsSpent = 0;
            Random r           = new Random();

            if (pointsSpent < ShipBudget)
            {
                ShipCost    = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                pointsSpent = pointsSpent + ShipCost;
            }

            foreach (var fetchedShipName in randomDictionary.RandomValues(dict, ShipCost).Take(1))
            {
                Ship1Name = fetchedShipName;
                Ships.Add("Ship 1: " + fetchedShipName, Ship1Name);
                if (uniqueList.UniqueVar.Contains(fetchedShipName))
                {
                    dict.Remove(fetchedShipName);

                    if (!dict.Values.Contains(ShipCost))
                    {
                        numbers.Remove(ShipCost);
                    }
                }
            }

            if (pointsSpent < ShipBudget)
            {
                Ship2Cost   = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                pointsSpent = pointsSpent + Ship2Cost;
            }


            foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship2Cost).Take(1))
            {
                Ship2Name = fetchedShipName.ToString();
                Ships.Add("Ship 2: " + fetchedShipName, Ship2Name);
                if (uniqueList.UniqueVar.Contains(fetchedShipName))
                {
                    dict.Remove(fetchedShipName);
                    if (uniqueList.UniqueVar.Contains(fetchedShipName))
                    {
                        dict.Remove(fetchedShipName);

                        if (!dict.Values.Contains(ShipCost))
                        {
                            numbers.Remove(ShipCost);
                        }
                    }
                }
            }

            if (pointsSpent < ShipBudget)
            {
                if (pointsSpent < ShipBudget - 5)
                {
                    shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    while (shipAudit + pointsSpent > ShipBudget + 5)
                    {
                        shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    }

                    Ship3Cost   = shipAudit;
                    pointsSpent = pointsSpent + Ship3Cost;
                }
            }

            if (Ship3Cost > 0)
            {
                foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship3Cost).Take(1))
                {
                    Ship3Name = fetchedShipName.ToString();
                    Ships.Add("Ship 3: " + fetchedShipName, Ship3Name);
                    if (uniqueList.UniqueVar.Contains(fetchedShipName))
                    {
                        dict.Remove(fetchedShipName);

                        if (!dict.Values.Contains(ShipCost))
                        {
                            numbers.Remove(ShipCost);
                        }
                    }
                }
            }

            if (pointsSpent < ShipBudget)
            {
                if (pointsSpent < ShipBudget - 12)
                {
                    shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    while (shipAudit + pointsSpent > ShipBudget + 5)
                    {
                        shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    }

                    Ship4Cost   = shipAudit;
                    pointsSpent = pointsSpent + Ship4Cost;
                }
            }

            if (Ship4Cost > 0)
            {
                foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship4Cost).Take(1))
                {
                    Ship4Name = fetchedShipName.ToString();
                    Ships.Add("Ship 4: " + fetchedShipName, Ship4Name);
                    if (uniqueList.UniqueVar.Contains(fetchedShipName))
                    {
                        dict.Remove(fetchedShipName);

                        if (!dict.Values.Contains(ShipCost))
                        {
                            numbers.Remove(ShipCost);
                        }
                    }
                }
            }

            if (pointsSpent < ShipBudget)
            {
                if (pointsSpent < ShipBudget - 12)
                {
                    shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    while (shipAudit + pointsSpent > ShipBudget + 5)
                    {
                        shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                    }

                    Ship5Cost   = shipAudit;
                    pointsSpent = pointsSpent + Ship5Cost;
                }
            }

            if (Ship5Cost > 0)
            {
                foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship5Cost).Take(1))
                {
                    Ship5Name = fetchedShipName.ToString();
                    Ships.Add("Ship 5: " + fetchedShipName, Ship4Name);
                    if (uniqueList.UniqueVar.Contains(fetchedShipName))
                    {
                        dict.Remove(fetchedShipName);

                        if (!dict.Values.Contains(ShipCost))
                        {
                            numbers.Remove(ShipCost);
                        }
                    }
                }
            }

            Console.WriteLine("");
            Console.Write(string.Format("We finished building your ships.  We will be spending {0} on Ship 1, {1} on ship 2", ShipCost.ToString(), Ship2Cost.ToString()));

            if (Ship3Cost > 0)
            {
                Console.Write(string.Format(", {0} on ship 3", Ship3Cost.ToString()));
            }

            if (Ship4Cost > 0)
            {
                Console.Write(string.Format(", {0} on ship 4", Ship4Cost.ToString()));
            }

            if (Ship5Cost > 0)
            {
                Console.Write(string.Format(", {0} on ship 5", Ship5Cost.ToString()));
            }

            Console.Write(".");
            Console.WriteLine("");

            SpentSoFar   = SpentSoFar + pointsSpent;
            SpentOnShips = pointsSpent;
        }
Пример #2
0
        public Dictionary <string, int> RandomUpgrade(string upgradeType)
        {
            RandomizerHelper randomDictionary = new RandomizerHelper();
            string           upgradeName      = "";

            int[] numbers;
            int   shuffle = 0;
            Dictionary <string, int> dict;

            if (upgradeType.Contains("Cannon"))
            {
                Cannon cannons = new Cannon();
                dict = cannons.CannonUpgrades;
                Random rand = new Random();
                numbers = new[] { 1, 2, 3, 4, 5, 7 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("Torpedo"))
            {
                Torpedo torp = new Torpedo();
                dict = torp.TorpedoUpgrades;
                Random rand = new Random();
                numbers = new[] { 2, 3, 4, 5, 6 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("Illicit"))
            {
                Illicit illict = new Illicit();
                dict = illict.IllicitUpgrades;
                Random rand = new Random();
                numbers = new[] { 1, 2, 3 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("ElitePilotTalent"))
            {
                ElitePilotTalent ept   = new ElitePilotTalent();
                ShipBuilder      shipB = new ShipBuilder();
                if (shipB.CurrentFaction == "scum")
                {
                    foreach (var talents in ept.ScumEPT)
                    {
                        ept.GenEPT.Add(talents.Key, talents.Value);
                    }
                }

                dict = ept.GenEPT;
                Random rand = new Random();
                numbers = new[] { 0, 1, 2, 3, 4 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("Crew"))
            {
                Crew        crew  = new Crew();
                ShipBuilder shipB = new ShipBuilder();
                if (shipB.CurrentFaction == "scum")
                {
                    foreach (var talents in crew.ScumCrew)
                    {
                        crew.GenCrew.Add(talents.Key, talents.Value);
                    }
                }
                try
                {
                    crew.GenCrew.Remove(Ship1Name);
                }
                catch
                {
                    Console.WriteLine(string.Format("Attempted to remove {0} from the crew list, but didn't find them as an available crew.", Ship1Name));
                }

                try
                {
                    crew.GenCrew.Remove(Ship2Name);
                }
                catch
                {
                    Console.WriteLine(string.Format("Attempted to remove {0} from the crew list, but didn't find them as an available crew.", Ship2Name));
                }

                try
                {
                    crew.GenCrew.Remove(Ship3Name);
                }
                catch
                {
                    Console.WriteLine(string.Format("Attempted to remove {0} from the crew list, but didn't find them as an available crew.", Ship3Name));
                }


                dict = crew.GenCrew;
                Random rand = new Random();
                numbers = new[] { 1, 2, 3, 4, 5 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    UniqueList unique = new UniqueList();
                    if (unique.UniqueVar.Contains(upgradeName))
                    {
                        crew.GenCrew.Remove(upgradeName);
                    }
                    continue;
                }
            }
            else if (upgradeType.Contains("Missile"))
            {
                Missile missile = new Missile();

                dict = missile.MissileUpgrade;
                Random rand = new Random();
                numbers = new[] { 1, 3, 4, 5 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("SalvagedAstromech"))
            {
                SalvagedAstromech astromech = new SalvagedAstromech();

                dict = astromech.SalvagedAstromechs;
                Random rand = new Random();
                numbers = new[] { 0, 1, 2, 3 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("System"))
            {
                Systems system = new Systems();

                dict = system.SystemsUpgrade;
                Random rand = new Random();
                numbers = new[] { 0, 1, 2, 3, 4 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("Modification"))
            {
                Modification modification = new Modification();

                dict = modification.Modifications;
                Random rand = new Random();
                numbers = new[] { 0, 1, 2, 3, 4 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }
            else if (upgradeType.Contains("Bomb"))
            {
                Bombs bomb = new Bombs();

                dict = bomb.BombUpgrades;
                Random rand = new Random();
                numbers = new[] { 2, 3, 4, 5 };
                shuffle = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First();
                foreach (var weapon in randomDictionary.RandomValues(dict, shuffle).Take(1))
                {
                    upgradeName = weapon;
                    continue;
                }
            }

            dict = new Dictionary <string, int>();
            dict.Add(upgradeName, shuffle);
            return(dict);
        }