我已经在这个网站上做了一些关于这方面的研究,但是,我在寻找可以使用的东西时遇到了一些麻烦.我正在尝试为口袋妖怪创建一个类似的程序,但更简单和基于文本.目前我正在使用数组存储Pokemon的统计数据.这工作得很好,但是当我需要打印Pokemon的名字时,我必须手动输入它.这个工作得很好,但我想让玩家与一个随机的口袋妖怪战斗.这是我目前的代码:
public static void main(String[] args) {
//Declare the Pokemon to be used
int[] Player = {0, 0, 0, 0, 0, 0 };
int[] Blastoise = {79, 83, 100, 85, 105, 78 };
int[] Raichu = {60, 90, 55, 90, 80, 110};
int[][] Pokemon = new int[][] {Blastoise, Raichu, Player};
Scanner input = new Scanner(System.in);
startBattle(input, Pokemon)
}
public static String startBattle(Scanner input, int[][] Pokemon) {
System.out.println("A wild Pokemon appeared!");
int r = (int) (Math.random() * 1);
System.out.println("A wild " + **POKEMON NAME** + " appeared!");
System.out.print("What Pokemon do you choose? ");
String userPokemon = input.next();
return userPokemon;
}
Run Code Online (Sandbox Code Playgroud)
在哪里说POKEMON NAME就是我想要的口袋妖怪的名字.我知道获取数组的名称是非常困难的,或者将一个String添加到一个int数组(我会将名称添加到list [0] spot).有什么方法我至少可以将String与其中一个列表相关联,这样我可以调用随机选择的Pokemon的名字吗?谢谢!
创建一个类.为它提供表示描述您的真实世界实体的属性,在这种情况下是一个宠物小精灵.
属性至少是表示名称的字符串和用于描述字符的整数数组.
这是一个例子:
public class Pokemon {
private String name;
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
private int hp;
public int getHP() { return this.hp; }
public void setHP(int hp) { this.hp = hp; }
// Repeat the pattern for all properties that describe a Pokemon
// hp, attack, defense, special attack, special defense, and speed
}
Run Code Online (Sandbox Code Playgroud)