Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
GameNoodle/src/level/LevelHandler.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
55 lines (46 sloc)
1.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package level; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.List; | |
import entities.Entity; | |
import level.tiles.Tile; | |
// Creates and manages the level when the game is running. | |
public class LevelHandler { | |
private Tile[][] tiles; | |
private List<Entity> entities; | |
private int width; | |
private int height; | |
private String levelName; | |
private String levelPath; | |
public LevelHandler(String levelPath) { | |
if (levelPath != null) { | |
this.levelPath = levelPath; | |
this.loadLevelFromFile(); | |
} | |
} | |
// TODO: Change this to use and XML file instead of a text file | |
private void loadLevelFromFile() { | |
try { | |
FileReader fileReader = new FileReader(levelPath); | |
BufferedReader bufferedReader = new BufferedReader(fileReader); | |
levelName = bufferedReader.readLine(); | |
bufferedReader.close(); | |
} catch (IOException e) { | |
System.err.println(e.getMessage()); | |
} | |
} | |
public void tick() { | |
for (Tile[] tileArray : tiles) { | |
for (Tile t : tileArray) { | |
t.tick(); | |
} | |
} | |
for (Entity e : entities) { | |
e.tick(); | |
} | |
} | |
public String getLevelName() { | |
return levelName; | |
} | |
} |