package{ import flash.display.*; //note: there is no L! FIGHT not FLIGHT! public class FightSimulator extends MovieClip{ //we're going to define our own objects! var someoneDied:Boolean = false; var fighter1Name:String = "Guan Yu"; var fighter2Name:String = "Xiahou Dun"; var attack1:int, attack2:int, defense1:int, defense2:int, health1:int, health2:int, damage1:int, damage2:int; //remember, this function has the same name as our document class //so it gets called automatically... we start here! public function FightSimulator(){ //this is a terrible way to do things //we'll see a much better way in coming weeks //and then an even better way after that attack1 = Math.floor(Math.random() * 10) + 1; attack2 = Math.floor(Math.random() * 10) + 1; defense1 = Math.floor(Math.random() * 10) + 1; defense2 = Math.floor(Math.random() * 10) + 1; damage1 = Math.floor(Math.random() * 10) + 1; damage2 = Math.floor(Math.random() * 10) + 1; health1 = Math.floor(Math.random() * 50) + 50; health2 = Math.floor(Math.random() * 50) + 50; var modAttack:int, modDefense:int, modDamage:int; var tabs:String = "\t\t\t\t\t\t\t\t\t\t"; //check the health of both fighters, we don't want any zombies while(health1 > 0 && health2 > 0){ trace("-----------------------------------------------------------------------"); trace("Name" + tabs + fighter1Name + tabs + fighter2Name); trace("Offense" + tabs + attack1 + tabs + attack2); trace("Damage" + tabs + damage1 + tabs + damage2); trace("Defense" + tabs + defense1 + tabs + defense2); trace("Health" + tabs + health1 + tabs + health2); trace("-----------------------------------------------------------------------"); //have the first guy attack modAttack = attack1 + Math.floor(Math.random() * 10) + 1; modDefense = defense2 + Math.floor(Math.random() * 10) + 1; if(modAttack > modDefense){ trace(fighter1Name + " hits " + fighter2Name + "!"); modDamage = damage1 + Math.floor(Math.random() * 10) + 1; if(modAttack > modDefense * 2){ trace("CRITICAL HIT!"); modDamage = modDamage * 2; } health2 -= modDamage; trace(fighter2Name + " takes " + modDamage + " damage and has " + health2 + " health left!"); }else{ trace(fighter1Name + " misses " + fighter2Name + "!"); } //make sure fighter 2 didn't die if(health2 < 0){ //break escapes from the loop it sits in break; } modAttack = attack2 + Math.floor(Math.random() * 10) + 1; modDefense = defense1 + Math.floor(Math.random() * 10) + 1; if(modAttack > modDefense){ trace(fighter2Name + " hits " + fighter1Name + "!"); modDamage = damage2 + Math.floor(Math.random() * 10) + 1; if(modAttack > modDefense * 2){ trace("CRITICAL HIT!"); modDamage = modDamage * 2; } health1 -= modDamage; trace(fighter1Name + " takes " + modDamage + " damage and has " + health1 + " health left!"); }else{ trace(fighter2Name + " misses " + fighter1Name + "!"); } } //fight is over, let's report the winner if(health1 <= 0){ trace(fighter2Name + " wins!"); }else{ trace(fighter1Name + " wins!"); } } } }