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

Finished QueueProvider rework #259

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions src/main/java/com/jadventure/game/CharacterChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.jadventure.game.entities.Player;
import com.jadventure.game.queueprovider.QueueProvider;

public class CharacterChange {
public void trigger(Player player, String triggerType, String keyword) {
Expand All @@ -34,13 +35,13 @@ public void trigger(Player player, String triggerType, String keyword) {
characterEffects = events.get(keyword).getAsJsonObject();
goAhead = true;
} else {
//QueueProvider.offer("Warning: The effects for the '" + triggerType + "' event and the '" + currentCharacter + "' character was not found");
//QueueProvider.getInstance().offer("Warning: The effects for the '" + triggerType + "' event and the '" + currentCharacter + "' character was not found");
}
} else {
//QueueProvider.offer("Warning: The event '" + triggerType + "' for the '" + currentCharacter + "' character was not found");
//QueueProvider.getInstance().offer("Warning: The event '" + triggerType + "' for the '" + currentCharacter + "' character was not found");
}
} else {
//QueueProvider.offer("Warning: The character '" + currentCharacter + "' was not found");
//QueueProvider.getInstance().offer("Warning: The character '" + currentCharacter + "' was not found");
}

if (goAhead == true) {
Expand Down Expand Up @@ -75,7 +76,7 @@ public void checkForCharacterChange(Player player) {
}
if (!highestCharacter.equals(currentCharacter)) {
player.setCurrentCharacterType(highestCharacter);
QueueProvider.offer("You're character type is now changed! You are now a " + highestCharacter + "!");
QueueProvider.getInstance().offer("You're character type is now changed! You are now a " + highestCharacter + "!");
}
it = characterLevels.entrySet().iterator();
while (it.hasNext()) {
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/com/jadventure/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.jadventure.game.monsters.MonsterFactory;
import com.jadventure.game.repository.LocationRepository;
import com.jadventure.game.prompts.CommandParser;
import com.jadventure.game.queueprovider.QueueProvider;

import java.util.ArrayList;

Expand All @@ -27,13 +28,13 @@ public Game(Player player, String playerType) throws DeathException {
newGameStart(player);
break;
case "old":
QueueProvider.offer("Welcome back, " + player.getName() + "!");
QueueProvider.offer("");
QueueProvider.getInstance().offer("Welcome back, " + player.getName() + "!");
QueueProvider.getInstance().offer("");
player.getLocation().print();
gamePrompt(player);
break;
default:
QueueProvider.offer("Invalid player type");
QueueProvider.getInstance().offer("Invalid player type");
break;
}
}
Expand All @@ -44,13 +45,13 @@ public Game(Player player, String playerType) throws DeathException {
* character and welcomes him / her. After that, it goes to the normal game prompt.
*/
public void newGameStart(Player player) throws DeathException {
QueueProvider.offer(player.getIntro());
String userInput = QueueProvider.take();
QueueProvider.getInstance().offer(player.getIntro());
String userInput = QueueProvider.getInstance().take();
player.setName(userInput);
LocationRepository locationRepo = GameBeans.getLocationRepository(player.getName());
this.player.setLocation(locationRepo.getInitialLocation());
player.save();
QueueProvider.offer("Welcome to Silliya, " + player.getName() + ".");
QueueProvider.getInstance().offer("Welcome to Silliya, " + player.getName() + ".");
player.getLocation().print();
gamePrompt(player);
}
Expand All @@ -65,8 +66,8 @@ public void gamePrompt(Player player) throws DeathException {
boolean continuePrompt = true;
try {
while (continuePrompt) {
QueueProvider.offer("\nPrompt:");
String command = QueueProvider.take().toLowerCase();
QueueProvider.getInstance().offer("\nPrompt:");
String command = QueueProvider.getInstance().take().toLowerCase();
continuePrompt = parser.parse(player, command);
}
} catch (DeathException e) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/jadventure/game/JAdventure.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.jadventure.game;

import com.jadventure.game.menus.MainMenu;
import com.jadventure.game.QueueProvider;
import com.jadventure.game.Client;

import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;

import com.jadventure.game.queueprovider.QueueProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,7 +54,7 @@ public static void main(String[] args) {
}
}
} else {
QueueProvider.startMessenger(GameModeType.STAND_ALONE);
QueueProvider.startStandaloneMessenger();
new MainMenu();
}
}
Expand Down
111 changes: 0 additions & 111 deletions src/main/java/com/jadventure/game/QueueProvider.java

This file was deleted.

34 changes: 18 additions & 16 deletions src/main/java/com/jadventure/game/Trading.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.jadventure.game.menus.Menus;
import com.jadventure.game.repository.ItemRepository;

import com.jadventure.game.queueprovider.QueueProvider;

public class Trading {
NPC npc;
Player player;
Expand Down Expand Up @@ -48,11 +50,11 @@ public void trade(boolean buy, boolean sell) {
}

public void playerBuy() {
QueueProvider.offer(npc.getName() + "'s items:\t" + npc.getName() + "'s gold:" + npc.getGold() + "\n");
QueueProvider.offer(npc.getStorage().displayWithValue(0, 0));
QueueProvider.getInstance().offer(npc.getName() + "'s items:\t" + npc.getName() + "'s gold:" + npc.getGold() + "\n");
QueueProvider.getInstance().offer(npc.getStorage().displayWithValue(0, 0));

QueueProvider.offer("You have " + player.getGold() + " gold coins.\nWhat do you want to buy?");
String itemName = QueueProvider.take();
QueueProvider.getInstance().offer("You have " + player.getGold() + " gold coins.\nWhat do you want to buy?");
String itemName = QueueProvider.getInstance().take();

if ("exit".equals(itemName) || "back".equals(itemName)) {
return;
Expand All @@ -61,23 +63,23 @@ public void playerBuy() {
Item item = tradeItem(npc, player, itemName);
if (item != null) {
if (item != itemRepo.getItem("empty")) {
QueueProvider.offer("You have bought a " + item.getName() + " for " + item.getProperties().get("value") + " gold coins.");
QueueProvider.offer("You now have " + player.getGold() + " gold coins remaining.");
QueueProvider.getInstance().offer("You have bought a " + item.getName() + " for " + item.getProperties().get("value") + " gold coins.");
QueueProvider.getInstance().offer("You now have " + player.getGold() + " gold coins remaining.");
}
else {
QueueProvider.offer("You do not have enough money!");
QueueProvider.getInstance().offer("You do not have enough money!");
}
} else {
QueueProvider.offer("Either this item doesn't exist or this character does not own that item");
QueueProvider.getInstance().offer("Either this item doesn't exist or this character does not own that item");
}
}

public void playerSell() {
QueueProvider.offer(player.getName() + "'s items:\t" + npc.getName() + "'s gold:" + npc.getGold() + "\n");
QueueProvider.offer(player.getStorage().displayWithValue(player.getLuck(), player.getIntelligence()));
QueueProvider.getInstance().offer(player.getName() + "'s items:\t" + npc.getName() + "'s gold:" + npc.getGold() + "\n");
QueueProvider.getInstance().offer(player.getStorage().displayWithValue(player.getLuck(), player.getIntelligence()));

QueueProvider.offer("You have " + player.getGold() + " gold coins.\nWhat do you want to sell?");
String itemName = QueueProvider.take();
QueueProvider.getInstance().offer("You have " + player.getGold() + " gold coins.\nWhat do you want to sell?");
String itemName = QueueProvider.getInstance().take();

if ("exit".equals(itemName) || "back".equals(itemName)) {
return;
Expand All @@ -86,14 +88,14 @@ public void playerSell() {
Item item = tradeItem(player, npc, itemName);
if (item != null) {
if (item != itemRepo.getItem("empty")) {
QueueProvider.offer("You have sold a " + item.getName() + " for " + (player.getGold() - goldBefore) + " gold coins.");
QueueProvider.offer("You now have " + player.getGold() + " gold coins remaining.");
QueueProvider.getInstance().offer("You have sold a " + item.getName() + " for " + (player.getGold() - goldBefore) + " gold coins.");
QueueProvider.getInstance().offer("You now have " + player.getGold() + " gold coins remaining.");
}
else {
QueueProvider.offer(npc.getName() + " does not have enough money!");
QueueProvider.getInstance().offer(npc.getName() + " does not have enough money!");
}
} else {
QueueProvider.offer("Either this item doesn't exist or this character does not own that item");
QueueProvider.getInstance().offer("Either this item doesn't exist or this character does not own that item");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.jadventure.game.items.Item;
import com.jadventure.game.repository.EncounteredNpcRepository;
import com.jadventure.game.repository.ItemRepository;
import com.jadventure.game.QueueProvider;
import com.jadventure.game.DeathException;
import com.jadventure.game.Trading;
import com.jadventure.game.queueprovider.QueueProvider;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -131,11 +131,11 @@ public void startConversation(NPC npc, Player player) throws DeathException {
}
}
if (start != null) {
QueueProvider.offer(start.getText());
QueueProvider.getInstance().offer(start.getText());
Line response = start.display(npc, player, conversation);
triggerAction(start, npc, player);
while (response != null) {
QueueProvider.offer(response.getText());
QueueProvider.getInstance().offer(response.getText());
triggerAction(response, npc, player);
Line temp_response = response.display(npc, player, conversation);
response = temp_response;
Expand All @@ -147,7 +147,7 @@ public void startConversation(NPC npc, Player player) throws DeathException {
private void triggerAction(Line line, NPC npc, Player player) throws DeathException {
switch (line.getAction()) {
case ATTACK:
QueueProvider.offer("\n" + npc.getName() + " is now attacking you!\n");
QueueProvider.getInstance().offer("\n" + npc.getName() + " is now attacking you!\n");
player.attack(npc.getName());
break;
case TRADE:
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jadventure/game/conversation/Line.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jadventure.game.conversation;


import com.jadventure.game.entities.NPC;
import com.jadventure.game.entities.Player;
import com.jadventure.game.menus.Menus;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/jadventure/game/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Map;

import com.jadventure.game.GameBeans;
import com.jadventure.game.QueueProvider;
import com.jadventure.game.items.Item;
import com.jadventure.game.items.ItemStack;
import com.jadventure.game.items.Storage;
import com.jadventure.game.repository.ItemRepository;
import com.jadventure.game.queueprovider.QueueProvider;

/**
* superclass for all entities (includes player, monsters...)
Expand Down Expand Up @@ -295,10 +295,10 @@ public Map<String, String> unequipItem(Item item) {
}

public void printEquipment() {
QueueProvider.offer("\n------------------------------------------------------------");
QueueProvider.offer("Equipped Items:");
QueueProvider.getInstance().offer("\n------------------------------------------------------------");
QueueProvider.getInstance().offer("Equipped Items:");
if (equipment.keySet().size() == 0) {
QueueProvider.offer("--Empty--");
QueueProvider.getInstance().offer("--Empty--");
} else {
int i = 0;
Item hands = itemRepo.getItem("hands");
Expand All @@ -315,16 +315,16 @@ public void printEquipment() {
locations.put(EquipmentLocation.FEET, "Feet");
for (Map.Entry<EquipmentLocation, Item> item : equipment.entrySet()) {
if (item.getKey() != null && !hands.equals(item.getValue()) && item.getValue() != null) {
QueueProvider.offer(locations.get(item.getKey()) + " - " + item.getValue().getName());
QueueProvider.getInstance().offer(locations.get(item.getKey()) + " - " + item.getValue().getName());
} else {
i++;
}
}
if (i == equipment.keySet().size()) {
QueueProvider.offer("--Empty--");
QueueProvider.getInstance().offer("--Empty--");
}
}
QueueProvider.offer("------------------------------------------------------------");
QueueProvider.getInstance().offer("------------------------------------------------------------");
}

public Storage getStorage() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jadventure/game/entities/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;


/**
* This class deals with Non Player Character (NPC) and all of their properties.
* Any method that changes a NPC or a player interacts with it should
Expand Down
Loading