package Maze; import java.awt.Image; import java.io.File; import java.util.Random; import java.util.Scanner; import javax.swing.ImageIcon; public class Items { private Scanner m[] = new Scanner[100]; private String iLine[] = new String[14]; private String imaps[][][] = new String[14][14][100]; private String itemsFile = ""; private Image stairsup, stairsdown, key, door, blank, monster; int numLevels = 3; int currentLevel = 1; private Player h; private int mnum; public Items() //constructor { //add player h = new Player(); ImageIcon img = new ImageIcon("C://ji//items//stairsup.png"); //loads image file for grass stairsup = img.getImage(); //sets grass Image = to grass.png img = new ImageIcon("C://ji//items//stairsdown.png"); stairsdown = img.getImage(); img = new ImageIcon("C://ji//items//door.png"); door = img.getImage(); img = new ImageIcon("C://ji//items//key.png"); key = img.getImage(); img = new ImageIcon("C://ji//items//blank.png"); blank = img.getImage(); img = new ImageIcon("C://ji//monsters//greenslime.png"); monster = img.getImage(); loadAllLevels(); } public void loadAllLevels(){ for (int z=1; z <=numLevels; z++){ openFile(z); readFile(z); closeFile(z); } } public Items upLevel(Items i){ i.currentLevel +=1; return i;} public Items downLevel(Items i){ i.currentLevel -=1; return i;} public Items pickUpKey(Items i, int x, int y, int z, Player p){ imaps[x][y][z] = "n"; return i; } public Items openDoor(Items i, int x, int y, int z, Player p){ imaps[x][y][z] = "n"; return i; } public Image getBlank() { return blank; //called when map is drawn so it knows which image to show } public Image getStairsUp() { return stairsup; //called when map is drawn so it knows which image to show } public Image getMonster() { // ImageIcon mimg = new ImageIcon("C://ji//items//greenslime.png"); // Random r = new Random(); // mnum = r.nextInt(5)+1; // if (mnum==1) mimg = new ImageIcon("C://ji//monsters//greenslime.png"); // if (mnum==2) mimg = new ImageIcon("C://ji//monsters//redslime.gif"); // if (mnum==3) mimg = new ImageIcon("C://ji//monsters//yellowslime.gif"); // if (mnum==4) mimg = new ImageIcon("C://ji//monsters//goblin.gif"); // if (mnum==5) mimg = new ImageIcon("C://ji//monsters//blackpudding.gif"); // // monster=mimg.getImage(); return monster; //called when map is drawn so it knows which image to show } public Image getDoor() { return door; //called when map is drawn so it knows which image to show } public Image getStairsDown() { return stairsdown; } public Image getKey() { return key; //called when map is drawn so it knows which image to show } public String getItems(int x, int y, int z) { // y = row, x = number of characters in String index2 = imaps[x][y][z]; return index2; } public void openFile(int n) { try //try...catch lets the program handle errors without crashing { itemsFile = "C://ji//maps//imap"+ n + ".txt"; m[n]= new Scanner(new File(itemsFile)); } catch(Exception e) { System.out.println("Error loading map"); } } public void readFile(int z)//z = Current Level { while(m[z].hasNext()) //loops while there is more to read { for(int i = 0; i < 14; i++) //one row at a time { iLine[i] = m[z].next(); //loads the text (g or w) into the map array } } for(int y=0; y< 14; y++){ for(int x=0; x< 14; x++){ imaps[x][y][z]= iLine[y].substring(x, x+1); } } } public void closeFile(int z) { m[z].close(); //close the file when we are done with it. } } //end Items class