首页>代码>java swing编写俄罗斯方块小游戏源代码下载>/russia/src/russia/game/square/FileHelpers.java
package russia.game.square;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;


/**
 * 保存游戏的类
 * @author Administrator
 *
 */
public class FileHelpers {
	
	/**
	 * 存方块
	 * 方块数组
	 * @param shapeMap
	 */
	public static final void wirte(int [][] shapeMap,int row,int column){
		try {
			File fl=new File("shape.txt");
			if(!fl.exists()){
				return ;
			}
			BufferedWriter bft=new BufferedWriter(new FileWriter(fl));
			  for(int i=0;i<row;i++){
			    	for(int j=0;j<column;j++){
			    		bft.append(shapeMap[i][j]+"");
			    	}
			    	bft.append("\n");
			    }
			  bft.flush();
			  bft.close();
		} catch (Exception e) {
		}
		
		
	}
	
	/**
	 * 写方块
	 * @return
	 * 方块数组
	 */
	public static final int [][]read(int row,int column) {
      		int [][]shapeMap=new int[row][column];
      		try {
      			
      			File fl=new File("shape.txt");
      			if(!fl.exists()){
      				fl.mkdir();
      			}
      		   BufferedReader bfd=new BufferedReader(new FileReader(fl));
      		   String read=null;
      		   int index=0;
      		   while((read=bfd.readLine())!=null){
      			  char[]ary= read.toCharArray();
      			   for(int i=0,size=ary.length;i<size;i++){
      				   char ch=ary[i];
      				   shapeMap[index][i]=Integer.parseInt(ch+"");
      			   }
      			   index++;
      		   }
      		   bfd.close();
      		}
      		catch (Exception e) {
			}
		return shapeMap;
	}
	
	
	

}
最近下载更多
ClydeSon  LV5 2023年12月27日
艾卡西亚没有暴雨  LV1 2021年6月9日
我叫杜有青  LV1 2021年3月5日
lyh3568263744  LV2 2020年12月19日
Care269031877  LV4 2020年12月18日
bhdzhhd  LV1 2020年12月2日
zzwllkw  LV1 2020年11月29日
xzx666  LV1 2020年11月16日
hhhhhjqjq  LV1 2020年7月1日
konodion  LV1 2020年6月28日
最近浏览更多
李龙生 1月31日
暂无贡献等级
ClydeSon  LV5 2023年12月27日
1112WHQ  LV7 2023年11月3日
ggl163163eel  LV2 2023年10月19日
huangzy  LV12 2023年6月11日
小安同学  LV7 2023年5月11日
XVXIAOPING  LV1 2022年12月21日
522881297  LV1 2022年12月19日
tree1112666  LV1 2022年8月19日
15946927292  LV1 2022年6月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友