當前位置:編程學習大全網 - 編程語言 - 關於掃雷的Java

關於掃雷的Java

妳用I/0 把要保存的東西,直接寫到*.ini文件中不就可以了嗎

這個是我 寫 連連看遊戲,用來保存記錄的,自己參考下,很簡單。

import java.awt.Point;

import java.io.*;

import java.util.*;

public class LoadAndSave {

private static final Properties prop=new Properties();

public static File recordFile=new File("record.dat");

public static File setFile=new File("setup.ini");

public static StringBuilder[] setLines;

public static int getRecord(int total) {

int seconds=999999999;

try {

BufferedReader bReader=new BufferedReader(new InputStreamReader(new FileInputStream(recordFile)));

String line=null;

while((line=bReader.readLine())!=null)

try {

String[] values=line.split("\t");

int n=Integer.parseInt(values[1]);

int s=Integer.parseInt(values[2]);

if(n==total&&s<seconds) seconds=s;

} catch (RuntimeException e) {

}

bReader.close();

} catch (Exception e) {

}

return seconds;

}

public static void load(){

try {

prop.loadFromXML(new FileInputStream(setFile));

} catch (Exception e) {

}

}

public static void save(){

try {

prop.storeToXML(new FileOutputStream(setFile), "no comment");

} catch (Exception e) {

}

}

public static void saveLevel(int level){

prop.setProperty("level", level+"");

save();

}

public static void saveLocation(Point p) {

prop.setProperty("frameX", p.x+"");

prop.setProperty("frameY", p.y+"");

save();

}

public static void saveRecord(int total, int seconds) {

try {

FileOutputStream fos=new FileOutputStream(recordFile,true);

PrintWriter out=new PrintWriter(fos,true);

out.println(new Date(System.currentTimeMillis())+"\t"+total+"\t"+seconds);

out.close();

} catch (FileNotFoundException e) {

}

}

}

  • 上一篇:求高手編寫壹個通達信用:個股每日“成交額”的指標源碼
  • 下一篇:數控車工證書怎麽考
  • copyright 2024編程學習大全網