加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Player.java 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
方子聪 提交于 2020-06-20 16:21 . 迷宫
import java.util.*;
public class Player
{
private int strength = 100;
private static Map<String, Thing> bag = new HashMap<>();
public void step() {
strength -= 10;
}
public void pick(Thing thing) {
bag.put(thing.getName(), thing);
System.out.println("捡到了:"+thing.getName()+"能量:"+thing.getEnergy());
}
public void eat(String name) {
Thing thing = bag.get(name);
if(thing != null) {
int strengthnow=strength;
strength += thing.getEnergy();
if(strength >100) {
strength = 100;
}
System.out.println("吃掉了"+name+"恢复"+(strength-strengthnow)+"能量");
System.out.println("现在:"+strength);
bag.keySet().removeIf(key -> key.contains(name));
}
}
public void checkBag() {
bag.keySet().stream().forEach(key -> System.out.print(key + " "));
System.out.println();
}
public boolean isDead() {
return strength <= 0;
}
public void monster(int hurt) {
strength = strength - hurt;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化