?? map.java
字號:
/**
* @(#)Map.java
* @A map with name,difficulty,proportions of four kinds of food and info.
*
* @Link Scholes
* @version 1.00 2008/7/21
*/
package Data;
//Java core packages
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class Map
{
private int tmp;
private int difficulty;
private int food[];
private int info[][];
private String temp;
private String name;
private BufferedReader input;
private BufferedWriter output;
private File file;
private Scanner scanner;
//construct a map with all properties defaulted
public Map()
{
food = new int[4];
info = new int[15][15];
difficulty = 564;
name = "DEFAULT";
for (int i = 0;i < 4;i ++)
{
food[i] = 25;
}
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
info[i][j] = 0;
}
}
}
//get the difficulty of the map
public int getDifficulty()
{
return difficulty;
}
//get the proportions of four kinds of food of the map
public int[] getFood()
{
return food;
}
//get the info of the map
public int[][] getInfo()
{
return info;
}
//get the name of the map
public String getName()
{
return name;
}
//set the map with specified name,info and proportions of four kinds of food
public void setMap(String s,int a[][],int b[])
{
name = s;
info = a;
food = b;
}
//turn the map to String
public String toString()
{
temp = "";
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
temp += info[i][j] + " ";
}
}
for (int i = 0;i < 4;i ++)
{
temp += food[i] + " ";
}
temp += difficulty;
return temp;
}
//save the map to a ".map" file
public void save()
{
try
{
difficulty();
input = new BufferedReader(new StringReader(toString()));
output = new BufferedWriter(new OutputStreamWriter(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream("map\\extended\\" + name + ".map")))));
tmp = input.read();
while (tmp != -1)
{
output.write(tmp);
tmp = input.read();
}
input.close();
output.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
//load a map of specified kind(original/extended) and specified name
public void load(boolean b,String s)
{
try
{
name = s;
temp = "";
input = new BufferedReader(new InputStreamReader(new BufferedInputStream(new GZIPInputStream(new FileInputStream("map\\" + ((b)?"original":"extended") + "\\" + name + ".map")))));
tmp = input.read();
while (tmp != -1)
{
temp += (char)tmp;
tmp = input.read();
}
input.close();
scanner = new Scanner(temp);
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
info[i][j] = scanner.nextInt();
}
}
for (int i = 0;i < 4;i ++)
{
food[i] = scanner.nextInt();
}
difficulty = scanner.nextInt();
}
catch(IOException e)
{
e.printStackTrace();
}
}
//calculate the difficulty of the map
private void difficulty()
{
for (int i = 0;i < 15;i ++)
{
for (int j = 0;j < 15;j ++)
{
if (info[i][j] == 10)
{
difficulty -= 4;
}
else
{
if (info[i][j] == 11)
{
difficulty += 16;
}
else
{
if (info[i][j] == 12)
{
difficulty += 20;
}
else
{
if (info[i][j] == 13)
{
difficulty -= 8;
}
else
{
if (info[i][j] > 13)
{
difficulty += 4;
}
}
}
}
}
}
}
difficulty -= 4 * food[0] - 16 * food[1] - 20 * food[2] + 8 * food[3] + 600;
}
} //end class Map
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -