您的位置:首页 > 其它

猎人僵尸

2017-11-22 00:00 92 查看
package org.jsoft.myworld;

import java.util.Scanner;

public class TextGame {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
String h=in.nextLine();
Hunter hunter=new Hunter();
Monster monster=new Monster();
hunter.setName(h);
while(hunter.getLife()>0&&monster.getLife()>0){
hunter.fight(monster);
monster.kill(hunter);
}
hunter.show();
monster.show();
}
}
-----------------------------------------------------------------------------------------------------

package org.jsoft.myworld;

public class Monster {
private String type;
private int life=2000;
private boolean islive;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getLife() {
return life;
}
public void setLife(int life) {
this.life = life;
}
public boolean isIslive() {
return islive;
}
public void setIslive(boolean islive) {
this.islive = islive;
}
public void kill(Hunter hunter){
hunter.setLife(hunter.getLife()-(int)(Math.random()*100+10));
}
public void injured(){

}
public void dead(){

}
public void show(){
if(life>0){
System.out.println("僵尸受伤"+" "+"剩余"+life);
}else{
System.out.println("僵尸死亡");
}
}
}
------------------------------------------------------------------------------------------------------

package org.jsoft.myworld;

public class Hunter {
private String name,weapon;
private int life=2000;
private boolean islive;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWeapon() {
return weapon;
}
public void setWeapon(String weapon) {
this.weapon = weapon;
}
public int getLife() {
return life;
}
public void setLife(int life) {
this.life = life;
}
public boolean isIslive() {
return islive;
}
public void setIslive(boolean islive) {
this.islive = islive;
}
public void fight(Monster monster){
monster.setLife(monster.getLife()-(int)(Math.random()*100+10));
}
public void injured(){

}
public void dead(){

}
public void show(){
if(life>0){
System.out.println(name+"受伤"+" "+"剩余"+life);
}else{
System.out.println(name+"死亡");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: