有意思,假期还有JS的作业,哥们假期好好看看书,争取自己做出来
解决方案 »
- js,根据来路跳转问题
- 如何让字符一个个停下来?
- 正则表达式
- 如何用javascript打开窗口,窗口大小按照自己的要求,导航栏都去掉!
- 图片等比缩放问题!急!!在线=====
- javascript怎么获得class 所定义的样式
- js联动问题
- 求指教!淘宝购买数量的方法为什么不能用在所有的对象上面?
- HELP!!!! 100分!html中Javascript利用Xmlhttp传递给asp中文字符乱码!
- 征集控件ing!!!
- 求一个用javascript验证输入框内容是否有效ip的程序!
- 我有一字符串 var str="abc|CSDN"; var test="wdfdfd|MSDN" 我想取到|线前面的,也就是,abc,wdfdfd.JS脚本有好方法吗?比如像C#里面的sp
function Pet(the_pet_name, the_form_number)//两个参数宠物名字和要显示其信息的表单号
{
this.age = 0;
this.hunger = Math.random() * 5; //给每个产生的宠物一个不同的饥饿,健康
this.health = Math.random() * 3 +1 ;//和快乐的初始值
this.happiness = Math.random() * 5;
this.pet_name = the_pet_name;
this.form_number = the_form_number; this.feed = feed;
this.play = play;
this.medicate = medicate;
this.display = display;
this.makeOlder = makeOlder; window.document.forms[the_form_number].pet_name.value = the_pet_name;
this.display();
}
//这样就可以创建两个宠物
//var pet1 = new Pet("barney",0);
//var pet2 = new Pet("betty",1);
function feed()//喂宠物的方法 如果调用了 pet1.feed()方法,首
//先它会产生一个0到2之间的数,然后把饥饿度减去这个数。
{
var meal_quality = Math.random() * 2;
this.hunger = this.hunger - meal_quality;
if (this.hunger <0)
{
this.hunger = 0;
}
this.display();
}
function display() //显示信息方法
{
var the_string = ""; if (this.health < min_health)
{
the_string = this.pet_name + " IS DEAD!";
} else {
the_string += "Happiness " + parseInt(this.happiness);
the_string += ". Health: " + parseInt(this.health);
the_string += ". Hunger: " + parseInt(this.hunger);
the_string += ". Age: " + parseInt(this.age);
the_string += ".";
} window.document.forms[this.form_number].pet_status.value = the_string;
}
function makeOlder()//宠物的年龄增加一岁,并让宠物更饿一点
//和更不高兴一点
{
var max_hunger = 5;
var good_happiness = 5; if (this.health > min_health)
{
this.age +=1;
this.happiness -= Math.random() * 2;//快乐值降低了一个随机数
this.hunger += Math.random() * 2;//饥饿度增加了一个随机
if (this.hunger > max_hunger)
{
this.health -= Math.random() * 2;
this.happiness -= Math.random() * 2;
} } this.display();
}
function moveTime() //设定让makeOlder()方法每三秒种就调用一次.
{
pet1.makeOlder();
pet2.makeOlder();
the_time_out = setTimeout("moveTime();", 3000);
}