Skip to content

Commit

Permalink
Add basic map, textbox and status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
B1G-SAM committed Mar 10, 2024
1 parent 6fbeb50 commit 2c79ba1
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/main/java/command/mapmove/MovingRightCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
public class MovingRightCommand extends MapMoveCommand {
@Override
public void execute() {

}
}
14 changes: 7 additions & 7 deletions src/main/java/main/CalculaChroniclesOfTheAlgorithmicKingdom.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package main;

import command.Command;
import map.DemoMap;
import map.Map;
import map.FirstMap;
import parser.Parser;
import textbox.PlayerStatus;
import textbox.TextBox;
import ui.Ui;


public class CalculaChroniclesOfTheAlgorithmicKingdom {
public static void main(String[] args) {
new CalculaChroniclesOfTheAlgorithmicKingdom().startGame();
}

public void startGame() {
PlayerStatus playerStatus = new PlayerStatus();
PlayerStatus playerStatus = new PlayerStatus(100, 0, 0);
TextBox textBox = new TextBox();
Parser parser = new Parser();
Map map = new DemoMap();
FirstMap map = new FirstMap();

Ui ui = new Ui();
map.initMap();
map.initMap(30, 10);
map.initPlayerLocation(0,0);
textBox.initTextBox();

Command userCommand;
while (true) {
String userCommandText = ui.readInCommand();
userCommand = parser.parserCommand(userCommandText);
userCommand.execute();

map.nextMapBasedOnCommand(userCommand);
playerStatus.showPlayerStatus();
ui.printPlayerStatus(playerStatus);
textBox.nextTextBoxBasedOnMapAndCommand(userCommand, map);
}
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/map/DemoMap.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/map/FirstMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package map;

public class FirstMap extends Map{
protected String DIFFICULTY_MODIFIER = "easy"; //can use to determine question difficulty
}
75 changes: 72 additions & 3 deletions src/main/java/map/Map.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,77 @@
package map;

import command.Command;
import java.util.ArrayList;

public abstract class Map {
public abstract void initMap();
public abstract void nextMapBasedOnCommand(Command userCommand);
protected int width;
protected int height;
protected ArrayList<ArrayList<Character>> storedMap;
protected int playerX;
protected int playerY;
protected String mapName;



public void initMap(int givenWidth, int givenHeight){
this.width = givenWidth;
this.height = givenHeight;
this.storedMap = new ArrayList<>(height);

for (int i = 0; i < height; i += 1){
ArrayList<Character> row = new ArrayList<>(width);
for (int j = 0; j < width; j += 1){
row.add('.');
}
storedMap.add(row);
}
}


public ArrayList<ArrayList<Character>> getStoredMap() {
return storedMap;
}

public void initPlayerLocation(int x, int y){
if (x >= 0 && x < width && y >= 0 && y < height){
storedMap.get(y).set(x, 'P');
this.playerX = x;
this.playerY = y;
}
}


public void movePlayerUpOne(){
if (this.playerY - 1 >= 0){
storedMap.get(playerY).set(playerX, '.');
storedMap.get(playerY - 1).set(playerX, 'P');
}
}


public void movePlayerDownOne(){
if (this.playerY + 1 < height){
storedMap.get(playerY).set(playerX, '.');
storedMap.get(playerY + 1).set(playerX, 'P');
}
}


public void movePlayerLeftOne(){
if (this.playerX - 1 >= 0){
storedMap.get(playerY).set(playerX, '.');
storedMap.get(playerY).set(playerX - 1, 'P');
}
}


public void movePlayerRightOne(){
if (this.playerY + 1 < width){
storedMap.get(playerY).set(playerX, '.');
storedMap.get(playerY).set(playerX + 1, 'P');
}
}

public void nextMapBasedOnCommand(Command userCommand){
userCommand.execute();
}
}
33 changes: 32 additions & 1 deletion src/main/java/textbox/PlayerStatus.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
package textbox;


public class PlayerStatus {
public void showPlayerStatus(){
private int playerHealth;
private int playerMoney;
private int playerExp;

public PlayerStatus(int startHealth, int startMoney, int startExp){
this.playerHealth = startHealth;
this.playerMoney = startMoney;
this.playerExp = startExp;
}

public int getPlayerHealth(){
return this.playerHealth;
}

public int getPlayerMoney(){
return this.playerMoney;
}

public int getPlayerExp(){
return this.playerExp;
}

public void setPlayerExp(int playerExp) {
this.playerExp = playerExp;
}

public void setPlayerHealth(int playerHealth) {
this.playerHealth = playerHealth;
}

public void setPlayerMoney(int playerMoney) {
this.playerMoney = playerMoney;
}
}
6 changes: 5 additions & 1 deletion src/main/java/textbox/TextBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import map.Map;

public class TextBox {
protected String nextMessage;
public void initTextBox(){

this.nextMessage = " ";
}
public void nextTextBoxBasedOnMapAndCommand(Command userCommand, Map map){

}
public String getNextMessage(){
return nextMessage;
}
}
35 changes: 35 additions & 0 deletions src/main/java/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package ui;
import map.Map;
import textbox.PlayerStatus;
import textbox.TextBox;

import java.util.ArrayList;
import java.util.Scanner;
public class Ui {
public String readInCommand(){
Expand All @@ -7,4 +12,34 @@ public String readInCommand(){
public void printDividingLine(){
System.out.println("===========================================================");
}

public void printPlayerStatus(PlayerStatus statusBar){
printDividingLine();
System.out.print("HEALTH: " + statusBar.getPlayerHealth() + " ");
System.out.print("MONEY: $" + statusBar.getPlayerMoney() + " ");
System.out.println("EXP: " + statusBar.getPlayerExp() + " ");
printDividingLine();
}


public void printTextBox(TextBox box){
printDividingLine();
if (box.getNextMessage() != null) {
System.out.println(box.getNextMessage());
} else {
System.out.println(" ");
}
printDividingLine();
}

public void printMap(Map map){
printDividingLine();
for (ArrayList<Character> row : map.getStoredMap()) {
for (char cell : row) {
System.out.print(cell + " ");
}
System.out.println();
}
printDividingLine();
}
}

0 comments on commit 2c79ba1

Please sign in to comment.