import java.util.Random;
public class PokemonGenerator {
private static final String[] ATTRIBUTES = {"火", "水", "草"};
private static final String[] SKILLS = {"火焰喷射", "水枪", "飞叶快刀"};
// 生成随机的神奇宝贝
public static Pokemon generatePokemon() {
Random random = new Random();
String name = "神奇宝贝" + random.nextInt(100);
String attribute = ATTRIBUTES[random.nextInt(ATTRIBUTES.length)];
String skill = SKILLS[random.nextInt(SKILLS.length)];
return new Pokemon(name, attribute, skill);
}
}
3. 创建玩家类
import java.util.ArrayList;
import java.util.List;
public class Player {
private String name;
private List<Pokemon> backpack;
// 构造方法
public Player(String name) {
this.name = name;
this.backpack = new ArrayList<>();
}
// 捕捉神奇宝贝并添加到背包中
public void catchPokemon(Pokemon pokemon) {
backpack.add(pokemon);
System.out.println(name + "捕捉到了一个" + pokemon.getName());
}
}
4. 实现捕捉神奇宝贝的功能
public class Game {
public static void main(String[] args) {
Player player = new Player("小明");
Pokemon pokemon = PokemonGenerator.generatePokemon();
player.catchPokemon(pokemon);
}
}
5. 实现神奇宝贝间的战斗
public class PokemonBattle {
public static void battle(Pokemon pokemon1, Pokemon pokemon2) {
System.out.println(pokemon1.getName() + "使用了" + pokemon1.getSkill());
System.out.println(pokemon2.getName() + "使用了" + pokemon2.getSkill());
// 战斗逻辑
}
}
6. 实现神奇宝贝的进化
public class PokemonEvolution {
public static void evolve(Pokemon pokemon) {
if (pokemon.getAttribute().equals("火")) {
System.out.println(pokemon.getName() + "进化为了炎兽");
} else if (pokemon.getAttribute().equals("水")) {
System.out.println(pokemon.getName() + "进化为了水王");
} else if (pokemon.getAttribute().equals("草")) {
System.out