Exemple #1
0
 public HttpResponseMessage FightPVP([FromUri]string login, [FromUri]double a, [FromUri]double b, [FromUri]double c)
 {
     AzureQueue queue = new AzureQueue();
     if (queue.PeekMsg(true))
     {
         bool result;
         string resultmsg = "33", resultopmsg = "33";
         CloudQueueMessage opponent = queue.deQueueMsg(true);
         string[] words = opponent.AsString.Split(new Char[] { ' ' });
         int enemyA = Int32.Parse(words[1]);
         int enemyB = Int32.Parse(words[2]);
         int enemyC = Int32.Parse(words[3]);
         Gladiator player = new Gladiator(a, b, c);
         Gladiator enemy = new Gladiator(enemyA, enemyB, enemyC);
         result = player.battle(enemy);
         azureTable user = new azureTable();
         if (result)
         {
             resultmsg = "01" + login + " vs " + words[0] + "NL" + player.GetLog(true);// victory
             resultopmsg = "00" + player.GetLog(false);
         }
         else
         {
             resultmsg = "00" + login + " vs " + words[0] + "NL" + player.GetLog(true);// defeat
             resultopmsg = "01" + player.GetLog(false);
         }
         user.UpdateLvl(login, result);
         user.UpdateLvl(words[0], !result);
         queue.AddMsgQ(String.Format("{0}&{1}&{2}", words[0], login, resultopmsg), false);
         string xml = string.Format("{0}", resultmsg);
         HttpResponseMessage response = Request.CreateResponse();
         response.Content = new StringContent(xml, System.Text.Encoding.UTF8, "text/plain");
         return response;
     }
     else
     {
         queue.AddMsgQ(String.Format("{0} {1} {2} {3}", login, a, b, c), true);
         string xml = string.Format("03");//Looking for opponents
         HttpResponseMessage response = Request.CreateResponse();
         response.Content = new StringContent(xml, System.Text.Encoding.UTF8, "text/plain");
         return response;
     }
 }
Exemple #2
0
        public bool battle(Gladiator enemy)
        {
            Random rnd = new Random();
            double tmpap = ap, tmphp = hp;
            double tmpape = enemy.ap, tmphpe = enemy.hp;
            log = string.Format("1. My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe) + "NL";
            log2 = string.Format("1. My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp) + "NL";
            //Console.WriteLine("Before the fight: My hp={0:0.00}, enemy hp={1:0.00}", tmphp, tmphpe);
            if ((rnd.Next(0, 100) % 2) == 0)//Player.this strikes first
            {
                int i = 0;
                log += "Player strikes first" + "NL";
                log2 += "Enemy strikes first" + "NL";
                //Console.WriteLine("Player strikes first");
                while ((tmphp > 0) && (tmphpe > 0))
                {

                    if (rnd.Next(0, 100) >= miss * 100)
                    {
                        if (rnd.Next(0, 100) <= crit * 100)
                        {
                            tmpap = tmpap * xcrit;
                            log += "Player critically hits!" + "NL";
                            log2 += "Enemy critically hits!" + "NL";
                            //Console.WriteLine("Player critically hits!");
                        }
                        if (rnd.Next(0, 100) >= ev * 100)
                        {
                            if (rnd.Next(0, 100) <= block * 100)
                            {
                                tmpap = tmpap * xblock;
                                log += "Enemy blocks the attack!" + "NL";
                                log2 += "Player blocks the attack!" + "NL";
                                //Console.WriteLine("Enemy blocks the attack!");
                            }
                            tmphpe = tmphpe - tmpap;
                            log += string.Format("Player hits for {0:0.00}!", tmpap) + "NL";
                            log2 += string.Format("Enemy hits for {0:0.00}!", tmpap) + "NL";
                            //Console.WriteLine("Player hits for {0:0.00}!", tmpap);
                        }
                        else
                        {
                            log += "Enemy evaded the attack!" + "NL";
                            log2 += "Player evaded the attack!" + "NL";
                        }
                        //Console.WriteLine("Enemy evaded the attack!");
                    }
                    else
                    {
                        log += "Player misses the target!" + "NL";
                        log2 += "Enemy misses the target!" + "NL";
                    }
                    //Console.WriteLine("Player misses the target!");
                    if (tmphpe <= 0)
                    {
                        log += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe) + "NL";
                        log2 += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp) + "NL";
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1:0.00}", tmphp, tmphpe);
                        return true;
                    }
                    if (rnd.Next(0, 100) >= miss * 100)
                    {
                        if (rnd.Next(0, 100) <= enemy.crit * 100)
                        {
                            tmpape = tmpape * xcrit;
                            log += "Enemy critically hits!" + "NL";
                            log2 += "Player critically hits!" + "NL";
                            //Console.WriteLine("Enemy critically hits!");
                        }
                        if (rnd.Next(0, 100) >= ev * 100)
                        {
                            if (rnd.Next(0, 100) <= block * 100)
                            {
                                tmpape = tmpape * xblock;
                                log += "Player blocks the attack!" + "NL";
                                log2 += "Enemy blocks the attack!" + "NL";
                                //Console.WriteLine("Player blocks the attack!");
                            }
                            tmphp = tmphp - tmpape;
                            log += string.Format("Enemy hits for {0:0.00}!", tmpape) + "NL";
                            log2 += string.Format("Player hits for {0:0.00}!", tmpape) + "NL";
                            //Console.WriteLine("Enemy hits for {0:0.00}!", tmpape);
                        }
                        else
                        {
                            log += "Player evaded the attack!" + "NL";
                            log2 += "Enemy evaded the attack!" + "NL";
                        }
                        //Console.WriteLine("Player evaded the attack!");
                    }
                    else
                    {
                        log += "Enemy misses the target!" + "NL";
                        log2 += "Player misses the target!" + "NL";
                    }
                    //Console.WriteLine("Enemy misses the target!");
                    if (tmphp <= 0)
                    {
                        log += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe) + "NL";
                        log2 += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp) + "NL";
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1:0.00}", tmphp, tmphpe);
                        return false;
                    }
                    tmpap = ap;
                    tmpape = enemy.ap;
                    i++;
                    log += string.Format("{2}. My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe, i + 1) + "NL";
                    log2 += string.Format("{2}. My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp, i + 1) + "NL";
                    //Console.WriteLine("My hp={0:0.00}, enemy hp={1:0.00} Skirmish={2}", tmphp, tmphpe, i);
                }

            }
            else//Enemy strikes first
            {
                log += "Enemy strikes first" + "NL";
                log2 += "Player strikes first" + "NL";
                //Console.WriteLine("Enemy strikes first");
                int i = 0;
                while ((tmphp > 0) && (tmphpe > 0))
                {
                    if (rnd.Next(0, 100) >= miss * 100)
                    {
                        if (rnd.Next(0, 100) <= enemy.crit * 100)
                        {
                            tmpape = tmpape * xcrit;
                            log += "Enemy critically hits!" + "NL";
                            log2 += "Player critically hits!" + "NL";
                            //Console.WriteLine("Enemy critically hits!");
                        }
                        if (rnd.Next(0, 100) >= ev * 100)
                        {
                            if (rnd.Next(0, 100) <= block * 100)
                            {
                                tmpape = tmpape * xblock;
                                log += "Player blocks the attack!" + "NL";
                                log2 += "Enemy blocks the attack!" + "NL";
                                //Console.WriteLine("Player blocks the attack!");
                            }
                            tmphp = tmphp - tmpape;
                            log += string.Format("Enemy hits for {0:0.00}!", tmpape) + "NL";
                            log2 += string.Format("Player hits for {0:0.00}!", tmpape) + "NL";
                            //Console.WriteLine("Enemy hits for {0:0.00}!", tmpape);
                        }
                        else
                        {
                            log += "Player evaded the attack!" + "NL";
                            log2 += "Enemy evaded the attack!" + "NL";
                        }
                        //Console.WriteLine("Player evaded the attack!");
                    }
                    else
                    {
                        log += "Enemy misses the target!" + "NL";
                        log2 += "Player misses the target!" + "NL";
                    }
                    //Console.WriteLine("Enemy misses the target!");
                    if (tmphp <= 0)
                    {
                        log += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe) + "NL";
                        log2 += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp) + "NL";
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1:0.00}", tmphp, tmphpe);
                        return false;
                    }
                    if (rnd.Next(0, 100) >= miss * 100)
                    {
                        if (rnd.Next(0, 100) <= crit * 100)
                        {
                            tmpap = tmpap * xcrit;
                            log += "Player critically hits!" + "NL";
                            log2 += "Enemy critically hits!" + "NL";
                            //Console.WriteLine("Player critically hits!");
                        }
                        if (rnd.Next(0, 100) >= ev * 100)
                        {
                            if (rnd.Next(0, 100) <= block * 100)
                            {
                                tmpap = tmpap * xblock;
                                log += "Enemy blocks the attack!" + "NL";
                                log2 += "Player blocks the attack!" + "NL";
                                //Console.WriteLine("Enemy blocks the attack!");
                            }
                            tmphpe = tmphpe - tmpap;
                            log += string.Format("Player hits for {0:0.00}!", tmpap) + "NL";
                            log2 += string.Format("Enemy hits for {0:0.00}!", tmpap) + "NL";
                            //Console.WriteLine("Player hits for {0:0.00}!", tmpap);
                        }
                        else
                        {
                            log += "Enemy evaded the attack!" + "NL";
                            log2 += "Player evaded the attack!" + "NL";
                        }
                        //Console.WriteLine("Enemy evaded the attack!");
                    }
                    else
                    {
                        log += "Player misses the target!" + "NL";
                        log2 += "Enemy misses the target!" + "NL";
                    }
                    //Console.WriteLine("Player misses the target!");
                    if (tmphpe <= 0)
                    {
                        log += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe) + "NL";
                        log2 += string.Format("After the fight: My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp) + "NL";
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1:0.00}", tmphp, tmphpe);
                        return true;
                    }
                    tmpap = ap;
                    tmpape = enemy.ap;
                    i++;
                    log += string.Format("{2}. My hp={0:0.00} enemy hp={1:0.00}", tmphp, tmphpe, i+1) + "NL";
                    log2 += string.Format("{2}. My hp={0:0.00} enemy hp={1:0.00}", tmphpe, tmphp, i + 1) + "NL";
                    //Console.WriteLine("My hp={0:0.00}, enemy hp={1:0.00} Skirmish={2}", tmphp, tmphpe, i);
                }
            }
            if (tmphpe <= 0)
            {
                //Console.WriteLine("Abnormal return true");
                return true;
            }
            else
            {
                //Console.WriteLine("Abnormal return false");
                return false;
            }
        }
Exemple #3
0
 public HttpResponseMessage Fight([FromUri]string login, [FromUri]double a, [FromUri]double b, [FromUri]double c, [FromUri]int d)
 {
     Gladiator enemy = new Gladiator(d);
     Gladiator player = new Gladiator(a, b, c);
     bool result;
     string resultmsg = "33";
     result = player.battle(enemy);
     azureTable user = new azureTable();
     if (result)
     {
         resultmsg = "01" + player.GetLog(true);// victory
     }
     else
         resultmsg = "00" + player.GetLog(true);// defeat
     user.UpdateLvl(login, result);
     string xml = string.Format("{0}", resultmsg);
     HttpResponseMessage response = Request.CreateResponse();
     response.Content = new StringContent(xml, System.Text.Encoding.UTF8, "text/plain");
     return response;
 }