Skip to content

Commit

Permalink
feat: improve alpha demo & some fixes (#53)
Browse files Browse the repository at this point in the history
* feat: auto generate description (onRightClick, initial)

* feat: add świstoklik

* chore: remove redundant _XD bushes

* fix: correct answer check

* fix: tests

* fix: quick fixes for numerous bugs & battle action

* feat: add new assets

* feat: add Goblin & co.
  • Loading branch information
kkafar authored May 24, 2022
1 parent 46bacc5 commit 741d924
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 57 deletions.
Binary file added assets/bandit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/boxing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bunny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/goblin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{ "tag": "mul-1", "position": { "row": 6, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 7, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 8, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "object-1", "position": { "row": 7, "col": 8 }, "assetPath": "assets/diamond.png" },
{ "tag": "object-1", "position": { "row": 7, "col": 8 }, "assetPath": "assets/bunny.png" },
{ "tag": "object-2", "position": { "row": 6, "col": 3 }, "assetPath": "assets/key.png" },
{ "tag": "object-3", "position": { "row": 2, "col": 0 }, "assetPath": "assets/zombie.png" },
{ "tag": "object-4", "position": { "row": 3, "col": 7 }, "assetPath": "assets/zombie.png" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
{
"tag": "object-3",
"assetPath": "assets/zombie.png",
"assetPath": "assets/bandit.png",
"type": "dialog",
"onLeftClick": {
"tag": "quiz",
"type": "quiz",
"questions": [
{
"question": "Programy komputerowe chronione są: ",
"a": "prawem autorskim, co wyklucza możliwość uzyskania ochrony patentowej przez program komputerowy",
"b": "prawem autorskim, a w pewnych przypadkach mogą uzyskać ochronę patentową",
"c": "jak utwory literackie",
"d": "nie są chronione",
"correct": "b"
}
],
"reward": 5
"tag": "battle",
"type": "battle",
"reward": 10
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tag": "object-6",
"position": { "row": 6, "col": 1 },
"assetPath": "assets/zombie.png",
"assetPath": "assets/bush.png",
"onLeftClick": {
"tag": "change-location",
"type": "location-change",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@
{ "tag": "mul-1", "position": { "row": 8, "col": 6 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 0, "col": 7 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 0, "col": 8 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 0, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 7, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 8, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 9, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "object-1", "position": { "row": 1, "col": 1 }, "assetPath": "assets/diamond.png" },
{ "tag": "object-2", "position": { "row": 15, "col": 15 }, "assetPath": "assets/key.png" },
{ "tag": "object-1", "position": { "row": 1, "col": 1 }, "assetPath": "assets/bunny.png" },
{ "tag": "object-3", "position": { "row": 2, "col": 3 }, "assetPath": "assets/zombie.png" },
{ "tag": "object-4", "position": { "row": 6, "col": 0 }, "assetPath": "assets/zombie.png" },
{ "tag": "object-5", "position": { "row": 5, "col": 8 }, "assetPath": "assets/zombie.png" },
{ "tag": "object-6", "position": { "row": 7, "col": 4 }, "assetPath": "assets/chest.png" },
{ "tag": "object-7", "position": { "row": 7, "col": 7 }, "assetPath": "assets/bush.png" }
{ "tag": "object-6", "position": { "row": 7, "col": 4 }, "assetPath": "assets/goblin.png" },
{ "tag": "object-7", "position": { "row": 7, "col": 7 }, "assetPath": "assets/bush.png" },
{ "tag": "object-8", "position": { "row": 8, "col": 8 }, "assetPath": "assets/coin.png" }
],
"backgroundPath": "assets/map.png",
"north": "location-3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"tag": "object-6",
"onLeftClick": {"tag": "action", "type": "dialogue", "statements": ["A very old chest."], "assetPath": "assets/chest.png"}
"onLeftClick": {
"tag": "action",
"type": "dialogue",
"statements": [
"Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen."
],
"assetPath": "assets/goblin.png"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tag": "object-8",
"assetPath": "assets/bunny.png",
"onLeftClick": {
"tag": "action-tag",
"type": "location-change",
"target-location": "location-3",
"target-position": { "row": 3, "col": 5 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{ "tag": "mul-1", "position": { "row": 7, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 8, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "mul-1", "position": { "row": 9, "col": 9 }, "assetPath": "assets/bush.png" },
{ "tag": "object-1", "position": { "row": 6, "col": 5 }, "assetPath": "assets/diamond.png"},
{ "tag": "object-1", "position": { "row": 6, "col": 5 }, "assetPath": "assets/bunny.png"},
{ "tag": "object-2", "position": { "row": 5, "col": 0 }, "assetPath": "assets/zombie.png" },
{ "tag": "object-3", "position": { "row": 1, "col": 1 }, "assetPath": "assets/zombie.png" }
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tag": "object-1",
"assetPath": "assets/knight.png",
"onLeftClick": {"tag": "actiontag", "type": "game-end", "description": "You won, congratulations!"}
}
3 changes: 2 additions & 1 deletion configurations/demo-config-1/root.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"position": { "row": 4, "col": 5 },
"type": "player",
"assetPath": "assets/knight.png",
"location": "location-1"
"location": "location-1",
"strength": 911
},
"textPopupBackground": "assets/popup-background.png",
"textPopupButton": "assets/button-image.png",
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/rpg/config/model/ActionConfigBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public class ActionConfigBundle {
// TODO: Create QuestionConfig model class
private List<Question> questions;


@Nullable
@SerializedName(value = "reward", alternate = {"reward-points", "rewardPoints"})
// TODO: consider introducing reward type & then we can parse the reward string
Expand Down Expand Up @@ -249,6 +248,10 @@ Result<Void, Exception> validateForShowDescriptionAction() {
return builder.isEmpty() ? Result.ok() : Result.err(new IllegalStateException(builder.toString()));
}

Result<Void, Exception> validateForBattle() {
return Result.ok();
}

Result<Void, Exception> validateBasic() {
ErrorMessageBuilder builder = new ErrorMessageBuilder();
if (tag == null) {
Expand Down Expand Up @@ -286,6 +289,7 @@ public Result<Void, Exception> validate() {
case LocationChange -> { return validateForLocationChangeAction(); }
case Quiz -> { return validateForQuizAction(); }
case ShowDescription -> { return validateForShowDescriptionAction(); }
case Battle -> { return validateForBattle(); }
default -> { return Result.err(new RuntimeException("Invalid result returned")); }
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/rpg/config/model/PlayerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class PlayerConfig extends GameObjectConfig {
@SerializedName("location")
private String initialLocationTag;

private int strength;

public PlayerConfig(@NotNull String tag, @NotNull Position position) {
super(tag, position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/rpg/controller/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void onAction(BattleAction action) {
GameObject opponent = action.getOpponent();
int reward = action.getReward();
BattleResult result;
if (player.getStrength() > opponent.getStrength()) {
if (player.getPoints() > opponent.getStrength()) {
player.addPoints(reward);
result = new BattleResult(BattleResult.Result.VICTORY, reward);
} else if (player.getStrength() < opponent.getStrength()) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/rpg/model/actions/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public enum ActionType {
ShowDescription("show-description"),

@SerializedName("dialogue")
Dialogue("dialogue");
Dialogue("dialogue"),

@SerializedName("battle")
Battle("battle");

private final String asString;

Expand All @@ -37,6 +40,7 @@ public static Optional<ActionType> fromString(String action) {
case "location-change" -> { return Optional.of(LocationChange); }
case "show-description" -> { return Optional.of(ShowDescription); }
case "dialogue" -> { return Optional.of(Dialogue); }
case "battle" -> { return Optional.of(Battle); }
default -> { return Optional.empty(); }
}
}
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/io/rpg/model/actions/BattleAction.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package io.rpg.model.actions;

import io.rpg.Game;
import io.rpg.model.object.GameObject;
import io.rpg.model.object.Player;

public class BattleAction {
private final GameObject opponent;
private final int reward;
public class BattleAction implements Action {
private GameObject opponent;
private final int reward;

public BattleAction(GameObject opponent, int reward) {
this.opponent = opponent;
this.reward = reward;
}
public BattleAction(int reward) {
this.reward = reward;
}

public GameObject getOpponent() {
return opponent;
}
public void setOpponent(GameObject object) {
this.opponent = object;
}

public int getReward() {
return reward;
}
public GameObject getOpponent() {
return opponent;
}

public int getReward() {
return reward;
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/rpg/model/object/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public String getCorrectAnswer() {
}

public char getCorrectAnswerChar() {
return correctAnswerChar;
return Character.toUpperCase(correctAnswerChar);
}
}
7 changes: 7 additions & 0 deletions src/main/java/io/rpg/util/ActionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static Action fromConfig(ActionConfigBundle config) {
case ShowDescription -> {
return showDescriptionActionFromConfig(config);
}
case Battle -> {
return battleActionFromConfig(config);
}
default -> {
throw new IllegalArgumentException("Unexpected action type!");
}
Expand Down Expand Up @@ -59,4 +62,8 @@ private static LocationChangeAction locationChangeActionFromConfig(ActionConfigB
private static ShowDescriptionAction showDescriptionActionFromConfig(ActionConfigBundle config) {
return new ShowDescriptionAction(config.getDescription(), new Image("file:" + config.getAssetPath()));
}

private static BattleAction battleActionFromConfig(ActionConfigBundle config) {
return new BattleAction(config.getRewardPoints());
}
}
21 changes: 21 additions & 0 deletions src/main/java/io/rpg/util/GameObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import io.rpg.config.model.GameObjectConfig;
import io.rpg.config.model.PlayerConfig;
import io.rpg.model.actions.Action;
import io.rpg.model.actions.BattleAction;
import io.rpg.model.actions.ShowDescriptionAction;
import io.rpg.model.object.GameObject;
import io.rpg.model.object.Player;
import javafx.scene.image.Image;


import java.util.LinkedList;
Expand All @@ -24,21 +27,39 @@ public static GameObject fromConfig(GameObjectConfig config) {
Action onLeftClickAction = config.getOnLeftClick() != null ? ActionFactory.fromConfig(config.getOnLeftClick()) : Action.VOID;
Action onRightClickAction = config.getOnRightClick() != null ? ActionFactory.fromConfig(config.getOnRightClick()) : Action.VOID;

if (onRightClickAction.equals(Action.VOID)) {
onRightClickAction = new ShowDescriptionAction(
DataObjectDescriptionProvider.combineDescriptions(
DataObjectDescriptionProvider.getFieldDescription(config, GameObjectConfig.class)
),
new Image("file:" + config.getAssetPath())
);
}

// Not implemented in model for now, however they should be
Action onClickAction = config.getOnClick() != null ? ActionFactory.fromConfig(config.getOnClick()) : Action.VOID;
Action onApproach = config.getOnApproach() != null ? ActionFactory.fromConfig(config.getOnApproach()) : Action.VOID;


if (config instanceof PlayerConfig) {
Player player = new Player(config.getTag(), config.getPosition(), config.getAssetPath());
player.setOnLeftClickAction(onLeftClickAction);
player.setOnRightClickAction(onRightClickAction);
// player.setStrength(config.getStrength());
return player;
} else {
GameObject gameObject = new GameObject(config.getTag(), config.getPosition());

gameObject.setOnLeftClickAction(onLeftClickAction);
gameObject.setOnRightClickAction(onRightClickAction);;

if (onLeftClickAction instanceof BattleAction) {
((BattleAction) onLeftClickAction).setOpponent(gameObject);
}
if (onRightClickAction instanceof BattleAction) {
((BattleAction) onRightClickAction).setOpponent(gameObject);
}

// TODO: Create ActionFactory & inflate the actions
return gameObject;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/io/rpg/viewmodel/question-popup-view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
<Font name="Monospaced Bold" size="18.0" />
</font>
</Label>
<Button fx:id="bButton" cancelButton="true" contentDisplay="CENTER" layoutX="255.0" layoutY="200.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="B:" textAlignment="CENTER" textFill="WHITE">
<Button fx:id="bButton" cancelButton="true" contentDisplay="CENTER" layoutX="255.0" layoutY="200.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="B:" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Monospaced Bold" size="14.0" />
<Font name="Monospaced Bold" size="12" />
</font>
</Button>
<Button fx:id="aButton" cancelButton="true" contentDisplay="CENTER" layoutX="45.0" layoutY="200.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="A:" textAlignment="CENTER" textFill="WHITE">
<Button fx:id="aButton" cancelButton="true" contentDisplay="CENTER" layoutX="45.0" layoutY="200.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="A:" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Monospaced Bold" size="14.0" />
<Font name="Monospaced Bold" size="12" />
</font>
</Button>
<Button fx:id="dButton" cancelButton="true" contentDisplay="CENTER" layoutX="255.0" layoutY="310.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="D:" textAlignment="CENTER" textFill="WHITE">
<Button fx:id="dButton" cancelButton="true" contentDisplay="CENTER" layoutX="255.0" layoutY="310.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="D:" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Monospaced Bold" size="14.0" />
<Font name="Monospaced Bold" size="12" />
</font>
</Button>
<Button fx:id="cButton" cancelButton="true" contentDisplay="CENTER" layoutX="45.0" layoutY="310.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="C:" textAlignment="CENTER" textFill="WHITE">
<Button fx:id="cButton" cancelButton="true" contentDisplay="CENTER" layoutX="45.0" layoutY="310.0" mnemonicParsing="false" prefHeight="100.0" prefWidth="200.0" style="-fx-background-color: BB722E;" styleClass="answer_button" stylesheets="@../../../css/styles.css" text="C:" textAlignment="CENTER" textFill="WHITE" wrapText="true">
<font>
<Font name="Monospaced Bold" size="14.0" />
<Font name="Monospaced Bold" size="12" />
</font>
</Button>
</children>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/rpg/model/object/QuestionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void testDeserialization() {
Assertions.assertEquals(question.getAnswerB(), "2");
Assertions.assertEquals(question.getAnswerC(), "3");
Assertions.assertEquals(question.getAnswerD(), "4");
Assertions.assertEquals(question.getCorrectAnswerChar(), 'b');
Assertions.assertEquals(question.getCorrectAnswerChar(), 'B');
Assertions.assertEquals(question.getCorrectAnswer(), "2");
}

Expand All @@ -52,7 +52,7 @@ public void testAlternateFieldNaming() {
Assertions.assertEquals(question.getAnswerB(), "2");
Assertions.assertEquals(question.getAnswerC(), "3");
Assertions.assertEquals(question.getAnswerD(), "4");
Assertions.assertEquals(question.getCorrectAnswerChar(), 'b');
Assertions.assertEquals(question.getCorrectAnswerChar(), 'B');
Assertions.assertEquals(question.getCorrectAnswer(), "2");
}

Expand Down

0 comments on commit 741d924

Please sign in to comment.