Skip to content

Commit

Permalink
Merge pull request #48 from Our-Magic-Journey/mine
Browse files Browse the repository at this point in the history
Mine
  • Loading branch information
AmonDeShir authored Jan 9, 2024
2 parents 44955cb + abeca79 commit 3b5c33d
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 11 deletions.
5 changes: 5 additions & 0 deletions core/src/xyz/magicjourney/nebulaquest/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public void movePlayer(Player player, int moveBy, boolean isFinalMove) {
finalPos -= this.fields.length();
}

// Start field
if (pawn.getField() == 0 && finalPos != 0) {
this.fields.get(0).getEntity().onPass(player);
}

for (int i = pawn.getField() + 1; i <= finalPos; i++) {
this.fields.get(i).getEntity().onPass(player);
}
Expand Down
13 changes: 8 additions & 5 deletions core/src/xyz/magicjourney/nebulaquest/dice/Dice.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ public Dice(AssetManager assets) {
this.rollNumber = 0;

this.debugRolls = new int[] {
5, 5, 5,
5, 2,
5, 6,
5, 12
12, 1,
12, 1,
12, 2,
2, 2, 1,
12, 11,
12, 11,
12, 11
};
}

Expand All @@ -54,7 +57,7 @@ protected int debugRoll() {

public void roll(Consumer<Integer> callback) {
int result = this.random.nextInt(11) + 1;
// int result = this.debugRoll();
//int result = this.debugRoll();

if (this.isRolling) {
return;
Expand Down
63 changes: 61 additions & 2 deletions core/src/xyz/magicjourney/nebulaquest/entity/entities/Mine.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package xyz.magicjourney.nebulaquest.entity.entities;

import java.util.Optional;
import java.util.Random;

import com.badlogic.gdx.assets.AssetManager;

import xyz.magicjourney.nebulaquest.board.field.Field;
import xyz.magicjourney.nebulaquest.entity.Buyable;
import xyz.magicjourney.nebulaquest.entity.Entity;
import xyz.magicjourney.nebulaquest.player.Player;

public class Mine extends Entity {
public class Mine extends Entity implements Buyable {
protected static final int BASE_PROFIT = 50;
protected int value;
protected Optional<Player> owner;
protected Random random;

public Mine() {
super("Asteroid Mine", "");
super("Asteroid Mine", "On this planet operates a Republic-owned mine, and since it's poorly paid, surely you can strike a good deal with the local manager");

this.value = 500;
this.owner = Optional.empty();
this.random = new Random();
}

@Override
Expand All @@ -17,10 +30,56 @@ public void onEnter(Player player) {

@Override
public void onPass(Player player) {
if (this.isOwner(player)) {
player.giveMoney((int) (BASE_PROFIT * (random.nextFloat() + 1)));
}
}

@Override
public Field toField(AssetManager assets) {
return new Field(this, "images/mine", assets);
}

@Override
public boolean canByBought() {
return true;
}

@Override
public Optional<Player> getOwner() {
return this.owner;
}

@Override
public int getValue() {
if (this.getOwner().isEmpty()) {
return this.value;
}

return (int) (this.value * 1.5);
}

public int setValue(int value) {
return this.value;
}

@Override
public int getFee() {
return 0;
}

@Override
public void setOwner(Player player) {
this.owner = Optional.of(player);
}

@Override
public String getInteractiveablePanelName(Player player) {
return "Mine";
}

@Override
public boolean isDecisionRequired(Player player) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void onEnter(Player player) {

@Override
public void onPass(Player player) {
System.out.println("Give money!");
player.setMoney(player.getMoney() + MONEY_ON_PASS_START);
player.giveMoney(MONEY_ON_PASS_START);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions core/src/xyz/magicjourney/nebulaquest/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public boolean buyProperty(Buyable property) {
public boolean payFee(Buyable property) {
if (property.mustPayFee(this) && this.pay(property.getFee())) {
Player owner = property.getOwner().get();

owner.setMoney(owner.getMoney() + property.getFee());


System.out.println(this.getName() + " pays " + owner.getName() + " " + property.getFee() + " credits for " + property.getName());

return true;
}

Expand All @@ -89,6 +90,8 @@ public boolean pay(int value) {
}

public void giveMoney(int value) {
System.out.println(this.getName() + " gets " + value + " credits");

this.setMoney(this.getMoney() + value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.CasinoInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.DescriptionInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.HubInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.MineInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.PayFeeInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.PlayerInteractiveView;
import xyz.magicjourney.nebulaquest.ui.panel.views.interactive.PlayersInteractiveView;
Expand Down Expand Up @@ -42,6 +43,7 @@ public InteractivePanel(AssetManager assets, Dice dice, TourPanel tourPanel, Pla
this.views.put("Hub", new HubInteractiveView(assets, this, tourPanel, board));
this.views.put("Teleport", new TeleportInteractiveView(assets, this, tourPanel, board));
this.views.put("TeleportPayFee", new TeleportPayFeeInteractiveView(assets, this, tourPanel));
this.views.put("Mine", new MineInteractiveView(assets, this, tourPanel));
this.views.put("UnknownJump", new UnknownJumpInteractiveView(assets, this, tourPanel, board));

this.content.pad(4, 4, 4, 4);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package xyz.magicjourney.nebulaquest.ui.panel.views.interactive;

import java.util.function.Consumer;

import com.badlogic.gdx.assets.AssetManager;

import xyz.magicjourney.nebulaquest.entity.Describable;
import xyz.magicjourney.nebulaquest.entity.Entity;
import xyz.magicjourney.nebulaquest.entity.entities.Mine;
import xyz.magicjourney.nebulaquest.player.Player;
import xyz.magicjourney.nebulaquest.ui.button.ActionButton;
import xyz.magicjourney.nebulaquest.ui.panel.TourPanel;
import xyz.magicjourney.nebulaquest.ui.panel.InteractivePanel;

public class MineInteractiveView extends DescriptionInteractiveView {
protected ActionButton buyButton;

protected Mine property;
protected Player player;

public MineInteractiveView(AssetManager assets, InteractivePanel parent, TourPanel tourPanel) {
super(assets, parent, tourPanel);

this.buyButton = new ActionButton("Buy", true, assets);
this.buyButton.onClick().subscribe(this.handleBuyClick);
}

@Override
public void createLayout(Describable entity, boolean displayDescription) {
super.createLayout(entity, true);

this.addSpacer();
this.add(this.buyButton).height(20).pad(2, 4, 0, 4).fillX().row();;
}

protected void generateDescription() {
String text = this.splitText(23, "There is a mine working for the Republic on this planet. Its manager is willing to share with you some 'excess' ore below market price. However, you must first prove to them that you are a trustworthy person.");

this.description.setText(text);
}

@Override
public void prepareForNextTurn() {
if (this.player != null) {
this.player.onChange().unsubscribe(this.update);
}

this.player = null;
this.property = null;
this.buyButton.setDisabled(true);
}

@Override
public void select(Player player, Entity field) {
this.display(field);

if (this.player == null) {
this.player = player;
this.player.onChange().subscribe(this.update);
}

if (field instanceof Mine property) {
this.property = property;

if (player.getMoney() >= property.getValue()) {
this.buyButton.setDisabled(false);
this.generateDescription();

return;
}
}
}

protected Consumer<Player> update = (player) -> {
this.buyButton.setDisabled(player.getMoney() < this.property.getValue());
};

protected Consumer<Runnable> handleBuyClick = (unblock) -> {
this.player.buyProperty(this.property);
this.owner.setText("Owner: " + this.player.getName());
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.magicjourney.nebulaquest.ui.panel.views.interactive;

import java.util.function.Consumer;

import com.badlogic.gdx.assets.AssetManager;

import xyz.magicjourney.nebulaquest.entity.Buyable;
Expand All @@ -12,6 +14,8 @@
public class TeleportPayFeeInteractiveView extends PayFeeInteractiveView {
public TeleportPayFeeInteractiveView(AssetManager assets, InteractivePanel parent, TourPanel tourPanel) {
super(assets, parent, tourPanel);

this.payButton.onClick().subscribe(this.handlePayClick);
}

@Override
Expand Down Expand Up @@ -57,4 +61,12 @@ protected void showDescriptionInstead() {
this.parent.select("Teleport");
this.tourPanel.unblockTurnButton();
}

protected Consumer<Runnable> handlePayClick = (unblock) -> {
this.bankruptButton.setDisabled(true);
this.player.payFee(this.property);

this.showDescriptionInstead();
};

}
Empty file modified gradlew
100755 → 100644
Empty file.

0 comments on commit 3b5c33d

Please sign in to comment.