Пример #1
0
        static void Main(string[] args)
        {
            List <Employee> empl = new List <Employee>();

            empl.Add(new Employee()
            {
                ID = 101, Name = "Brad", salary = 20000, Experiance = 13
            });
            empl.Add(new Employee()
            {
                ID = 102, Name = "John", salary = 30000, Experiance = 4
            });
            empl.Add(new Employee()
            {
                ID = 103, Name = "Suzan", salary = 50000, Experiance = 8
            });
            empl.Add(new Employee()
            {
                ID = 104, Name = "Mike", salary = 10000, Experiance = 2
            });

            //Using delegate business logic got separated from employee class which makes code reusable.

            //Creating an instance of delegate
            isPromote pro = new isPromote(promote);

            //Calling PromoteEmp function with passing the employee list and the delegate
            Employee.PromoteEmp(empl, pro);

            //multi cast delegate example
            strDele delobj = new strDele(uppercasestr);  //method reference 1

            Console.WriteLine(delobj("Thank You"));
            delobj += new strDele(Lowercasestr);  //method reference 2
            Console.WriteLine(delobj("Thank You"));
        }
Пример #2
0
    public void onClickGetBonus()
    {
        strDele fun = new strDele(showMessage);

        bonusCode.analyzeCode(bonusCodeInput.text, fun);
    }
Пример #3
0
    public static void analyzeCode(string code, strDele fun)
    {
        if (dataset.Count == 0)
        {
            parseCode();    //parsing code
            //getList();
        }
        if (code == null || code == "" || !dataset.ContainsKey(code))
        {
            fun.Invoke("Invalid Code.", "Error!");
            return;
        }

        if (player.Incre.usedCode.Contains(code))
        {
            fun.Invoke("You have already used this code.", "Error!");
            return;
        }

        //=========developer -------------//
        if (code == "money")
        {
            fun.Invoke("Great Job on Class work!", "1000 Money Added!");
            player.Incre.coin.active  += 1000;
            player.Incre.coin.passive += 1000;
        }
        if (code == "time")
        {
            fun.Invoke("Great Job on Class work!", "time Added!");
            player.Incre.timeleft.cur += 60 * 10;
        }
        if (code == "stamina")
        {
            fun.Invoke("Great Job on Class work!", "stamina Added!");
            player.Incre.stamina.cur++;
        }


        string reward = "";

        dataset.TryGetValue(code, out reward);
        //============= player ==================//
        if (reward == "money")
        {
            fun.Invoke((bal.getPassiveCoinBonus() * 10).ToString() + "You gained Passive Coin and " + (bal.getActiveCoinBonus() * 10).ToString() + " Active Coin. ", "Great Job on Class work!");
            player.Incre.coin.passive += (bal.getPassiveCoinBonus() * 10);
            player.Incre.coin.active  += (bal.getActiveCoinBonus() * 10);
        }
        if (reward == "time")
        {
            //add 10 minutes
            player.Incre.timeleft.cur += 60 * 10;
            fun.Invoke("You gained extra 10 minutes play time!", "Great Job on Class work!");
        }
        if (reward == "item")
        {
            player.Incre.coin.numBooster     += 2;
            player.Incre.exp.numBooster      += 2;
            player.Incre.progress.numBooster += 2;
            fun.Invoke("You gained 2 of each booster items!", "Great Job on Class work!");
        }
        if (reward == "stamina")
        {
            //add 5 more stamina
            player.Incre.stamina.cur += 5;
            fun.Invoke("You gained 5 extra stamina!", "Great Job on Class work!");
        }
        player.Incre.usedCode.Add(code);
    }