map_manager.java

来自「分别是模糊识别、模糊聚类、模糊控制的实例代码」· Java 代码 · 共 54 行

JAVA
54
字号
package fuzzy_control;

import java.util.*;
import java.io.*;

public class Map_manager {
  private String line;
  private ArrayList lines;
  private int width,height;
  private byte[][] map;

  public Map_manager(int h,int w)
  {
    height = h;
    width = w;
    try
    {
       loadMap("maps/map1.txt");
    }catch(IOException e){}
   }

  private void loadMap(String filename) throws IOException
  {
      lines = new ArrayList();
      BufferedReader reader = new BufferedReader(new FileReader(filename));

      while (true)
      {
          line = reader.readLine();
          if (line == null)
          {
              reader.close();
              break;
          }
         lines.add(line);
     }

      map = new byte[height][width];
      for (int x=0; x<height; x++)
      {
          String line = (String)lines.get(x);
          for (int y=0; y<width; y++)
          {
            map[x][y]=Byte.parseByte(line.valueOf(line.charAt(y)));
          }
      }
  }

  public byte[][] returnMap()
  {
      return map;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?