鉴于Im在环境负荷系统上工作,我不想工作,我尝试了不同的方式这样做,而除了不工作外,这看上去是最佳的,因为我需要在当天年底之前这样做。
该守则是:
public GameSettings getGameSettings() throws Exception
{
Resolution GameResolution;
GameSettings gs = new GameSettings(true, true, false, 50, new Resolution(800, 600));
for(int k = 0; k < lines.size(); k++)
{
String[] s1 = lines.get(k).split("=");
if(s1[0].equals("volume"))
{
gs.setVolume(Integer.parseInt(s1[1]));
}
if(s1[0].equals("musicOn"))
{
gs.setMusicOn(Boolean.parseBoolean(s1[1]));
}
if(s1[0].equals("soundOn"))
{
gs.setSoundOn(Boolean.parseBoolean(s1[1]));
}
if(s1[0].equals("aOpenGL"))
{
gs.setAOpenGL(Boolean.parseBoolean(s1[1]));
}
if(s1[0].equals("GameRes"))
{
String[] s2 = s1[1].split("x");
GameResolution = new Resolution(Integer.parseInt(s2[1]), Integer.parseInt(s2[1]));
gs.setGameResolution(GameResolution);
}
if(s1[0].startsWith("#"))
{
continue;
}
else
{
System.err.println("WARNING: Unknow setting in settings file ( " + s1[0] + " )");
continue;
}
}
return gs;
}
, this is the settings.dat file content:
#************************** Settings
#Settings file version 1.5
musicOn=false
volume=75
soundOn=true
aOpenGL=false
GameRes=1000x800
#end of settings file
并且最后是青春期产出:
WARNING: Unknow setting in settings file ( musicOn )
WARNING: Unknow setting in settings file ( volume )
WARNING: Unknow setting in settings file ( soundOn )
WARNING: Unknow setting in settings file ( aOpenGL )
WARNING: Unknow setting in settings file ( GameRes )