<script language=javascript> var HEALTH_ADD = 10; var HAPPY_ADD = 10; var HUNGER_ADD = 10; // 宠物对象 function Pet(pet_name){ this.pet_name=pet_name; // 宠物名称 this.health=100; // 宠物健康度 // 最高100 低于0将生病死 this.happiness=100; // 宠物快乐度 最高100 低于0将被抑郁死 this.hunger=0; // 宠物饥饿度 达到100会饿死 this.age=0; // 宠物年龄 this.display=display; // 关联显示状态方法 this.feed=feed; // 关联喂养方法 this.play=play; // 关联游戏方法 this.wash=wash; // 关联洗澡方法 this.ageOld=ageOld; // 关联年龄生长方法 this.healthDecrease=healthDecrease; // 关联健康减少方法 this.happinessDecrease=happinessDecrease; // 关联快乐减少方法 this.hungerAdd=hungerAdd; // 关联饥饿增加方法 } function hungerAdd(){ // 饥饿增加 this.hunger+=1; } function happinessDecrease(){ // 快乐减少 this.happiness-=1; } function healthDecrease(){ // 健康减少 this.health-=1; } function ageOld(){ // 年龄增长 this.age+=1; } function feed(){ // 喂养宠物 this.hunger-=HUNGER_ADD; this.display(); } function play(){ // 玩耍 this.happiness+=
js写的简单宠物程序
最新推荐文章于 2024-09-03 09:51:41 发布
本文介绍了一个使用JavaScript编写的简单宠物程序。程序包括宠物的名称、健康度、快乐度、饥饿度和年龄等属性,为用户提供了一种互动的游戏体验。
摘要由CSDN通过智能技术生成