⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 手机游戏,解决存地图的问题,共享代码.txt

📁 最近有很人说怎么把类文件里的地图数据转成文件形式存储起来.以便节省内存.所有小弟把自己的共享出来.方便大家使用.
💻 TXT
字号:
最近有很人说怎么把类文件里的地图数据转成文件形式存储起来.以便节省内存.所有小弟把自己的共享出来.方便大家使用.   
    
  生成地图文件代码:   
    
  import   java.io.*;   
  public   class   WriteData   {   
    public   static   final   byte[][][]   mapdata=new   byte[][][]   
    {   
      //第一关   
      {   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
          {   0,   0,   0,   6,   0,   10,   11,   12,   0,   0,   0,   36   },   
          {   0,   0,   7,   0,   0,   13,   14,   15,   36,   36,   36,   36   },   
          {   67,   49,   0,   0,   0,   16,   17,   18,   36,   67,   67,   36   },   
          {   43,   43,   36,   36,   36,   36,   36,   36,   36,   65,   0,   36   },   
          {   0,   0,   0,   0,   0,   0,   0,   51,   35,   45,   45,   36   },   
          {   72,   0,   0,   0,   0,   (byte)1001,   0,   0,   0,   0,   0,   36   },   
          {   36,   36,   36,   0,   0,   0,   0,   0,   0,   0,   0,   36   },   
          {   67,   67,   36,   36,   36,   36,   36,   31,   32,   0,   0,   36   },   
          {   63,   67,   8,   0,   38,   39,   40,   33,   34,   0,   0,   36   },   
          {   67,   67,   8,   0,   58,   59,   60,   0,   36,   0,   0,   36   },   
                {   41,   41,   8,   0,   78,   79,   80,   0,   36,   0,   0,   36   },   
                {   47,   0,   0,   8,   8,   0,   8,   8,   36,   61,   0,   36   },   
                {   0,   0,   0,   0,   0,   (byte)1001,   0,   67,   67,   67,   0,   36   },   
                {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
            },   
      //第二关   
      {   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
          {   0,   0,   0,   0,   0,   0,   67,   0,   0,   8,   61,   36   },   
          {   19,   36,   0,   0,   36,   0,   67,   0,   8,   0,   0,   36   },   
          {   20,   0,   36,   0,   0,   36,   0,   8,   0,   0,   36,   36   },   
          {   67,   0,   0,   36,   0,   0,   8,   0,   0,   36,   0,   36   },   
          {   67,   0,   0,   36,   0,   (byte)1002,   0,   0,   36,   0,   9,   36   },   
          {   67,   0,   0,   36,   0,   38,   39,   40,   0,   9,   67,   36   },   
          {   67,   0,   67,   67,   0,   58,   59,   60,   8,   67,   0,   36   },   
          {   67,   36,   67,   0,   36,   78,   79,   80,   8,   0,   0,   36   },   
          {   8,   67,   0,   8,   0,   67,   0,   67,   0,   8,   71,   36   },   
          {   0,   0,   36,   0,   67,   0,   65,   0,   67,   8,   67,   36   },   
          {   0,   0,   8,   8,   8,   0,   0,   8,   8,   8,   67,   36   },   
          {   0,   0,   36,   55,   36,   0,   0,   36,   56,   36,   67,   36   },   
          {   0,   0,   0,   (byte)1002,   0,   0,   0,   0,   0,   0,   63,   36   },   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
      },   
      //第三关   
      {   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
          {   0,   0,   0,   0,   0,   0,   43,   67,   67,   67,   67,   36   },   
          {   0,   0,   57,   36,   0,   51,   36,   36,   36,   61,   67,   36   },   
          {   0,   0,   77,   0,   36,   36,   36,   49,   0,   36,   36,   36   },   
          {   0,   0,   0,   0,   0,   72,   45,   0,   0,   67,   67,   36   },   
          {   0,   36,   0,   0,   0,   (byte)1003,   0,   0,   36,   67,   0,   36   },   
          {   0,   36,   0,   0,   0,   0,   0,   0,   36,   36,   36,   36   },   
          {   0,   36,   36,   0,   0,   0,36,36,   36,   36,   36,   36   },   
          {   0,   0,   36,   27,   28,   0,   0,   0,   67,   67,   67,   36   },   
          {   0,   0,   56,   29,   30,   0,   0,   9,   9,   9,   37,   36   },   
          {   67,   67,   36,   36,   36,   38,   39,   40,   0,   41,   67,   36   },   
          {   6,   0,   35,   65,   47,   58,   59,   60,   0,   8,   67,   36   },   
          {   6,   0,   (byte)1003,   0,   35,   78,   79,   80,   0,   8,   67,   36   },   
          {   7,   0,   0,   0,   0,   0,   0,   0,   0,   8,   63,   36   },   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36},   
      },   
      //第四关   
      {   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
          {   0,   0,   0,   0,   0,   76,   0,   61,   0,   0,   0,   36   },   
          {   0,   0,   0,   0,   0,   76,   0,   67,   67,   67,   0,   36   },   
          {   0,   36,   0,   0,   0,   76,   76,   45,   45,   76,   0,   36   },   
          {   0,   36,   0,   0,   87,   88,   92,   0,   9,   76,   76,   36   },   
          {   51,   19,   0,   0,   95,   103,   102,   0,   0,   0,   47,   36   },     
          {   43,   20,   36,   36,   0,   0,   0,   0,   27,   28,   (byte)1002,   36},   
          {   67,   67,   (byte)1002,   36,   0,   0,   0,   0,   29,   30,   0,   36},   
          {   0,   65,   0,   36,   0,   36,   36,   36,   36,   36,   36,   36   },   
          {   0,   0,   0,   36,   0,   36,   0,   0,   67,   67,   0,   36   },   
          {   0,   0,   0,   36,   0,   36,   0,   0,   38,   39,   40,   36   },   
          {   0,   49,   36,   36,   41,   41,   41,   0,   58,   59,   60,   36   },   
          {   0,   0,   36,   67,   41,   63,   41,   0,   78,   79,   80,   36   },   
          {   0,   0,   67,   67,   41,   41,   41,   (byte)1002,   0,   0,   0,   36   },   
          {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
      },   
      //第五关   
        {   
      {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36   },   
      {0,8,8,0,67,67,49,8,8,43,61,   36},   
      {0,0,8,0,0,0,0,0,0,43,43,   36},   
      {71,0,8,0,0,0,(byte)1004,0,0,0,0,   36},   
      {0,27,28,8,8,2,8,36,0,8,8,   36},   
      {0,29,30,1,1,1,1,36,0,0,67,   36},   
      {7,36,36,1,41,1,1,36,(byte)1004,0,67,   36},   
      {6,36,36,41,63,41,1,8,0,0,67,   36},   
      {7,5,51,1,41,1,1,8,0,0,67,   36},   
      {0,5,1,1,1,1,1,8,0,0,67,   36},   
      {8,0,53,3,3,3,3,8,38,39,40,   36},   
      {8,6,7,(byte)1004,0,0,0,0,58,59,60,   36},   
      {45,45,67,67,0,0,53,7,78,79,80,   36},   
      {65,45,8,8,47,0,0,6,7,7,7,   36},   
      {   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36,   36},   
        }   
      };   
      static   int   mapwidth;   
      static   int   mapheight;   
            public   static   void   main(String   args[])   {   
            try   {   
              for(int   k=0;k<mapdata.length;k++){   
                      mapwidth=mapdata[k].length;         
                      mapheight=mapdata[k][0].length;   
                      System.out.println("mapwitdh="+mapwidth);   
                      System.out.println("mapheight="+mapheight);   
                      FileOutputStream   fout   =   new   FileOutputStream("map"+k+".bin");   
                      BufferedOutputStream   bout   =   new   BufferedOutputStream(fout);   
                      DataOutputStream   dout   =   new   DataOutputStream(bout);   
                      dout.writeByte(mapwidth);   
                      dout.writeByte(mapheight);   
                      for(int   i=0;i<mapwidth;i++){   
                      for(int   j=0;j<mapheight;j++){   
                        System.out.println("mapdata["+k+"]["+i+"]["+j+"]="+mapdata[k][i][j]);   
                        dout.writeByte(mapdata[k][i][j]);   
                            }     
                      }   
                      dout.flush();   
                      fout.close();   
              }   
          }catch   (IOException   e){                     
            System.err.println(e.toString());   
          }   
      }   
  }   
    
  读取地图代码:   
  DataInputStream   dis   =   new   DataInputStream(getClass().getResourceAsStream("/map"+String.valueOf(stage-1)+".bin"));   
                mapwlen   =   dis.readByte();       
                maphlen   =   dis.readByte();       
                secondmap=new   byte[mapwlen][maphlen];   
                //System.out.println("mapwlen="+mapwlen);   
                //System.out.println("maphlen="+maphlen);   
                for(int   i=0;i<mapwlen;i++){   
              for(int   j=0;j<maphlen;j++){   
            secondmap[i][j]=dis.readByte();   
            //System.out.println("secondmap["+i+"]["+j+"]="+secondmap[i][j]);   
            }     
              }   
                dis.close(); 

⌨️ 快捷键说明

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