首页 分享 java版本电子宠物游戏代码

java版本电子宠物游戏代码

来源:萌宠菠菠乐园 时间:2024-08-19 04:49

package Petgame; import javax.microedition.lcdui.*; /* * 创建日期 2004-7-25 * * 更改所生成文件模板为 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释 */ /** * @author Administrator * * 更改所生成类型注释的模板为 窗口 > 首选项 > Java > 代码生成 > 代码和注释 */ public class Pet extends Sprite { public Pet (Image pic, int height, int width) { super (pic, height, width); heart = new estate ("心情度",12, 12, 10, 6, "我很快乐","我很不开心"); posture = new estate ("劳累度",12, 12, 20, 6, "身体状态不错","很累"); glut = new estate ("饱腹度",12, 12, 40, 6, "不饿","很饿"); if (heart.getFlag ()) { setframesq (good_ani); } else { setframesq (bad_ani); } } private int good_ani[] = { 14, 15, 16, 14, 15, 16 }; //好心情动画数组 private int bad_ani[] = { 12, 13, 12, 13, 12, 13 }; //坏心情动画数组 private int dining_ani[] = { 0, 1, 2, 2, 2, 3 }; //喂吃动画数组 private int playgame_ani[] = { 10, 11, 10, 11, 10, 11 }; //游玩动画数组 private int repose_ani[] = { 17, 18, 17, 18, 17, 18 }; //休息动画数组 private int hungry_ani[] = { 4, 5, 4, 5, 4, 5 }; //饥饿动画数组 private int posture_ani[] = { 6, 7, 8, 8, 9, 9 }; //劳累动画数组 private estate heart; //心情 private estate posture; //身体状态 private estate glut; //饱腹度 private boolean command_flag = false; /** * 进行过程指令,负责宠物生命进程 * */ public void playing () { heart.playing (); posture.playing (); glut.playing (); if (worked () && !glut.getFlag ()) { setframesq (hungry_ani); command_flag = false; } if (worked () && !posture.getFlag ()) { setframesq (posture_ani); command_flag = false; } if (worked ()) { command_flag = false; if (heart.getFlag ()) { setframesq (good_ani); } else { setframesq (bad_ani); } } nextframe (); } /** * 喂吃宠物指令 * */ public void dining () { if (!command_flag) { heart.value = heart.value + 3; glut.value = glut.value + 4; posture.value = posture.value - 1; command_flag = true; setframesq (dining_ani); } } /** * 宠物游玩指令 * */ public void playgame () { if (!command_flag) { heart.value = heart.value + 3; glut.value = glut.value - 1; posture.value = posture.value - 1; command_flag = true; setframesq (playgame_ani); } } public void drawMsg (Graphics g) { g.drawString (heart.name,0,0,Graphics.LEFT|Graphics.TOP); g.drawString (":",34,0,Graphics.LEFT|Graphics.TOP); g.drawString (heart.getValue (),40,0,Graphics.LEFT|Graphics.TOP); g.drawString (posture.name,60,0,Graphics.LEFT|Graphics.TOP); g.drawString (":",94,0,Graphics.LEFT|Graphics.TOP); g.drawString (posture.getValue (),100,0,Graphics.LEFT|Graphics.TOP); g.drawString (glut.name,120,0,Graphics.LEFT|Graphics.TOP); g.drawString (":",154,0,Graphics.LEFT|Graphics.TOP); g.drawString (glut.getValue (),160,0,Graphics.LEFT|Graphics.TOP); if (!glut.getFlag ()) g.drawString (glut.getMsg (),65,150,Graphics.LEFT|Graphics.TOP); else if (!posture.getFlag ()) g.drawString (posture.getMsg (),65,150,Graphics.LEFT|Graphics.TOP); else if (true) g.drawString (heart.getMsg (),65,150,Graphics.LEFT|Graphics.TOP); } /** * 宠物休息指令 * */ public void repose () { if (!command_flag) { heart.value = heart.value + 1; posture.value = posture.value + 4; command_flag = true; setframesq (repose_ani); } } /** * 状态类 * * @author Administrator * * 更改所生成类型注释的模板为 窗口 > 首选项 > Java > 代码生成 > 代码和注释 */ public class estate { public estate (String name, int value, int max, int timemax, int grade, String msg1, String msg2) { this.name = name; this.value = value; this.max = max; this.time = timemax; this.timemax = timemax; this.grade = grade; this.flag = true; this.msg1 = msg1; this.msg2 = msg2; } public String getValue () { String Value; Value= String.valueOf (this.value); return Value; } public String getMsg () { String msg; if (flag == true) msg = msg1; else msg = msg2; return msg; } public void playing () { if (value!=0) { if (time <= 0) { time = timemax; value--; } else { --time; } } } public boolean getFlag () { if (value > grade) { flag = true; } else { flag = false; } return flag; } protected String name; protected int value; protected int max; protected int time;

相关知识

电子宠物游戏java
Java基于JAVA语言的宠物寄养管理(开题+源码)
用java写的小宠物游戏
java毕设安卓宠物app(开题+源码)
计算机毕业设计 SSM+Vue宠物管理系统 宠物商城 宠物用品购物平台 宠物领养救助系统 Java Vue MySQL数据库 远程调试 代码讲解
毕业设计:基于java的宠物管理系统设计与实现
[附源码]JAVA计算机毕业设计宠物救援平台(源码+开题)
【JAVA程序设计】(C00047)基于springboot+vue的宠物服务管理系统
饥荒代码输入没反应,饥荒联机版宠物领养流程攻略
「Pokemon GO」续作?AR电子宠物游戏「Peridot」试玩评测

网址: java版本电子宠物游戏代码 https://www.mcbbbk.com/newsview78262.html

所属分类:萌宠日常
上一篇: 养宠物游戏
下一篇: 2021好玩的女生手机养宠物游戏

推荐分享