commit a4a77fb8dd12e994284c059eefd56f75cf91c020 Author: Jalen Winslow Date: Mon Nov 6 10:55:21 2017 -0700 Initial commit diff --git a/Game1_Launcher.class b/Game1_Launcher.class new file mode 100644 index 0000000..2c87f88 Binary files /dev/null and b/Game1_Launcher.class differ diff --git a/Game1_Launcher.java b/Game1_Launcher.java new file mode 100644 index 0000000..aa6e194 --- /dev/null +++ b/Game1_Launcher.java @@ -0,0 +1,9 @@ + +import build.com.hobogames.Game; + +public class Game1_Launcher { + public static void main(String[] args) { + Game game = new Game(); + game.gameLoop(); + } +} \ No newline at end of file diff --git a/about/Game1_GameDesignDoc.txt b/about/Game1_GameDesignDoc.txt new file mode 100644 index 0000000..73b68bd --- /dev/null +++ b/about/Game1_GameDesignDoc.txt @@ -0,0 +1,43 @@ +Game1 Game Design Document +Title: none +Date: 9/29/2017 + +*** This game is no longer following this document. *** + +About: +Text Based RPG. A story of becoming either a hero, a villian, or a bystander. A man created by Fate. He awakes +to the sound of people. A group of heroes to be exact. They were the heroes of the story. One who shone the brightest +and brought peace and harmony to those around him. Then there was the Villian, before he became one, who followed +and looked up to the Hero. The man, created by Fate, watched as they went by. Then Fate said to him, "Are you a +hero, a villian, or a bystander?" + +Story: +--Characters-- +-The Hero: +Blessed by Fate, he was born and raised in a log cabin. His father, once being a common soldier, brought him up in +honour and responsibility. Teaching him how to protect and care for people in need. Pushing himself to become better. +He built his skills with the sword, eventually matching his father's. Overtime, with the village near him, he became +well liked. He played with the village kids, while young. Going adventures to deep parts of the forest as he got +older. On one adventure, he became lost and seperated from his friends, but being blessed by Fate; this was suppose +to happen. He came across a single small tree in the middle of a clearing. It stood lonely and singled out. It was +indeed peculiar, yet it wasn't. He considered going to it, but decided not to for he had to find his friends. When +he was walking away he heard a sound coming from the tree. He looked at the tree. He watched and watched but nothing +of interest came out. Turning to walk away, for nothing of interest came from the tree, he stopped. Not quite sure +why, he turned back towards the tree and started walking towards the tree. For some odd reason, he was curious. +He wanted to get closer. As he was getting closer, he heard a small ringing. The ringing seemed to bounce all +around him, from tree to tree. Despite this, he moved closer to the tree. He stopped suddenly in front of it +and reached out to touch it. He felt an overwhelming calm and peace. In fact, he didn't feel himself at all. Nothing +mattered anymore and he felt like giving into it. Actually he was going to, until he heard a voice, "Come here". +Suddenly that sense of calmness disappeared and he reawakened to the suprise that he was sinking into the ground. +He immediately pushed himself up climbing out of the ground. He ran off into the forest, away from the short tree. +It wasn't until later he found a symbol on his hand. A sign of a blessing that would make him the hero. Eventually, +he found his friends and they ended their adventure there. A year later a group of bandits raided the village +he would go to. Only a few had survived, one including a friend who had lost his parents and a sibling in the raid. +Eventually the few remaining survivors decided to disband and leave for a new home. The friend of the hero was taken +in by the hero and his parents. When the time came they would leave together, out on an adventure. + +-The Villian: +The son of a common farmer and his wife. Raised to be a farmer, he helped out with the livestock and farming. His +little sister would stay in the house with his mother and learn from her. Eventually they would have their free time, +which was spent hanging with the kids in the local village. He admired his friend, the hero, who was + diff --git a/build/com/hobogames/Game.class b/build/com/hobogames/Game.class new file mode 100644 index 0000000..a70ae47 Binary files /dev/null and b/build/com/hobogames/Game.class differ diff --git a/build/com/hobogames/Handler.class b/build/com/hobogames/Handler.class new file mode 100644 index 0000000..5ed6356 Binary files /dev/null and b/build/com/hobogames/Handler.class differ diff --git a/build/com/hobogames/gameobj/GOHandler.class b/build/com/hobogames/gameobj/GOHandler.class new file mode 100644 index 0000000..cba6198 Binary files /dev/null and b/build/com/hobogames/gameobj/GOHandler.class differ diff --git a/build/com/hobogames/gameobj/GameObject.class b/build/com/hobogames/gameobj/GameObject.class new file mode 100644 index 0000000..e6e739a Binary files /dev/null and b/build/com/hobogames/gameobj/GameObject.class differ diff --git a/build/com/hobogames/gameobj/entities/Entity.class b/build/com/hobogames/gameobj/entities/Entity.class new file mode 100644 index 0000000..1c48447 Binary files /dev/null and b/build/com/hobogames/gameobj/entities/Entity.class differ diff --git a/build/com/hobogames/gameobj/entities/humans/Human.class b/build/com/hobogames/gameobj/entities/humans/Human.class new file mode 100644 index 0000000..37896f7 Binary files /dev/null and b/build/com/hobogames/gameobj/entities/humans/Human.class differ diff --git a/build/com/hobogames/gameobj/entities/humans/Player.class b/build/com/hobogames/gameobj/entities/humans/Player.class new file mode 100644 index 0000000..1e423c7 Binary files /dev/null and b/build/com/hobogames/gameobj/entities/humans/Player.class differ diff --git a/build/com/hobogames/gameobj/nonentities/Wall.class b/build/com/hobogames/gameobj/nonentities/Wall.class new file mode 100644 index 0000000..875f54b Binary files /dev/null and b/build/com/hobogames/gameobj/nonentities/Wall.class differ diff --git a/build/com/hobogames/states/MenuState.class b/build/com/hobogames/states/MenuState.class new file mode 100644 index 0000000..3195ca2 Binary files /dev/null and b/build/com/hobogames/states/MenuState.class differ diff --git a/build/com/hobogames/states/PlayState.class b/build/com/hobogames/states/PlayState.class new file mode 100644 index 0000000..f14f8d0 Binary files /dev/null and b/build/com/hobogames/states/PlayState.class differ diff --git a/build/com/hobogames/states/State.class b/build/com/hobogames/states/State.class new file mode 100644 index 0000000..6453e8b Binary files /dev/null and b/build/com/hobogames/states/State.class differ diff --git a/build/com/hobogames/utils/Choice.class b/build/com/hobogames/utils/Choice.class new file mode 100644 index 0000000..46d986e Binary files /dev/null and b/build/com/hobogames/utils/Choice.class differ diff --git a/build/com/hobogames/utils/Controller.class b/build/com/hobogames/utils/Controller.class new file mode 100644 index 0000000..b466b51 Binary files /dev/null and b/build/com/hobogames/utils/Controller.class differ diff --git a/build/com/hobogames/utils/Map.class b/build/com/hobogames/utils/Map.class new file mode 100644 index 0000000..69cef8b Binary files /dev/null and b/build/com/hobogames/utils/Map.class differ diff --git a/build/com/hobogames/utils/ReadFile.class b/build/com/hobogames/utils/ReadFile.class new file mode 100644 index 0000000..a6cea10 Binary files /dev/null and b/build/com/hobogames/utils/ReadFile.class differ diff --git a/res/maps/Game1_tutorialMap.txt b/res/maps/Game1_tutorialMap.txt new file mode 100644 index 0000000..29fb22a --- /dev/null +++ b/res/maps/Game1_tutorialMap.txt @@ -0,0 +1,21 @@ +31 13 +room 20 1 3 3 +room 26 1 4 4 +room 13 5 7 4 +room 4 6 3 3 +hall 17 2 3 1 +hall 17 2 1 3 +hall 23 2 3 1 +hall 0 7 4 1 +hall 7 8 6 1 +hall 17 9 1 3 +switch 17 11 1 +lock_door 12 8 1 +exit 0 7 +enemy 5 7 +pillar 14 6 +pillar 18 6 +door 17 4 +lock_door 19 2 2 +p_plate 20 2 2 +torch 21 1 \ No newline at end of file diff --git a/res/texts/Game1_intro.txt b/res/texts/Game1_intro.txt new file mode 100644 index 0000000..b1ebaf8 --- /dev/null +++ b/res/texts/Game1_intro.txt @@ -0,0 +1,6 @@ +Dark and cold. +Nothing to be seen or heard. Only the feeling of a cold, rough stone. You lay there on the floor curled up. +For a moment, your existence seemed like a fluke. Nothing there to symbolize that you existed except for +the stone floor. Then you moved and sat up, feeling the floor around you for anything, but found nothing. +You reach out to all sides but felt only the air around your hand. You stand up feeling disorientated and +afraid. \ No newline at end of file diff --git a/res/texts/Game1_menuScreen.txt b/res/texts/Game1_menuScreen.txt new file mode 100644 index 0000000..84d4ec5 --- /dev/null +++ b/res/texts/Game1_menuScreen.txt @@ -0,0 +1,4 @@ +What would you like to do: + + 1. Play Game (p) + 2. Exit Game (q) \ No newline at end of file diff --git a/src/com/hobogames/Game.java b/src/com/hobogames/Game.java new file mode 100644 index 0000000..d196241 --- /dev/null +++ b/src/com/hobogames/Game.java @@ -0,0 +1,51 @@ +package build.com.hobogames; + +import build.com.hobogames.states.*; + +public class Game { + + private boolean gameOn; + + private Handler handler; + private State menuState; + private State playState; + + public Game() { + + } + + public void init() { + gameOn = true; + + handler = new Handler(this); + menuState = new MenuState(handler); + playState = new PlayState(handler); + State.setCurrentState(menuState); + State.getCurrentState().init(); + + } + + public void gameLoop() { + init(); + + while (gameOn) { + if (State.getCurrentState() != null) { + State.getCurrentState().update(); + } + System.out.println("\n----------------\n"); + + } + + end(); + } + + public void end() { + System.out.println("Exiting game."); + } + + public boolean getGameOn() {return gameOn;} + public MenuState getMenuState() {return (MenuState)menuState;} + public PlayState getPlayState() {return (PlayState)playState;} + + public void setGameOn(boolean gameOn) {this.gameOn = gameOn;} +} \ No newline at end of file diff --git a/src/com/hobogames/Handler.java b/src/com/hobogames/Handler.java new file mode 100644 index 0000000..69c82ea --- /dev/null +++ b/src/com/hobogames/Handler.java @@ -0,0 +1,26 @@ +package build.com.hobogames; + +import build.com.hobogames.states.*; +import build.com.hobogames.gameobj.entities.humans.Player; +import java.util.Random; +import java.util.Scanner; + +public class Handler { + + private Game game; + public Random rand; + public Scanner sc; + + public Handler(Game game) { + this.game = game; + this.rand = new Random(); + sc = new Scanner(System.in); + } + + public Game getGame() {return game;} + public boolean getGameOn() {return game.getGameOn();} + public MenuState getMenuState() {return game.getMenuState();} + public PlayState getPlayState() {return game.getPlayState();} + public Player getPlayer() {return getPlayState().getPlayer();} + +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/GOHandler.java b/src/com/hobogames/gameobj/GOHandler.java new file mode 100644 index 0000000..54d5e0a --- /dev/null +++ b/src/com/hobogames/gameobj/GOHandler.java @@ -0,0 +1,23 @@ +package build.com.hobogames.gameobj; + +import build.com.hobogames.Handler; +import build.com.hobogames.gameobj.GameObject; +import java.util.ArrayList; + +public class GOHandler { + + private Handler handler; + private ArrayList gameObjects; + + public GOHandler(Handler handler) { + this.handler = handler; + } + + public void update() { + for (int i = 0; i < gameObjects.size(); i++) { + if (gameObjects.get(i) != null) { + gameObjects.get(i).update(); + } + } + } +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/GameObject.java b/src/com/hobogames/gameobj/GameObject.java new file mode 100644 index 0000000..30a55e6 --- /dev/null +++ b/src/com/hobogames/gameobj/GameObject.java @@ -0,0 +1,35 @@ +package build.com.hobogames.gameobj; + +import build.com.hobogames.Handler; + +public abstract class GameObject { + + protected Handler handler; + protected int posX, posY; + protected String name; + protected int gameId; + public static int idNum = 0; + + public GameObject(Handler handler) { + this.handler = handler; + posX = 0; + posY = 0; + idNum++; + gameId = idNum; + } + + public abstract void init(); + public abstract void update(); + public abstract void end(); + + public int getPosX() {return posX;} + public int getPosY() {return posY;} + public String getName() {return name;} + public int getGameId() {return gameId;} + + public void setPosX(int posX) {this.posX = posX;} + public void setPosY(int posY) {this.posY = posY;} + public void setName(String name) {this.name = name;} + public void setGameId(int id) {this.gameId = id;} + +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/entities/Entity.java b/src/com/hobogames/gameobj/entities/Entity.java new file mode 100644 index 0000000..9267592 --- /dev/null +++ b/src/com/hobogames/gameobj/entities/Entity.java @@ -0,0 +1,65 @@ +package build.com.hobogames.gameobj.entities; + +import build.com.hobogames.gameobj.GameObject; +import build.com.hobogames.Handler; + +public abstract class Entity extends GameObject { + + protected int dir; + protected int health, maxHealth; + protected int stamina, maxStamina; + protected int attack, defense, speed; + protected int blockChance, dodgeChance, hitChance; + protected int xp, level; + + //attributes + protected int strength, agility, endurance, intelligence, perception, charisma, luck; + + //protected Trait[] traits = new Trait[40] + //protected Skill[] skills = new Skills[20] + + public Entity(Handler handler) { + super(handler); + } + + public abstract void move(int moveX, int moveY); + public abstract void attack(); + + public int getDir() {return dir;} + public int getHealth() {return health;} + public int getMaxHealth() {return maxHealth;} + public int getAttack() {return attack;} + public int getDefense() {return defense;} + public int getSpeed() {return speed;} + public int getBlockChance() {return blockChance;} + public int getDodgeChance() {return dodgeChance;} + public int getHitChance() {return hitChance;} + public int getXp() {return xp;} + public int getLevel() {return level;} + public int getStrength() {return strength;} + public int getAgility() {return agility;} + public int getEndurance() {return endurance;} + public int getIntelligence() {return intelligence;} + public int getPerception() {return perception;} + public int getCharisma() {return charisma;} + public int getLuck() {return luck;} + + public void setDir(int dir) {this.dir = dir;} + public void setHealth(int health) {this.health = health;} + public void setMaxHealth(int maxHealth) {this.maxHealth = maxHealth;} + public void setAttack(int attack) {this.attack = attack;} + public void setDefense(int defense) {this.defense = defense;} + public void setSpeed(int speed) {this.speed = speed;} + public void setBlockChance(int blockChance) {this.blockChance = blockChance;} + public void setDodgeChance(int dodgeChance) {this.dodgeChance = dodgeChance;} + public void setHitChance(int hitChance) {this.hitChance = hitChance;} + public void setXp(int xp) {this.xp = xp;} + public void setLevel(int level) {this.level = level;} + public void setStrength(int strength) {this.strength = strength;} + public void setAgility(int agility) {this.agility = agility;} + public void setEndurance(int endurance) {this.endurance = endurance;} + public void setIntelligence(int intelligence) {this.intelligence = intelligence;} + public void setPerception(int perception) {this.perception = perception;} + public void setCharisma(int charisma) {this.charisma = charisma;} + public void setLuck(int luck) {this.luck = luck;} +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/entities/humans/Human.java b/src/com/hobogames/gameobj/entities/humans/Human.java new file mode 100644 index 0000000..888c85f --- /dev/null +++ b/src/com/hobogames/gameobj/entities/humans/Human.java @@ -0,0 +1,38 @@ +package build.com.hobogames.gameobj.entities.humans; + +import build.com.hobogames.Handler; +import build.com.hobogames.gameobj.entities.Entity; + +public class Human extends Entity { + + + public Human(Handler handler) { + super(handler); + } + + @Override + public void init() { + + } + + @Override + public void update() { + + } + + @Override + public void end() { + + } + + @Override + public void move(int moveX, int moveY) { + + } + + @Override + public void attack() { + + } + +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/entities/humans/Player.java b/src/com/hobogames/gameobj/entities/humans/Player.java new file mode 100644 index 0000000..351ec33 --- /dev/null +++ b/src/com/hobogames/gameobj/entities/humans/Player.java @@ -0,0 +1,46 @@ +package build.com.hobogames.gameobj.entities.humans; + +import build.com.hobogames.gameobj.entities.humans.Human; +import build.com.hobogames.Handler; + +public class Player extends Human { + + + public Player(Handler handler) { + super(handler); + + } + + @Override + public void init() { + dir = handler.rand.nextInt(4); + maxHealth = 20; health = maxHealth; + maxStamina = 20; stamina = 20; + posX = 0; posY = 0; + name = "Player"; + System.out.println(dir + " " + health + " " + stamina + " " + posX + posY + " " + name + " " + gameId); + System.out.println("Player is created!"); + } + + @Override + public void update() { + + } + + @Override + public void end() { + + } + + @Override + public void move(int moveX, int moveY) { + posX += moveX; + posY += moveY; + System.out.println("Player X: " + posX + " Y: " + posY); + } + + @Override + public void attack() { + + } +} \ No newline at end of file diff --git a/src/com/hobogames/gameobj/nonentities/Wall.java b/src/com/hobogames/gameobj/nonentities/Wall.java new file mode 100644 index 0000000..d607974 --- /dev/null +++ b/src/com/hobogames/gameobj/nonentities/Wall.java @@ -0,0 +1,28 @@ +package build.com.hobogames.gameobj.nonentities; + +import build.com.hobogames.Handler; +import build.com.hobogames.gameobj.GameObject; + +public class Wall extends GameObject{ + + + public Wall(Handler handler) { + super(handler); + } + + @Override + public void init() { + + } + + @Override + public void update() { + + } + + @Override + public void end() { + + } + +} \ No newline at end of file diff --git a/src/com/hobogames/states/MenuState.java b/src/com/hobogames/states/MenuState.java new file mode 100644 index 0000000..40e673c --- /dev/null +++ b/src/com/hobogames/states/MenuState.java @@ -0,0 +1,60 @@ +package build.com.hobogames.states; + +import build.com.hobogames.utils.Choice; +import build.com.hobogames.utils.ReadFile; +import build.com.hobogames.Handler; + +public class MenuState extends State { + + + public MenuState(Handler handler) { + super(handler); + } + + @Override + public void init() { + subState = "Main"; + } + + @Override + public void update() { + switch (subState) { + case "Main": + + ReadFile.setPath("res/texts/Game1_menuScreen.txt"); + System.out.print(ReadFile.getText() + "\n -> "); + Choice[] menuChoices = { + new Choice("Play", new String[]{"1", "Play", "Play Game", "p"}), + new Choice("Exit", new String[]{"2", "Exit", "Exit Game", "q"}) + }; + String choice = sc.nextLine(); + + for (int i = 0; i < menuChoices.length; i++) { + if (menuChoices[i].checkAnswer(choice)) { + subState = menuChoices[i].getAnswer(); + break; + } + subState = choice; + } + + break; + case "Play": + end(); + State.setCurrentState(handler.getPlayState()); + State.getCurrentState().init(); + break; + case "Exit": + if (handler.getGameOn()) {handler.getGame().setGameOn(false);} + break; + default: + System.out.println("String:subState does not match any choices. Setting to main."); + subState = "Main"; + break; + } + } + + @Override + public void end() { + + } +} \ No newline at end of file diff --git a/src/com/hobogames/states/PlayState.java b/src/com/hobogames/states/PlayState.java new file mode 100644 index 0000000..50a697e --- /dev/null +++ b/src/com/hobogames/states/PlayState.java @@ -0,0 +1,43 @@ +package build.com.hobogames.states; + +import build.com.hobogames.Handler; +import build.com.hobogames.gameobj.entities.humans.Player; +import build.com.hobogames.utils.Controller; +import build.com.hobogames.utils.Map; + +public class PlayState extends State { + + private Player player; + private Controller controls; + private Map map; + + public PlayState(Handler handler) { + super(handler); + } + + @Override + public void init() { + System.out.println("The game is not ready."); + player = new Player(handler); + controls = new Controller(handler); + map = new Map(handler); + player.init(); + controls.init(); + map.init(); + } + + @Override + public void update() { + controls.update(); + map.displayMap(); + } + + @Override + public void end() { + + } + + public Player getPlayer() {return player;} + + public void setPlayer(Player player) {this.player = player;} +} \ No newline at end of file diff --git a/src/com/hobogames/states/State.java b/src/com/hobogames/states/State.java new file mode 100644 index 0000000..581e880 --- /dev/null +++ b/src/com/hobogames/states/State.java @@ -0,0 +1,25 @@ +package build.com.hobogames.states; + +import build.com.hobogames.Handler; +import java.util.Scanner; + +public abstract class State { + + protected static State currentState = null; + protected Handler handler; + + protected Scanner sc = new Scanner(System.in); + protected String subState; + + public State(Handler handler) { + this.handler = handler; + } + + public abstract void init(); + public abstract void update(); + public abstract void end(); + + public static State getCurrentState() {return currentState;} + + public static void setCurrentState(State state) {State.currentState = state;} +} \ No newline at end of file diff --git a/src/com/hobogames/utils/Choice.java b/src/com/hobogames/utils/Choice.java new file mode 100644 index 0000000..1434dd8 --- /dev/null +++ b/src/com/hobogames/utils/Choice.java @@ -0,0 +1,32 @@ +package build.com.hobogames.utils; + + +public class Choice { + + private String answer; + private String[] choices; + + public Choice() { + answer = ""; + choices = new String[1]; + } + public Choice(String answer, String[] choices) { + this.answer = answer; + this.choices = new String[choices.length]; + for (int i=0; i < choices.length; i++) { + this.choices[i] = choices[i]; + } + } + + public boolean checkAnswer(String choice) { + for (String c : choices) { + if (choice.equalsIgnoreCase(c)) { + return true; + } + } + return false; + } + + public String getAnswer() {return answer;} + +} \ No newline at end of file diff --git a/src/com/hobogames/utils/Controller.java b/src/com/hobogames/utils/Controller.java new file mode 100644 index 0000000..7bbc511 --- /dev/null +++ b/src/com/hobogames/utils/Controller.java @@ -0,0 +1,54 @@ +package build.com.hobogames.utils; + +import build.com.hobogames.Handler; +import build.com.hobogames.utils.Choice; +import build.com.hobogames.states.State; + +public class Controller { + + private Handler handler; + + private Choice[] moveChoice; + + public Controller(Handler handler) { + this.handler = handler; + } + + public void init() { + moveChoice = new Choice[]{ + new Choice("move north", new String[]{"move north", "north", "walk north", "n"}), + new Choice("move east", new String[]{"move east", "east", "walk east", "e"}), + new Choice("move south", new String[]{"move south", "south", "walk south", "s"}), + new Choice("move west", new String[]{"move west", "west", "walk west", "w"}), + new Choice("quit", new String[]{"quit", "q"}) + }; + } + + public void update() { + System.out.print(" -> "); + String choice = handler.sc.nextLine(); + + for (Choice c : moveChoice) { + if (c.checkAnswer(choice)) { + choice = c.getAnswer(); + } + } + + switch (choice) { + case "move north": handler.getPlayer().move(0,1);break; + case "move east":handler.getPlayer().move(1,0);break; + case "move south": handler.getPlayer().move(0,-1);break; + case "move west": handler.getPlayer().move(-1,0);break; + case "quit": + System.out.println("Quiting the game"); + handler.getPlayState().end(); + State.setCurrentState(handler.getMenuState()); + State.getCurrentState().init(); + break; + default: + System.out.println("Unknown choice."); + } + } + + +} \ No newline at end of file diff --git a/src/com/hobogames/utils/Map.java b/src/com/hobogames/utils/Map.java new file mode 100644 index 0000000..967fc87 --- /dev/null +++ b/src/com/hobogames/utils/Map.java @@ -0,0 +1,90 @@ +package build.com.hobogames.utils; + +import build.com.hobogames.Handler; +import java.lang.Integer; + +public class Map { + + private Handler handler; + private String[][] mapData; + + public Map(Handler handler) { + this.handler = handler; + } + + public void init() { + buildMap(); + } + + public void buildMap() { + ReadFile.setPath("res/maps/Game1_tutorialMap.txt"); + String[] mapFile = ReadFile.getText().split("\n"); + + mapData = new String[Integer.parseInt(mapFile[0].split(" ")[1])][Integer.parseInt(mapFile[0].split(" ")[0])]; + + for (int k = 0; k < mapFile.length; k++) { + String[] object = mapFile[k].split(" "); + switch (object[0]) { + case "room": + for (int j = 0; j < Integer.parseInt(object[4]); j++) { + for (int i = 0; i < Integer.parseInt(object[3]); i++) { + mapData[j + Integer.parseInt(object[2])][i + Integer.parseInt(object[1])] = "."; + } + } + break; + case "hall": + for (int j = 0; j < Integer.parseInt(object[4]); j++) { + for (int i = 0; i < Integer.parseInt(object[3]); i++) { + mapData[j + Integer.parseInt(object[2])][i + Integer.parseInt(object[1])] = "."; + } + } + break; + case "switch": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "S"; + break; + case "lock_door": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "D"; + break; + case "exit": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "E"; + break; + case "enemy": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "@"; + break; + case "pillar": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "#"; + break; + case "door": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "D"; + break; + case "p_plate": + mapData[Integer.parseInt(object[2])][Integer.parseInt(object[1])] = "^"; + break; + } + } + for (int j = 0; j < mapData.length; j++) { + for (int i = 0; i < mapData[j].length; i++) { + if (mapData[j][i] == null) { + if (j+1 != mapData.length && i+1 != mapData[j].length && + (mapData[j+1][i] != null || mapData[j][i+1] != null)) { + mapData[j][i] = "#"; + } else if (j-1 != -1 && i-1 != -1 && + (mapData[j-1][i] != null || mapData[j][i-1] != null) && + (mapData[j-1][i] != "#" || mapData[j][i-1] != "#")) { + mapData[j][i] = "#"; + } else + mapData[j][i] = " "; + } + } + } + } + + public void displayMap() { + for (int j = 0; j < mapData.length; j++) { + for (int i = 0; i < mapData[j].length; i++) { + System.out.print(" " + mapData[j][i]); + } + System.out.println(); + } + } +} \ No newline at end of file diff --git a/src/com/hobogames/utils/ReadFile.java b/src/com/hobogames/utils/ReadFile.java new file mode 100644 index 0000000..6410d4a --- /dev/null +++ b/src/com/hobogames/utils/ReadFile.java @@ -0,0 +1,41 @@ +package build.com.hobogames.utils; + +import java.io.BufferedReader; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.io.File; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileReader; + +public class ReadFile { + + private static File fileToRead; + private static Path pathToFile; + + + public ReadFile() { + + } + + public static void setPath(String path) { + pathToFile = Paths.get(path); + fileToRead = pathToFile.toFile(); + } + + public static String getText() { + String line = ""; + String text = ""; + try (BufferedReader reader = new BufferedReader(new FileReader(fileToRead))) { + line = reader.readLine(); + while (line != null) { + text += line + "\n"; + line = reader.readLine(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + return text; + } + +}