Skip to content
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
2 changes: 1 addition & 1 deletion src/main/java/io/rpg/controller/PopupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.stage.Stage;
import javafx.stage.StageStyle;


public class PopupController {

private final Stage popupStage = new Stage(StageStyle.TRANSPARENT);
Expand Down Expand Up @@ -130,7 +131,6 @@ public void openDialoguePopup(String text, Image npcImage, int x, int y) {
}
}


public void hidePopup() {
popupStage.hide();
}
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/io/rpg/model/actions/ActionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ public void onAction(QuizAction action) {
public void acceptQuizResult(boolean correct, int pointsCount) {
var controller = controller();
if (correct) {
controller.getPlayerController().addPoints(pointsCount);
if (pointsCount > 0)
if (pointsCount > 0) {
controller.getPopupController().openPointsPopup(pointsCount, controller.getWindowCenterX(), controller.getWindowCenterY());
controller.getPlayerController().addPoints(pointsCount);
}
} else {
controller.getPopupController().hidePopup();
logger.info("Wrong answer provided");
Expand All @@ -107,8 +108,7 @@ public void onAction(BattleAction action) {
GameObject opponent = action.getOpponent();
int reward = action.getReward();
BattleResult result;
if (player.getPoints() > opponent.getStrength()) {
player.addPoints(reward);
if (player.getStrength() > opponent.getStrength()) {
player.addDefeatedOpponent(opponent.getTag());
result = new BattleResult(BattleResult.Result.VICTORY, reward);
} else if (player.getStrength() < opponent.getStrength()) {
Expand All @@ -118,9 +118,16 @@ public void onAction(BattleAction action) {
}
controller().getPopupController().openTextPopup(result.getMessage(),
controller().getWindowCenterX(), controller().getWindowCenterY());
if (player.getStrength() > opponent.getStrength())
player.addPoints(reward);
});
}

public void onAction(LevelUpAction action) {
controller().getPopupController().openTextPopup("Achieved level " + action.newLevel + "!",
controller().getWindowCenterX(), controller().getWindowCenterY());
}

public void onAction(CollectAction action) {
actionGuard(action, () -> {
var controller = controller();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/rpg/model/actions/LevelUpAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.rpg.model.actions;

import io.rpg.model.actions.condition.Condition;

/**
* Class for storing local data to perform level up action
*/
public class LevelUpAction extends BaseAction {
public final int newLevel;

public LevelUpAction(int newLevel, Condition condition) {
super(condition);
this.newLevel = newLevel;
}

@Override
public void acceptActionEngine(ActionEngine engine) {
engine.onAction(this);
}
}
21 changes: 21 additions & 0 deletions src/main/java/io/rpg/model/object/Player.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.rpg.model.object;

import io.rpg.model.actions.Action;
import io.rpg.model.actions.LevelUpAction;
import io.rpg.model.data.Inventory;
import io.rpg.model.data.Position;
import io.rpg.view.GameObjectView;
Expand All @@ -21,6 +23,8 @@ public class Player extends GameObject {
private boolean downPressed;
private GameObjectView gameObjectView;
private int points;
private int level;
public Action levelUpAction;
private final Inventory inventory;

private final Set<String> defeatedOpponents;
Expand All @@ -34,6 +38,7 @@ public Player(@NotNull String tag, @NotNull Position position, @NotNull String a
this.upPressed = false;
this.downPressed = false;
this.strength = 0;
this.level = 1;
this.defeatedOpponents = new LinkedHashSet<>();
this.inventory = new Inventory();
}
Expand Down Expand Up @@ -100,6 +105,7 @@ public int getPoints() {

public void addPoints(int value) {
points += value;
updateLevel();
}

public void removePoints(int value) {
Expand All @@ -114,6 +120,21 @@ public Inventory getInventory() {
return inventory;
}

public int getLevel() {
return level;
}

public void updateLevel() { //TODO: update different types of stats instead of just strength. Also do not use an arbitrary value
int levelDifference = points / 10;
points %= 10;
if (levelDifference != 0) {
level += levelDifference;
updateStrength(10);
levelUpAction = new LevelUpAction(level, null);
emitAction(levelUpAction);
}
}

public void addDefeatedOpponent(@NotNull String tag) {
this.defeatedOpponents.add(tag);
}
Expand Down