求用JAVA编程模拟培养类游戏需要有以下类:
发布网友
发布时间:2022-04-20 09:26
我来回答
共1个回答
热心网友
时间:2022-07-14 01:40
=============LEVEL 类==================
package pojo;
public class level {
private int id;
private int attack;
private int against;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAttack() {
return attack;
}
public void setAttack(int attack) {
this.attack = attack;
}
public int getAgainst() {
return against;
}
public void setAgainst(int against) {
this.against = against;
}
public level(int id, int attack, int against) {
super();
this.id = id;
this.attack = attack;
this.against = against;
}
public level(int id) {
super();
this.id = id;
this.attack =10+id*20 ;
this.against = 5+id*20;
}
}
================PET类=====================
package pojo;
public class pet {
private int id;
private String name;
private level level;
public pet(int id, String name, level level) {
super();
this.id = id;
this.name = name;
this.level = level;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public level getLevel() {
return level;
}
public void setLevel(level level) {
this.level = level;
}
}
=================PetDao============================================
package ;
import java.util.Scanner;
import pojo.level;
import pojo.pet;
public class petDao {
public static void main(String[] args) {
level levelLow=new level(1);
level levelMiddle=new level(15);
level levelHigh=new level(50);
pet pet=new pet(1,"宠物猫",levelLow);
boolean b=true;
while(b){
System.out.println("请输入你要输入的数字");
Scanner scan=new Scanner(System.in);
String str=scan.nextLine();
if(str.equals("levelup")){
int levelId=pet.getLevel().getId();
levelLow=new level(levelId+1);
pet.setLevel(levelLow);
System.out.println("你当前等级为:"+pet.getLevel().getId());
System.out.println("你当前攻击力为:"+pet.getLevel().getAttack());
System.out.println("你当前防御力为:"+pet.getLevel().getAgainst());
}
if(str.equals("leveldown")){
int levelId=pet.getLevel().getId();
if(levelId<=1){
levelId=2;
}
levelLow=new level(levelId-1);
pet.setLevel(levelLow);
System.out.println("你当前等级为:"+pet.getLevel().getId());
System.out.println("你当前攻击力为:"+pet.getLevel().getAttack());
System.out.println("你当前防御力为:"+pet.getLevel().getAgainst());
}
int nowLevel=pet.getLevel().getId();
if(nowLevel<30){
System.out.println("你当前宠物级别:低");
}
else if(nowLevel>=30&&nowLevel<60){
System.out.println("你当前宠物级别:中");
}
else{
System.out.println("你当前宠物级别:高");
}
if(str.equals("exit")){
System.exit(0);
}
}
}
}