Пример #1
0
        // attack another jedi knight with the help of magic random numbers
        public void AttackEnemy(JediKnight jediKnight, JediKnight opponent)
        {
            try
            {
                // set up an attack using a standard lightsaber action, registering opponent's resulting damage level, and slandering him
                if (opponent.currentDamageLevel == DamageLevel.Wasted)
                {
                    // He's already finito.. see if we can make him join the game again!
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " takes a poke trying to off " + opponent.Name + " who is already at the Rigor Mortis stage. Tsk, tsk.. a bit necro-phixated, are we?");
                    // Rescusiate..
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " gets all squishy-feely at seeing " + opponent.Name + " so horribly pale, and takes him - ok, drags him.. along to the Jawa sandcrawler for recycling.");
                    opponent.currentDamageLevel = DamageLevel.Critical;
                    opponent.Deceased = false;
                    jediKnight.fightLog.FightEvents.Add(opponent.Name + " didn't bring in much of a recycle fee for " + jediKnight.Name + " - but the Jawas were real nice. Our hero was kicked out in the desert again alive, minus only a few insignificant internal body parts and sporting a damage level of: "
                            + opponent.currentDamageLevel);
                }
                else
                {
                    RandomGenerator ranGen = new Helpers.RandomGenerator();
                    int randomInt = ranGen.RandomInteger(10);
                    // record which lightsaber maneouver was randomly chosen
                    currentLightSaberAction = (LightSaberAction)randomInt;
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " attacks " + opponent.Name
                                             + " by deftly applying the Light Saber Academy approved maneouver "
                                             + currentLightSaberAction);

                    // Make a stab using the current DamageLevel cast to an int. Record which new damage level resulted from the attack.
                    System.Threading.Thread.Sleep(500); // skip a heartbeat here, so we get a new random seed number
                    randomInt = ranGen.RandomInteger((int)(opponent.currentDamageLevel));
                    // Series of if statements, to determine which damage level is closest to the generated number
                    if (randomInt >= 50)
                        opponent.currentDamageLevel = DamageLevel.Healthy;
                    else if (randomInt < 50 && randomInt > 25)
                        opponent.currentDamageLevel = DamageLevel.Challenged;
                    else if (randomInt <= 25 && randomInt > 10)
                        opponent.currentDamageLevel = DamageLevel.Critical;
                    else // less than or equal to 10, we's long gone dude
                    {
                        opponent.currentDamageLevel = DamageLevel.Wasted;
                        opponent.Deceased = true;
                    }

                    jediKnight.fightLog.FightEvents.Add(opponent.Name + " now has a damage level of: " + opponent.currentDamageLevel + " based on a randomInt of " + randomInt);

                    // Pick a random slander expression for posterity, except if he is dead as a result of that last attack of yours.
                    if (opponent.currentDamageLevel > DamageLevel.Wasted)
                    {
                        randomInt = ranGen.RandomInteger(enemySlanders.Length, 0);
                        string slander = enemySlanders[randomInt];
                        jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " says: " + slander);
                    }
                    else if (opponent.currentDamageLevel == DamageLevel.Wasted)
                    {
                        jediKnight.fightLog.FightEvents.Add(opponent.Name + " hoarsely whispers: " + opponent.LastWords);
                        jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " says: Rest in pieces, " + opponent.Name + ".");
                        jediKnight.fightLog.FightEvents.Add(opponent.Name + " has bought the big farm in the sky.");
                    }
                }
            }
            catch (Exception e)
            {
                // TODO: log the exception
                string msg = e.Message;
            }
        }
        // public ViewResult RecruitForm(JediKnight jediKnight)
        public ViewResult RecruitForm(ThePlayer newWarrior)
        {
            // check user input
            if (ModelState.IsValid)
            {
                // Set up a game log of Fight Events
                AttackRecorder gameLog = new AttackRecorder();
                gameLog.FightEvents = new List<string>() { "..the game log was the only book in town that the Evil Emperor wanted to read." };

                // Set up a Jedi Warrior object - using the data entered in the form
                ThePlayer myWarrior = new ThePlayer();
                myWarrior.Name = newWarrior.Name;
                myWarrior.Email = newWarrior.Email;
                myWarrior.LightSaberColor = newWarrior.LightSaberColor;
                myWarrior.currentDamageLevel = JediKnight.DamageLevel.Healthy;
                myWarrior.DarkSide = newWarrior.DarkSide;
                myWarrior.Deceased = false;
                myWarrior.fightLog = new AttackRecorder();

                // Init the personal fight log
                myWarrior.fightLog.FightEvents = new List<string>()
	            {
	                myWarrior.Name + " loosens his tie",
	                myWarrior.Name + " unstraps his lightsaber and admires it's wonderfully " + myWarrior.LightSaberColor + " sheen.",
	                myWarrior.Name + " quotes Caesar: 'Jacta Alea Est', dude!",
                    myWarrior.Name + " shuffles his feet and looks a bit shyly at the other guys.. quite imposing figures, actually.."
	            };
                // start up first knight in game log
                gameLog.FightEvents.AddRange(myWarrior.fightLog.FightEvents);

                // Set up some more Jedi objects
                Darth DarthV = new Darth();
                // start up second knight in game log
                gameLog.FightEvents.AddRange(DarthV.fightLog.FightEvents);

                Luke LukeS = new Luke();
                // start up third knight in game log
                gameLog.FightEvents.AddRange(LukeS.fightLog.FightEvents);

                EvilEmperor Palpatine = new EvilEmperor();
                gameLog.FightEvents.Add(Palpatine.Encouragement);
                gameLog.FightEvents.Add(Palpatine.Chew);

                List<JediKnight> myJedis = new List<JediKnight>();
                myJedis.Add(myWarrior);
                myJedis.Add(DarthV);
                myJedis.Add(LukeS);

                RandomGenerator ranGen = new Helpers.RandomGenerator();

                // Now, let's run a battle scenario umpteen times over, based on the logic in the model for each Knight.
                // That ought to be enough to kill one of our protagonists outright a few times over..
                for (int i = 1; i < 18; i++)
                {
                    // Pick a random Jedi Knight to kick into action                
                    int randomInt = ranGen.RandomInteger(myJedis.Count() - 1, 0);
                    JediKnight warrior = myJedis[randomInt];
                    Palpatine.DarkSideBoost(myJedis);
                    // Empty the individual fight log before next batch recording of events
                    warrior.fightLog.FightEvents.Clear();
                    warrior.fightLog.FightEvents.Add("The Evil Emperor randomly points a bony finger at " + warrior.Name + " and says: 'do some nasty work for me - now!'");

                    

                    while (Palpatine.PickJediKnight(myJedis, randomInt) == null)
                    {
                        randomInt = ranGen.RandomInteger(myJedis.Count);
                    }
                    // Attack opponents, but only if they are on the opposing side, and only if you aren't dead yourself..yet.                                      
                    switch (warrior.Name)
                    {

                        case "Darth Vader":
                            if (!warrior.Deceased)
                            {
                                warrior.AttackEnemy(warrior, LukeS);
                                if (myWarrior.DarkSide == false) { warrior.AttackEnemy(warrior, myWarrior); }
                            }
                            else // this happens if the Emperor points a bony finger at a dead Jedi Knight
                            {
                                warrior.fightLog.FightEvents.Add(warrior.Name + " unfortunately feels a bit out of it right now, and is rather actively knockin' on the Force's Door.");
                                // Darth is a mean ole bean, so we'll re-life him with a lousy medicare allowance of 'Hurting'
                                warrior.Deceased = false;
                                warrior.currentDamageLevel = JediKnight.DamageLevel.Hurting;
                                warrior.fightLog.FightEvents.Add("Wow, that door-mojo worked... " + warrior.Name + " is in a rather hurt condition, but still bouncing back for some mean ole revenge!");
                            }
                            // add player fight events to game log
                            gameLog.FightEvents.AddRange(warrior.fightLog.FightEvents);
                            break;

                        case "Luke Skywalker":
                            if (!warrior.Deceased)
                            {
                                warrior.AttackEnemy(warrior, DarthV);
                                if (myWarrior.DarkSide == true) { 
                                    warrior.AttackEnemy(warrior, myWarrior);
                                    //ObiWan.SaveLuke(warrior);
                                    

                                }
                            }
                            else
                            {
                                warrior.fightLog.FightEvents.Add(warrior.Name + " unfortunately feels a bit out of it right now, and is feebly knockin' on the Force's Door, in a Lukey way.");
                                // give Luke an advantage when killed, by rescusiating him and by setting his health to max
                                warrior.Deceased = false;
                                warrior.currentDamageLevel = JediKnight.DamageLevel.Healthy;
                                warrior.fightLog.FightEvents.Add(warrior.Name + " apparently has mucho clout with the Force's Door and is now bouncing back for some swashbuckling revenge!");
                            }
                            // add player fight events to game log
                            
                            gameLog.FightEvents.AddRange(warrior.fightLog.FightEvents);
                            break;

                        // default case will be our guy on the dance floor wanting a serious piece of the action
                        default:
                            if (!warrior.Deceased)
                            {
                                if (warrior.DarkSide == false) { warrior.AttackEnemy(warrior, DarthV); }
                                if (warrior.DarkSide == true) { warrior.AttackEnemy(warrior, LukeS); }
                                
                            }
                            else
                            {
                                warrior.fightLog.FightEvents.Add(warrior.Name + " unfortunately feels a bit out of it right now, and is knockin' on the Force's Door.");
                                warrior.Deceased = false;
                                warrior.currentDamageLevel = JediKnight.DamageLevel.Challenged;
                                warrior.fightLog.FightEvents.Add(warrior.Name + " apparently has some clout with the Force's Door and is now bent on some challenged-level revenge!");
                               
                            }
                            // add player fight events to game log
                            gameLog.FightEvents.AddRange(warrior.fightLog.FightEvents);
                            break;
                    }
                }
                    
                    // Conclude fight at this point - check who's still vital, and do the victory roll
                    foreach (JediKnight warrior in myJedis)
                    {
                        
                        if (!warrior.Deceased)
                        {
                            Logging logTxt = new Helpers.Logging();
                            logTxt.Main("Alive");
                           
                            gameLog.FightEvents.Add("Ho ho ho! " + warrior.Name + "'s still around, with a rude health of: " + warrior.currentDamageLevel);
                            gameLog.FightEvents.Add(warrior.Name + " has died " + warrior.numOfDeaths + " times");
                        }
                        else
                        {
                            Logging logTxt = new Helpers.Logging();
                            logTxt.Main("Dead");
                            gameLog.FightEvents.Add("Awww, " + warrior.Name + " is sleeping with the fishes!");
                            gameLog.FightEvents.Add(warrior.Name + " has died " + warrior.numOfDeaths + " times");
                        }
                    }

                // Outputs the overall winner at the end of the battle according to how many times he/she has died
                    int Winner = WinnerOfDeaths(myJedis);
                    gameLog.FightEvents.Add("The winner is: " + myJedis[Winner].Name);


                // Set up viewbag list of event strings
                ViewBag.FightDescription = new List<string> { "A long time ago in a galaxy far, far away...." };

                // put the game log contents into the ViewBag
                foreach (string FightEvent in gameLog.FightEvents)
                {
                    ViewBag.FightDescription.Add(FightEvent);
                }

                return View("Jedi_Vs_Sith", myWarrior);
            }
            else
            {
                // validation error - redisplay form with error messages
                return View();
            }

        }
Пример #3
0
        // attack another jedi knight with the help of magic random numbers       
        public void AttackEnemy(JediKnight jediKnight, JediKnight opponent)
        {
            try
            {

                //MailMessage mail = new MailMessage();
                //mail.To.Add("*****@*****.**");
                //mail.From = new MailAddress("*****@*****.**");
                //mail.Subject = "Email using Gmail form our game";

                //string Body = "Hi, this mail is to test sending mail" +
                //            "using Gmail in ASP.NET";
                //mail.Body = Body;

                //mail.IsBodyHtml = true;
                //SmtpClient smtp = new SmtpClient("smtp.gmail.com", 465);
                //smtp.EnableSsl = true;
                //smtp.Credentials = new System.Net.NetworkCredential("email", "pass");
                //smtp.Send(mail);

                // set up an attack using a standard lightsaber action, registering opponent's resulting damage level, and slandering him                
                if (opponent.currentDamageLevel == DamageLevel.Wasted)
                {   
                    // He's already finito.. see if we can make him join the game again!
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " takes a poke trying to off " + opponent.Name + " who is already at the Rigor Mortis stage. Tsk, tsk.. a bit necro-phixated, are we?");
                    // Rescusiate..
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " gets all squishy-feely at seeing " + opponent.Name + " so horribly pale, and takes him - ok, drags him.. along to the Jawa sandcrawler for recycling.");
                    opponent.currentDamageLevel = DamageLevel.Critical;
                    opponent.Deceased = false;
                    jediKnight.fightLog.FightEvents.Add(opponent.Name + " didn't bring in much of a recycle fee for " + jediKnight.Name + " - but the Jawas were real nice. Our hero was kicked out in the desert again alive, minus only a few insignificant internal body parts and sporting a damage level of: "
                            + opponent.currentDamageLevel);
                }
                else
                {
                    //Get the instance of the log class
                    Logging logTxt = new Helpers.Logging();

                    RandomGenerator ranGen = new Helpers.RandomGenerator();
                    int randomInt = ranGen.RandomInteger(10);
                    // record which lightsaber maneouver was randomly chosen
                    currentLightSaberAction = (LightSaberAction)randomInt;
                    jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " attacks " + opponent.Name
                                             + " by deftly applying the Light Saber Academy approved maneouver "
                                             + currentLightSaberAction);

                    if (currentLightSaberAction == LightSaberAction.Pierce_Enemy_Chest)
                    {
                        jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " scored a hole-in " + opponent.Name
                                             + " by Piercing the Enemy Chest");

                        opponent.currentDamageLevel = DamageLevel.Wasted;

                        //Log action in the log file
                        logTxt.Main(jediKnight.Name + " killed " + opponent.Name + " by Piercing his chest");
                    }

                    // Make a stab using the current DamageLevel cast to an int. Record which new damage level resulted from the attack.
                    System.Threading.Thread.Sleep(1000); // skip a heartbeat here, so we get a new random seed number
                    randomInt = ranGen.RandomInteger((int)(opponent.currentDamageLevel));

                    logTxt.Main("Jedi Knight random health level is: " + randomInt);

                    // Series of if statements, to determine which damage level is closest to the generated number
                    if (randomInt >= 50)
                        opponent.currentDamageLevel = DamageLevel.Healthy;
                    else if (randomInt < 50 && randomInt > 25)
                        opponent.currentDamageLevel = DamageLevel.Challenged;
                    else if (randomInt <= 25 && randomInt > 10)
                        opponent.currentDamageLevel = DamageLevel.Critical;
                    else // less than or equal to 10, we's long gone dude
                    {
                        opponent.currentDamageLevel = DamageLevel.Wasted;
                        opponent.Deceased = true;
                        jediKnight.numOfDeaths++;
                    }

                    jediKnight.fightLog.FightEvents.Add(opponent.Name + " now has a damage level of: " + opponent.currentDamageLevel + " based on a randomInt of " + randomInt);

                    // Pick a random slander expression for posterity, except if he is dead as a result of that last attack of yours.
                    if (opponent.currentDamageLevel > DamageLevel.Wasted)
                    {
                        randomInt = ranGen.RandomInteger(enemySlanders.Length - 1);
                        string slander = enemySlanders[randomInt];
                        jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " says: " + slander);
                        
                    }
                    else if (opponent.currentDamageLevel == DamageLevel.Wasted)
                    {
                        if (opponent.Name == "Luke Skywalker")
                        {
                            Obi_Wan ObiWan = new Obi_Wan();
                            jediKnight.fightLog.FightEvents.Add(ObiWan.Encouragement);
                            jediKnight.fightLog.FightEvents.Add(ObiWan.Dismay);
                            ObiWan.SaveLuke(opponent);
                            logTxt.Main("Obi-Wan helps Luke Skywalker regain his health");
                            jediKnight.fightLog.FightEvents.Add(opponent.Name + " now has a damage level of: " + opponent.currentDamageLevel);
                        }
                        else
                        {
                            jediKnight.fightLog.FightEvents.Add(opponent.Name + " hoarsely whispers: " + opponent.LastWords);
                            jediKnight.fightLog.FightEvents.Add(jediKnight.Name + " says: Rest in pieces, " + opponent.Name + ".");
                            jediKnight.fightLog.FightEvents.Add(opponent.Name + " has bought the big farm in the sky.");
                        }
                        opponent.numOfDeaths++;
                        logTxt.Main(opponent.Name + " has died " + opponent.numOfDeaths + " times");
                        logTxt.Main(jediKnight.Name + " has died " + jediKnight.numOfDeaths + " times");
                    }

                }
            }
            catch (Exception e)
            {
                // TODO: log the exception
                string msg = e.Message;
            }
        }