source: java-rpg-common/Map.java

Last change on this file was de19622, checked in by dportnoy <dmp1488@…>, 15 years ago

Removed some VERY old commented VB code and allowed the structInfo file to specify a player's spawn point upon login.

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[04e7260]1import java.io.*;
2import java.util.*;
3
4public class Map {
5 private Location[][] grid;
[de19622]6 public Point startingLoc;
[04e7260]7
8 public Map(int x, int y) {
9 grid = new Location[x][y];
10 }
11
12 public Map(String landFile, String structFile, HashMap<LandType, Land> landMap, HashMap<StructureType, Structure> structMap) {
13 try {
14 int length, height, x, y;
15 String str, loc;
16 BufferedReader in = new BufferedReader(new FileReader(landFile));
17
18 str = in.readLine();
19 length = Integer.parseInt(str.substring(0, str.indexOf("x")));
20 height = Integer.parseInt(str.substring(str.indexOf("x")+1));
21 grid = new Location[length][height];
22
23 for(x=0; x<height; x++) {
24 str = in.readLine();
25 for(y=0; y<length; y++) {
26 if(str.indexOf(",") == -1)
27 loc = str;
28 else {
29 loc = str.substring(0, str.indexOf(","));
30 str = str.substring(str.indexOf(",")+1);
31 }
32
33 if(loc.equals("o")) {
34 loc = "Ocean";
35 }else if(loc.equals("1")) {
36 loc = "Grass";
37 }
38
39 grid[y][x] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None));
40 }
41 }
42
43 in.close();
44
45 in = new BufferedReader(new FileReader(structFile));
46
[de19622]47 startingLoc = new Point(0, 0);
[04e7260]48 while((loc = in.readLine()) != null) {
49 str = in.readLine();
50 x = Integer.valueOf(str.substring(0, str.indexOf(",")));
51 y = Integer.valueOf(str.substring(str.indexOf(",")+1));
52
53 grid[x-1][y-1].setStruct(structMap.get(StructureType.valueOf(loc)));
[de19622]54 if(StructureType.valueOf(loc) == StructureType.LoginPedestal) {
55 startingLoc = new Point(100*x-40, 100*y-50);
56 }
[04e7260]57 }
58 } catch(IOException ioe) {
59 ioe.printStackTrace();
60 }
61 }
62
63 public Location getLoc(int x, int y) {
64 return grid[x][y];
65 }
66
67 public void setLoc(Location loc, int x, int y) {
68 grid[x][y] = loc;
69 }
70
71 public int getLength() {
72 return grid.length;
73 }
74
75 public int getHeight() {
76 if(grid.length>0)
77 return grid[0].length;
78 else
79 return 0;
80 }
81}
Note: See TracBrowser for help on using the repository browser.