第一个ActionScript3.0语言的文字小游戏【古惑仔之人在江湖】


/*第一个ActionScript3.0语言的文字小游戏【古惑仔之人在江湖】
author:KKK
date:2010-07-22
function:【古惑仔之人在江湖】人在江湖漂,哪能不挨刀,话说陈浩南投入洪兴大佬B门下之后,忠心效主。
洪兴另一揸Fit人靓坤,将大佬B谋害,遂于陈浩南结怨,一场生死之战拉开。
战至最后,今日不是你死就是我亡
*/
var hero:Object = new Object();
var boss:Object = new Object();

hero.name = "@陈浩南@";
hero.HP = 100; //生命值
hero.ATT =90; //攻击力
hero.DEF = 88; //防御力
hero.AGI = 60; //敏捷度
hero.skill1 = "拳头";
hero.skill2 = "铁链";
hero.skill3 = "钢管";

boss.name = "#靓坤#";
boss.HP = 120;//生命值
boss.ATT =92; //攻击力
boss.DEF = 90; //防御力
boss.AGI = 22;//敏捷度
boss.skill1 = "飞脚";
boss.skill2 = "小刀";
boss.skill3 = "砍刀";

var timer:Timer = new Timer(1000); //1000毫秒间隔发送事件
timer.addEventListener(TimerEvent.TIMER, round); //监听事件
timer.start();

function whoAttacks(a:Object, b:Object):Array{
return a.AGI*Math.random() > b.AGI*Math.random()? [a,b]:[b,a];
}

function round(e:TimerEvent):void{
var damage:Number;
var skillIndex:uint;
var roundFight:Array = whoAttacks(hero, boss);
var attacker:Object = roundFight[0];
var defender:Object = roundFight[1];
damage = attacker.ATT * Math.random() - defender.DEF * Math.random();
if (damage <= 0){
damage = 0;
}else{
damage = Math.ceil(damage); //伤害值取整
}
defender.HP -= damage ;
if(damage < attacker.ATT /3){ //按照伤害值来选定攻击方式
skillIndex = 1;
}else if(damage < attacker.ATT*2 /3){
skillIndex = 2;
}else{
skillIndex = 3;
}

trace(attacker.name + "向" + defender.name + "使出了" +
attacker["skill"+skillIndex] + "," + defender.name+
"损失了" + damage + "点HF");
if(defender.HP <= 0){
trace(defender.name + "顶5住了,倒了\n" + attacker.name+
"胜出");
timer.removeEventListener(TimerEvent.TIMER, round); //移除监听

trace("\nGame Over");
return; //退出程序

}

trace(hero.name + "HP:" + hero.HP + "\t"+
boss.name + "HP:" + boss.HP+"\n" );
}

你可能感兴趣的:(游戏)