猎人僵尸

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+"死亡");
        }
    }
}

转载于:https://my.oschina.net/u/3719225/blog/1577240

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值