对话处理类源码

public class DialogText //对话处理输出类
{
public static String DIALOG_FORMAT = "wxsc 0.2.0"; //版本
public HashMap<String, String[]> data; //总数据
public String[] splitdata; //初处理数据
public boolean isVersionMatch() //是否符合版本
{
if (splitdata[0].equals(DIALOG_FORMAT))
{
return true;
}
return false;
}
public String annotation() //查看注释
{
return splitdata[1];
}
public NPCTalk talkTo(String name) //打开某npc对话
{
return new NPCTalk(name, data.get(name));
}
public DialogText(InputStream in) throws IOException //打开对话文件
{
byte[] bytes = new byte[in.available()];
in.read(bytes);
String all=new String(bytes, "UTF-8");
in.close();
splitdata = all.split("\n#####\n");
if (isVersionMatch())
{
for (int i=2;i < splitdata.length;i++)
{
String[] temp = splitdata[i].split("#\n");
data.put(temp[0], temp);
}
}
}
public class NPCTalk //npc对话类
{
public int schedule; //进度
public int length; //长度
public String npcname; //npc的ID
public String[] saying; //内容
public void setScheduleTo(int location) //设置对话进度位置
{
if (location < length)
{
schedule = location;
}
}
public String say() //对话ing
{
if (schedule < length)
{
schedule++;
return saying[schedule];
}
else
{
return "";
}
}
public String say(int location) //定位到特定位置对话
{
if (location < length)
{
schedule = location;
return saying[schedule];
}
else
{
return "";
}
}
public NPCTalk(String name, String[] text) //构造方法(外部尽量别用)
{
saying = text;
npcname = name;
schedule = 0;
}
}
}