Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra methods to map and battle interface #18

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/main/java/InteractableEntity/Enemy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
public class Enemy extends InteractableEntity{
protected int damage;
protected int defence;
protected int health;

public Enemy(int dmg, int def){
public Enemy(int dmg, int def, int hp){
this.damage = dmg;
this.defence = def;
this.health = hp;
}

public int getHealth(){
return health;
}
public void setDamage(int dmg){
damage = dmg;
}

public void harmHealth(int dmg){
health -= dmg;
}

public int getDefence(){
return defence;
}

public int getDamage() {
return damage;
}
}
4 changes: 1 addition & 3 deletions src/main/java/command/fight/FightingCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package command.fight;

import command.Command;
import map.AMap;
import map.FirstMap;


public class FightingCommand extends Command {
public FightingCommand() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/command/mapmove/InteractingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import map.BattleInterface.BattleInterface;

public class InteractingCommand extends MapMoveCommand {

public InteractingCommand(){
commandDescription = "interact";
}
@Override
public void execute() {
String entityInteractedWith = currentMap.handleInteract();
System.out.println(entityInteractedWith);
AMap battleMap;
switch (entityInteractedWith) {
case "@":
InteractableEntity monster = new Enemy(10, 10);
InteractableEntity monster = new Enemy(10, 10, 10);
battleMap = new BattleInterface(playerStatus, textBox, monster);
battleMap.initMap(30, 10);
currentMap = battleMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void startGame() {
ui.printPlayerStatus(playerStatus);
ui.printMap(map);
}
textBox.nextTextBoxBasedOnMapAndCommand(userCommand, map);
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/map/BattleInterface/BattleInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import InteractableEntity.Enemy;
import InteractableEntity.InteractableEntity;
import command.Command;
import map.AMap;
import parser.Parser;
import textbox.PlayerStatus;
import textbox.TextBox;
import ui.Ui;

import java.lang.management.PlatformLoggingMXBean;
import java.util.ArrayList;
Expand All @@ -14,10 +17,12 @@ public class BattleInterface extends AMap {
protected TextBox currentTextBox;
protected InteractableEntity currentEntity;


public BattleInterface(PlayerStatus player, TextBox text, InteractableEntity entity) {
this.currentPlayer = player;
this.currentTextBox = text;
this.currentEntity = entity;

}

public void initMap(int givenWidth, int givenHeight) {
Expand Down Expand Up @@ -45,4 +50,28 @@ public void initMap(int givenWidth, int givenHeight) {
}
}


public void playerHitEnemy(){
if (currentEntity instanceof Enemy){
int dmgDone = 10 - (10 * ((Enemy) currentEntity).getDefence());
((Enemy) currentEntity).harmHealth(dmgDone);
}
}

public void enemyHitPlayer(){
if (currentEntity instanceof Enemy){
int dmgDone = ((Enemy) currentEntity).getDamage();
currentPlayer.harmHealth(dmgDone);
}
}


public InteractableEntity getCurrentEntity(){
return currentEntity;
}

public PlayerStatus getCurrentPlayer(){
return currentPlayer;
}

}
4 changes: 4 additions & 0 deletions src/main/java/textbox/PlayerStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public void setPlayerHealth(int playerHealth) {
public void setPlayerMoney(int playerMoney) {
this.playerMoney = playerMoney;
}

public void harmHealth(int dmg){
playerHealth -= dmg;
}
}
Loading