有没有办法从文件中获取这些参数(JSON,XML或可从java解析的东西)?我有很多问题"在我的代码和内部编码显然不是最好的方法。
new Question("Is it a men?", character -> character.isMale(), Question.TYPE.GENDER));
public class Question {
private final String text;
private final Predicate<Character> filter;
private final Question.TYPE type;
/**
* @param text testo della domanda
* @param filter filtro della domanda
* @param type classe di appartenenza della domanda
*/
public Question(final String text, final Predicate<Character> filter, final TYPE type) {
this.text = text;
this.filter = filter;
this.type = type;
}
/**
* @return Testo della domanda.
*/
public String getText() {
return text;
}
/**
* @return Il filtro necessario per ottenere i personaggi che rispecchiano le caratteristiche fisiche volute.
*/
public Predicate<Character> getFilter() {
return filter;
}
/**
* @return la classe di appartenenza della domanda.
*/
public TYPE getType() {
return this.type;
}
/**
* Definisce le classi di appartenenza delle domande, viene utilizzato per escludere le domande che hanno relazioni fra loro.
*/
public enum TYPE {
/***/
HAIR_COLOR, EYE_COLOR, GENDER, GLASSES, HAIR_TYPE, HAT, BEARD;
}
}
-----角色等级
package model;
import java.util.Optional;
import javax.swing.ImageIcon;
import utilities.Colors;
public class Character {
private final String name;
private final boolean isMale;
private final Colors eyeColor;
private final Optional<Colors> hairColor;
private final Colors skinColor;
private final boolean hasBeard;
private final boolean hasMustache;
private final boolean hasHat;
private final boolean hasEarings;
private final boolean hasGlasses;
private final Hair hairType;
private final String picPath;
/**
* Tipi di capelli.
*/
public enum Hair {
/***/
STRAIGHT, CURLY, BALD;
}
/**
* @param name nome
* @param isMale genere
* @param eyeColor colore degli occhi
* @param hairColor colore dei capelli
* @param skinColor colore della pelle
* @param hasBeard .
* @param hasMustache .
* @param hasHat .
* @param hasEarings .
* @param hasGlasses .
* @param hairType .
* @param picPath .
*/
public Character(final String name, final boolean isMale, final Colors eyeColor, final Optional<Colors> hairColor, final Colors skinColor,
final boolean hasBeard, final boolean hasMustache, final boolean hasHat, final boolean hasEarings, final boolean hasGlasses,
final Hair hairType, final String picPath) {
super();
this.name = name;
this.isMale = isMale;
this.eyeColor = eyeColor;
this.hairColor = hairColor;
this.skinColor = skinColor;
this.hasBeard = hasBeard;
this.hasMustache = hasMustache;
this.hasHat = hasHat;
this.hasEarings = hasEarings;
this.hasGlasses = hasGlasses;
this.hairType = hairType;
this.picPath = picPath;
}
/**
* @return il nome del personaggio
*/
public String getName() {
return name;
}
/**
* @return ritorna true se è maschio
*/
public boolean isMale() {
return this.isMale;
}
/**
* @return il colore dei capelli del personaggio (Empty se non li ha).
*/
public Optional<Colors> getHairColor() {
return this.hairColor;
}
/**
* @return il colore della pelle del personaggio.
*/
public Colors getSkinColor() {
return this.skinColor;
}
/**
* @return true se ha la barba
*/
public boolean hasBeard() {
return this.hasBeard;
}
/**
* @return true se ha i baffi
*/
public boolean hasMustache() {
return this.hasMustache;
}
/**
* @return true se ha il cappello
*/
public boolean hasHat() {
return this.hasHat;
}
/**
* @return true se ha gli orecchini/piercing
*/
public boolean hasEarings() {
return this.hasEarings;
}
/**
* @return true se ha gli occhiali
*/
public boolean hasGlasses() {
return this.hasGlasses;
}
/**
* @return il tipo di capelli definiti in enum Character.Hair
*/
public Hair getHairType() {
return this.hairType;
}
/**
* @return il colore degli occhi del personaggio.
*/
public Colors getEyeColor() {
return this.eyeColor;
}
/**
* @return l'immagine che rappresenta il personaggio.
*/
public ImageIcon getPicPath() {
return new ImageIcon(this.picPath);
}
}