js写的简单宠物程序

本文介绍了一个使用JavaScript编写的简单宠物程序。程序包括宠物的名称、健康度、快乐度、饥饿度和年龄等属性,为用户提供了一种互动的游戏体验。
摘要由CSDN通过智能技术生成
<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+=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值