Beispiel #1
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("Before the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe) + Environment.NewLine;
            //Console.WriteLine("Before the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe);
            if ((rnd.Next(0, 100)%2) == 0)//Player.this strikes first
            {
                int i = 0;
                log += "Player strikes first" + Environment.NewLine;
                //Console.WriteLine("Player strikes first");
                //insert while
                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!" + Environment.NewLine;
                            //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!" + Environment.NewLine;
                                //Console.WriteLine("Enemy blocks the attack!");
                            }
                            tmphpe = tmphpe - tmpap;
                            log += string.Format("Player hits for {0:0.00}!", tmpap) + Environment.NewLine;
                            //Console.WriteLine("Player hits for {0:0.00}!", tmpap);
                        }else
                            log += "Enemy evaded the attack!" + Environment.NewLine;
                        //Console.WriteLine("Enemy evaded the attack!");
                    } else
                        log += "Player misses the target!" + Environment.NewLine;
                    //Console.WriteLine("Player misses the target!");
                    if (tmphpe <= 0) {
                        log += string.Format("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe) + Environment.NewLine;
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1}", 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!" + Environment.NewLine;
                            //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!" + Environment.NewLine;
                                //Console.WriteLine("Player blocks the attack!");
                            }
                            tmphp = tmphp - tmpape;
                            log += string.Format("Enemy hits for {0:0.00}!", tmpape) + Environment.NewLine;
                            //Console.WriteLine("Enemy hits for {0:0.00}!", tmpape);
                        } else
                            log += "Player evaded the attack!" + Environment.NewLine;
                        //Console.WriteLine("Player evaded the attack!");
                    } else
                        log += "Enemy misses the target!" + Environment.NewLine;
                    //Console.WriteLine("Enemy misses the target!");
                    if (tmphp <= 0) {
                        log += string.Format("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe) + Environment.NewLine;
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe);
                        return false;
                    }
                    tmpap = ap;
                    tmpape = enemy.ap;
                    i++;
                    log += string.Format("My hp={0:0.00}, enemy hp={1}, i={2}", tmphp, tmphpe, i) + Environment.NewLine;
                    //Console.WriteLine("My hp={0:0.00}, enemy hp={1}, i={2}", tmphp, tmphpe, i);
                }

            }
            else//Enemy strikes first
            {
                log += "Enemy strikes first" + Environment.NewLine;
                //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!" + Environment.NewLine;
                            //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!" + Environment.NewLine;
                                //Console.WriteLine("Player blocks the attack!");
                            }
                            tmphp = tmphp - tmpape;
                            log += string.Format("Enemy hits for {0:0.00}!", tmpape) + Environment.NewLine;
                            //Console.WriteLine("Enemy hits for {0:0.00}!", tmpape);
                        }
                        else
                            log += "Player evaded the attack!" + Environment.NewLine;
                        //Console.WriteLine("Player evaded the attack!");
                    }
                    else
                        log += "Enemy misses the target!" + Environment.NewLine;
                    //Console.WriteLine("Enemy misses the target!");
                    if (tmphp <= 0) {
                        log += string.Format("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe) + Environment.NewLine;
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1}", 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!" + Environment.NewLine;
                            //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!" + Environment.NewLine;
                                //Console.WriteLine("Enemy blocks the attack!");
                            }
                            tmphpe = tmphpe - tmpap;
                            log += string.Format("Player hits for {0:0.00}!", tmpap) + Environment.NewLine;
                            //Console.WriteLine("Player hits for {0:0.00}!", tmpap);
                        }
                        else
                            log += "Enemy evaded the attack!" + Environment.NewLine;
                        //Console.WriteLine("Enemy evaded the attack!");
                    }
                    else
                        log += "Player misses the target!" + Environment.NewLine;
                    //Console.WriteLine("Player misses the target!");
                    if (tmphpe <= 0) {
                        log += string.Format("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe) + Environment.NewLine;
                        //Console.WriteLine("After the fight: My hp={0:0.00}, enemy hp={1}", tmphp, tmphpe);
                        return true;
                    }
                    tmpap = ap;
                    tmpape = enemy.ap;
                    i++;
                    log += string.Format("My hp={0:0.00}, enemy hp={1}, i={2}", tmphp, tmphpe, i) + Environment.NewLine;
                    //Console.WriteLine("My hp={0:0.00}, enemy hp={1}, i={2}", tmphp, tmphpe, i);
                }
            }
            if (tmphpe <= 0)
            {
                Console.WriteLine("Abnormal return true");
                return true;
            }
            else
            {
                Console.WriteLine("Abnormal return false");
                return false;
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     char pressanykey;
     double a = 80, b = 6, c = 60;
     double a2 = 98, b2 = 8, c2 = 0;
     int d = 2;
     //Gladiator enemy = new Gladiator(d);
     Gladiator enemy = new Gladiator(a2, b2, c2);
     Gladiator player = new Gladiator(a, b, c);
     bool result;
     string resultmsg = "Empty", log = "empty";
     result = player.battle(enemy);
     log = player.GetLog();
     if (result)
         resultmsg = "You win!";
     else
         resultmsg = "You lose!";
     Console.WriteLine(log + resultmsg);
     pressanykey = (char)Console.Read();
 }