示例#1
0
        public static Random rnd = new Random(); //this determines which warrior takes the first turn

        #endregion Fields

        #region Methods

        public bool aliveCheck(Warrior warr)
        {
            if(warr.isAlive == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
示例#2
0
        public static Random fightAttack = new Random();   //generates random number for how big the hit will be on this fighter's turn



        /// <summary>
        ///
        /// This method is used to accept 2 objects of the warrior class, allow them to fight to the death, and return the winner warrior
        ///
        /// </summary>
        /// <param name="fighter1"></param>
        /// <param name="fighter2"></param>
        /// <returns></returns>
        public List <string> fight(Warrior fighter1, Warrior fighter2)
        {
            //Here I use an array of the warrior class so I can programatically refer to each warrior since its up in the air who's turn it will be
            Warrior[] fightersArray = new Warrior[3];
            var       fightEvents   = new List <string>();

            fightersArray[1] = fighter1;
            fightersArray[2] = fighter2;

            int firstTurn;
            int currentTurn;
            int notTurn;
            int hit;                      //attack damage on hit

            firstTurn   = rnd.Next(1, 3); //this randomly will decide which warrior takes the first turn
            currentTurn = firstTurn;      //For the first round currentTurn will be whoever wins first attack coin toss



            //this is where the loop starts for the 2 soldiers to battle to the DEATH!!!
            do
            {
                //making sure notTurn is opposite of current turn
                if (currentTurn == 1)
                {
                    notTurn = 2;
                }
                else
                {
                    notTurn = 1;
                }


                //Determine how big the hit will be
                //this random will generate a hit between 0 and whatever the fighter's strength is
                hit = fightAttack.Next(0, fightersArray[currentTurn].strength + 1);

                //Attack
                fightersArray[notTurn].health -= hit;

                //Output string representing the hit
                //using a switch statement to handle different cases
                switch (hit)
                {
                case 0:

                    fightEvents.Add(fightersArray[currentTurn].name + " missed cause he's a big huge NOOB HEHEHEHE! ");
                    break;

                case 1 - 2:
                    fightEvents.Add(fightersArray[currentTurn].name + " hit " + fightersArray[notTurn].name + " for a measly " + Convert.ToString(hit) + " points of damage");
                    break;

                default:
                    fightEvents.Add(fightersArray[currentTurn].name + " hit " + fightersArray[notTurn].name + " right in the face for " + Convert.ToString(hit) + " points of damage");
                    break;
                }

                //Switch Turns
                currentTurn = notTurn;       //This sets current turn to what notTurn was..notTurn will be set at the top of the loop to the opposite

                //Checks if one of the fighters died
                if (fighter1.health <= 0)
                {
                    fightEvents.Add("-----------------------" + fighter1.name + " IS DEAD!! XD XD XD XD XD" + "-----------------------");
                    fighter1.isAlive = false;
                }
                else if (fighter2.health <= 0)
                {
                    fightEvents.Add("----------------------- " + fighter2.name + " IS DEAD!! XD XD XD XD XD" + "-----------------------");
                    fighter2.isAlive = false;
                }
            } while (fighter1.health > 0 && fighter2.health > 0);

            return(fightEvents);
        }//end fight method
示例#3
0
        /// <summary>
        /// 
        /// This method is used to accept 2 objects of the warrior class, allow them to fight to the death, and return the winner warrior
        /// 
        /// </summary>
        /// <param name="fighter1"></param>
        /// <param name="fighter2"></param>
        /// <returns></returns>
        public List<string> fight(Warrior fighter1, Warrior fighter2)
        {
            //Here I use an array of the warrior class so I can programatically refer to each warrior since its up in the air who's turn it will be
            Warrior[] fightersArray = new Warrior[3];
            var fightEvents = new List<string>();
            fightersArray[1] = fighter1;
            fightersArray[2] = fighter2;

            int firstTurn;
            int currentTurn;
            int notTurn;
            int hit;                //attack damage on hit

            firstTurn = rnd.Next(1, 3);     //this randomly will decide which warrior takes the first turn
            currentTurn = firstTurn;        //For the first round currentTurn will be whoever wins first attack coin toss

            //this is where the loop starts for the 2 soldiers to battle to the DEATH!!!
            do
            {
                //making sure notTurn is opposite of current turn
                if (currentTurn == 1)
                {
                    notTurn = 2;
                }
                else
                {
                    notTurn = 1;
                }

                //Determine how big the hit will be
                //this random will generate a hit between 0 and whatever the fighter's strength is
                hit = fightAttack.Next(0, fightersArray[currentTurn].strength + 1);

                //Attack
                fightersArray[notTurn].health -= hit;

                //Output string representing the hit
                //using a switch statement to handle different cases
                switch (hit)
                {
                    case 0:

                        fightEvents.Add(fightersArray[currentTurn].name + " missed cause he's a big huge NOOB HEHEHEHE! ");
                        break;

                    case 1 - 2:
                        fightEvents.Add(fightersArray[currentTurn].name + " hit " + fightersArray[notTurn].name + " for a measly " + Convert.ToString(hit) + " points of damage");
                        break;

                    default:
                        fightEvents.Add(fightersArray[currentTurn].name + " hit " + fightersArray[notTurn].name + " right in the face for " + Convert.ToString(hit) + " points of damage");
                        break;
                }

                //Switch Turns
                currentTurn = notTurn;       //This sets current turn to what notTurn was..notTurn will be set at the top of the loop to the opposite

                //Checks if one of the fighters died
                if(fighter1.health <= 0)
                {
                    fightEvents.Add("-----------------------" + fighter1.name + " IS DEAD!! XD XD XD XD XD" + "-----------------------");
                    fighter1.isAlive = false;
                }
                else if(fighter2.health <= 0)
                {
                    fightEvents.Add("----------------------- " + fighter2.name + " IS DEAD!! XD XD XD XD XD" + "-----------------------");
                    fighter2.isAlive = false;
                }

            } while (fighter1.health > 0 && fighter2.health > 0);

            return fightEvents;
        }