Initial commit
This commit is contained in:
commit
a4a77fb8dd
BIN
Game1_Launcher.class
Normal file
BIN
Game1_Launcher.class
Normal file
Binary file not shown.
9
Game1_Launcher.java
Normal file
9
Game1_Launcher.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
43
about/Game1_GameDesignDoc.txt
Normal file
43
about/Game1_GameDesignDoc.txt
Normal file
@ -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
|
||||||
|
|
BIN
build/com/hobogames/Game.class
Normal file
BIN
build/com/hobogames/Game.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/Handler.class
Normal file
BIN
build/com/hobogames/Handler.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/GOHandler.class
Normal file
BIN
build/com/hobogames/gameobj/GOHandler.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/GameObject.class
Normal file
BIN
build/com/hobogames/gameobj/GameObject.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/entities/Entity.class
Normal file
BIN
build/com/hobogames/gameobj/entities/Entity.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/entities/humans/Human.class
Normal file
BIN
build/com/hobogames/gameobj/entities/humans/Human.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/entities/humans/Player.class
Normal file
BIN
build/com/hobogames/gameobj/entities/humans/Player.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/gameobj/nonentities/Wall.class
Normal file
BIN
build/com/hobogames/gameobj/nonentities/Wall.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/states/MenuState.class
Normal file
BIN
build/com/hobogames/states/MenuState.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/states/PlayState.class
Normal file
BIN
build/com/hobogames/states/PlayState.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/states/State.class
Normal file
BIN
build/com/hobogames/states/State.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/utils/Choice.class
Normal file
BIN
build/com/hobogames/utils/Choice.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/utils/Controller.class
Normal file
BIN
build/com/hobogames/utils/Controller.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/utils/Map.class
Normal file
BIN
build/com/hobogames/utils/Map.class
Normal file
Binary file not shown.
BIN
build/com/hobogames/utils/ReadFile.class
Normal file
BIN
build/com/hobogames/utils/ReadFile.class
Normal file
Binary file not shown.
21
res/maps/Game1_tutorialMap.txt
Normal file
21
res/maps/Game1_tutorialMap.txt
Normal file
@ -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
|
6
res/texts/Game1_intro.txt
Normal file
6
res/texts/Game1_intro.txt
Normal file
@ -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.
|
4
res/texts/Game1_menuScreen.txt
Normal file
4
res/texts/Game1_menuScreen.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
What would you like to do:
|
||||||
|
|
||||||
|
1. Play Game (p)
|
||||||
|
2. Exit Game (q)
|
51
src/com/hobogames/Game.java
Normal file
51
src/com/hobogames/Game.java
Normal file
@ -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;}
|
||||||
|
}
|
26
src/com/hobogames/Handler.java
Normal file
26
src/com/hobogames/Handler.java
Normal file
@ -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();}
|
||||||
|
|
||||||
|
}
|
23
src/com/hobogames/gameobj/GOHandler.java
Normal file
23
src/com/hobogames/gameobj/GOHandler.java
Normal file
@ -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<GameObject> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
src/com/hobogames/gameobj/GameObject.java
Normal file
35
src/com/hobogames/gameobj/GameObject.java
Normal file
@ -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;}
|
||||||
|
|
||||||
|
}
|
65
src/com/hobogames/gameobj/entities/Entity.java
Normal file
65
src/com/hobogames/gameobj/entities/Entity.java
Normal file
@ -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;}
|
||||||
|
}
|
38
src/com/hobogames/gameobj/entities/humans/Human.java
Normal file
38
src/com/hobogames/gameobj/entities/humans/Human.java
Normal file
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
46
src/com/hobogames/gameobj/entities/humans/Player.java
Normal file
46
src/com/hobogames/gameobj/entities/humans/Player.java
Normal file
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
28
src/com/hobogames/gameobj/nonentities/Wall.java
Normal file
28
src/com/hobogames/gameobj/nonentities/Wall.java
Normal file
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
src/com/hobogames/states/MenuState.java
Normal file
60
src/com/hobogames/states/MenuState.java
Normal file
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
43
src/com/hobogames/states/PlayState.java
Normal file
43
src/com/hobogames/states/PlayState.java
Normal file
@ -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;}
|
||||||
|
}
|
25
src/com/hobogames/states/State.java
Normal file
25
src/com/hobogames/states/State.java
Normal file
@ -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;}
|
||||||
|
}
|
32
src/com/hobogames/utils/Choice.java
Normal file
32
src/com/hobogames/utils/Choice.java
Normal file
@ -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;}
|
||||||
|
|
||||||
|
}
|
54
src/com/hobogames/utils/Controller.java
Normal file
54
src/com/hobogames/utils/Controller.java
Normal file
@ -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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
90
src/com/hobogames/utils/Map.java
Normal file
90
src/com/hobogames/utils/Map.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
src/com/hobogames/utils/ReadFile.java
Normal file
41
src/com/hobogames/utils/ReadFile.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user