Exemplo n.º 1
0
        public static bool Search(SocketUser user)
        {
            WorldAccount a = WorldStorage.GetAccount(user);

            Queue <Unit> scoutsA = new Queue <Unit>();

            foreach (Unit u in a.units)
            {
                if (u.Class == "warrior")
                {
                    scoutsA.Enqueue(u);
                }
            }

            if (scoutsA.Count() > 0)
            {
                Random random = new Random();
                if (random.Next(0, 100) >= 75)
                {
                    a.Gold += 5;
                }
                WorldStorage.UpdateInfo(user);
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public static string Buy(SocketUser user, string unit)
        {
            WorldAccount a = WorldStorage.GetAccount(user);

            if (unit == "cleric" && a.Gold >= 10)
            {
                a.units.Add(new Cleric());
                a.Gold -= 10;
                WorldStorage.UpdateInfo(user);
                return("Cleric unit purchased");
            }
            else if (unit == "warrior" && a.Gold >= 10)
            {
                a.units.Add(new Warrior());
                a.Gold -= 10;
                WorldStorage.UpdateInfo(user);
                return("Warrior unit purchased");
            }
            else if (unit == "scout" && a.Gold >= 10)
            {
                a.units.Add(new Scout());
                a.Gold -= 10;
                WorldStorage.UpdateInfo(user);
                return("Scout unit purchased");
            }

            return($"Not enough gold for {unit}. {a.Gold}/10 gold.");
        }
Exemplo n.º 3
0
        public static string Fight(SocketUser fighter1, SocketUser fighter2)
        {
            WorldAccount a = WorldStorage.GetAccount(fighter1);
            WorldAccount b = WorldStorage.GetAccount(fighter2);

            //! Mapless fighting;
            Queue <Unit> warriorsA = new Queue <Unit>();
            Queue <Unit> warriorsB = new Queue <Unit>();

            foreach (Unit u in a.units)
            {
                if (u.Class == "warrior")
                {
                    warriorsA.Enqueue(u);
                }
            }

            foreach (Unit u in b.units)
            {
                if (u.Class == "warrior")
                {
                    warriorsB.Enqueue(u);
                }
            }

            if (warriorsA.Count() > 0 && warriorsB.Count() > 0)
            {
                //! Warriors fight warriors
                warriorsB.Peek().HP -= 1;
                if (warriorsB.Peek().HP <= 0)
                {
                    warriorsB.Dequeue(); //! Remove dead warrior

                    WorldStorage.UpdateInfo(fighter1);
                    WorldStorage.UpdateInfo(fighter2);

                    return($"{fighter1.Username} took out {fighter2.Username}'s warrior!");
                }

                WorldStorage.UpdateInfo(fighter1);
                WorldStorage.UpdateInfo(fighter2);

                return($"{fighter1.Username} attacked {fighter2.Username}'s warrior!");
            }
            else if (warriorsA.Count() > 0 && warriorsB.Count() == 0)
            {
                //! a warrior attack b base
                b.units[0].HP -= 1;

                WorldStorage.UpdateInfo(fighter1);
                WorldStorage.UpdateInfo(fighter2);

                return($"{fighter1.Username} attacks {fighter2.Username}'s base!");
            }
            else if (warriorsA.Count() == 0 && warriorsB.Count() > 0)
            {
                //! b warrior attack a base
                //! This case is because playerA tried attacking w/ no one to attack with.
                a.units[0].HP -= 1;

                WorldStorage.UpdateInfo(fighter1);
                WorldStorage.UpdateInfo(fighter2);

                return($"{fighter2.Username} attacks {fighter1.Username}'s base!");
            }
            //! Both have 0
            return("Neither player can attack, need to purchase warriors!");
        }