diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Client.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..17d824ffa5bb52d95c6bf663cd6b95b9351e2cfd --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Client.java @@ -0,0 +1,41 @@ +package com.galaxytrucker.galaxytruckerreloaded.Controller.Actions; + +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; + +import java.net.Socket; + +public class Client { + + private Socket socket; + + private ClientControllerCommunicator clientControllerCommunicator; + + public String sendAndReceive(){ + // View clicks something + // Controller issues a request + // Client ships request to server + // receive response + // give response to controller + // update views + // return server response as string + return null; + } + + /** Constructor */ + public Client(){ + clientControllerCommunicator = new ClientControllerCommunicator(); + // Connect to server + try { + // Send login request + // receive true/false + // send ship request + //clientControllerCommunicator.setClientShip(); + } + catch (Exception e){ + + } + while (true){ + sendAndReceive(); + } + } +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/ClientControllerCommunicator.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/ClientControllerCommunicator.java new file mode 100644 index 0000000000000000000000000000000000000000..9952e0ba58192434496a079353fda982187cf3b3 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/ClientControllerCommunicator.java @@ -0,0 +1,25 @@ +package com.galaxytrucker.galaxytruckerreloaded.Controller.Actions; + +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import lombok.Setter; + +@Setter +public class ClientControllerCommunicator { + + /** Client ship */ + private Ship clientShip; + + /** Issue a new request and receive a response + * @param request - the request + * @return the server's response */ + public String sendRequest(String request){ + return null; + } + + /** Issue login request + * @param username - the username + * @return true if the user already exists else create a enw spaceship */ + public boolean login(String username){ + return false; + } +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Controller.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Controller.java new file mode 100644 index 0000000000000000000000000000000000000000..01005dcee17a7cd38ad9ac13580a9a55aac31688 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Controller/Actions/Controller.java @@ -0,0 +1,9 @@ +package com.galaxytrucker.galaxytruckerreloaded.Controller.Actions; + +public abstract class Controller { + + /** ClientControllerCommunicator */ + private ClientControllerCommunicator clientControllerCommunicator; + + // Extend me +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Server.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Server.java index f4b8703dbdba0e1128855d3f445884ffda5b0e59..6fc08e4b2af9df28739ba517dfd04b93bdd121ba 100644 --- a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Server.java +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Server.java @@ -1,10 +1,7 @@ package com.galaxytrucker.galaxytruckerreloaded.Server; -import com.galaxytrucker.galaxytruckerreloaded.Server.Database.Database; -import com.galaxytrucker.galaxytruckerreloaded.Server.Services.CrewService; +import com.j256.ormlite.support.ConnectionSource; -import java.io.InputStream; -import java.io.OutputStream; import java.net.Socket; /** @@ -12,52 +9,32 @@ import java.net.Socket; */ public class Server { - /** - * The database - */ - private Database database; - - /** - * Start the server - */ - public static void main(String[] args) { - Database database = new Database(); - database.setup(); - } + /** Server service communicator */ + private ServerServiceCommunicator serverServiceCommunicator; - /** - * Client handler handles clients connected - */ - public void client_handler(Socket socket) { - } + /** Main method */ + public static void main(String[] args){} - /** - * Send some data - * - * @param stream - input stream of data to send - */ - public void sendPackets(InputStream stream) { - } + /** Client handler + * @param socket - the client's socket */ + private void clientHandler(Socket socket){ - /** - * Receive some data - * - * @return outputstream of received data - */ - public OutputStream receivePackets() { - return null; } - /** - * Validate packets - */ - public void validatePackets() { + /** Start serverServiceCommunicator + * @param source - the database connection source */ + private void startServerServiceCommunicator(ConnectionSource source){ + } - /** - * Initialize database - */ - private void initializeDatabase() { + /** Receive some data from the client and return a response + * @param socket - the client socket */ + private void receiveAndSendData(Socket socket){ + } + /** Initialize database + * @return the database connection source */ + private ConnectionSource initializeDatabase(){ + return null; } } diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/ServerServiceCommunicator.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/ServerServiceCommunicator.java new file mode 100644 index 0000000000000000000000000000000000000000..b6c0cdf2c4f588894162243b2f5cdc3955615b07 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/ServerServiceCommunicator.java @@ -0,0 +1,37 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server; + +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import com.j256.ormlite.support.ConnectionSource; +import lombok.AccessLevel; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +public class ServerServiceCommunicator { + + /** Database connection source */ + @NonNull + private ConnectionSource databaseConnectionSource; + + /** Take a request from the client side, pass it through the services + * and return a response + * @return the server's response to the client's request */ + public String getResponse(String request){ + return null; + } + + /** Send the client his ship + * @param username - the client's username + * @return the client's ship */ + public Ship getClientShip(String username){ + return null; + } + + /** Login + * @param username - the user that wants to login + * @return if the client is allowed to login */ + public String login(String username){ + return null; + } + +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java new file mode 100644 index 0000000000000000000000000000000000000000..ac8e8d8693acb533f5bdef5ba9aa3b0fbf1257ee --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/BattleService.java @@ -0,0 +1,57 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Services; + +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; +import lombok.*; + +@Getter +@Setter +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +public class BattleService { + + /** List of ships participating in the fight */ + @NonNull + private List<Ship> participants; + + /** The ship which's round it is */ + private Ship currentRound; + + /** Change the ship which's round it is */ + public void nextRound(){} + + /** Validate user input by checking if it's his round to play + * @param s - the ship which wants to play + * @return true if it is it's round else false */ + private boolean validMove(Ship s){ + return false; + } + + /** Make one ship attack another's section + * @param attacker - the attacking ship + * @param opponent - the opponent's ship + * @param weapon - the weapon attacking */ + private void attack(Ship attacker, Ship opponent, Weapon weapon){} + + /** Heal a ship + * @param ship - the ship to heal + * @param healingWeapon - the healing weapon */ + private void heal(Ship ship,Weapon healingWeapon){} + + /** Flee a fight, reward the winner + * @param coward - the ship that wants to flee + * @param opponent - the opponent that wins the fight */ + private void fleeFight(Ship coward, Ship opponent){} + + /** Give winner reward and end the fight (or the game) + * @param loser - the ship that lost + * @param victor - the ship that won */ + private void endFight(Ship loser, Ship victor){} + + /** Receive data from server and turn into valid battle move + * @param s - the string to turn to battle moves + * @return the outcome of the battle moves as a string command */ + public String applyBattleMoves(String s){ + return null; + } +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java new file mode 100644 index 0000000000000000000000000000000000000000..bcce1d13455895535c7de92e42cc97922f9ce758 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/PlanetEventService.java @@ -0,0 +1,50 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Services; + +import com.badlogic.gdx.scenes.scene2d.ui.List; +import com.galaxytrucker.galaxytruckerreloaded.Model.Map.PlanetEvent; +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import com.galaxytrucker.galaxytruckerreloaded.Model.Weapons.Weapon; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.ShipDAO; +import lombok.*; + +@Getter +@Setter +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +public class PlanetEventService { + + /** Type of planet event currently happening */ + @NonNull + private Enum<PlanetEvent> currentEvent; + + /** Ship DAO */ + @NonNull + private ShipDAO shipDAO; + + /** Round counter (meteorShower/Nebula) */ + private int roundCounter = 0; + + /** Give the player some coins + * @param s - the ship to give coins to + * @param amount - amount of coins to add */ + public void giveCoins(Ship s,int amount){} + + /** Take coins away from player + * @param s - the ship to remove coins from + * @param amount - the amount of coins to remove */ + public void removeCoins(Ship s,int amount){} + + /** Give the player a weapon as loot + * @param s - the ship to give the reward to + * @param weapons - list of possible drops */ + public void giveWeapon(Ship s, List<Weapon> weapons){} + + /** Trader shop + * @return a list of all available stock */ + public List<Weapon> getTraderStock(){ + return null; + } + + /** MeteorShower damage + * @param s - the player in the meteorShower */ + private void meteorShower(Ship s){} +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java new file mode 100644 index 0000000000000000000000000000000000000000..f0c148ed21e388ce71ed3b60f0b3bca4ee2915bd --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/RewardService.java @@ -0,0 +1,4 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Services; + +public class RewardService { +} diff --git a/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TravelService.java b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TravelService.java new file mode 100644 index 0000000000000000000000000000000000000000..e53283963561bbb5011888086ef32cbecfb178e1 --- /dev/null +++ b/core/src/com/galaxytrucker/galaxytruckerreloaded/Server/Services/TravelService.java @@ -0,0 +1,29 @@ +package com.galaxytrucker.galaxytruckerreloaded.Server.Services; + +import com.galaxytrucker.galaxytruckerreloaded.Model.Map.Planet; +import com.galaxytrucker.galaxytruckerreloaded.Model.Ship; +import com.galaxytrucker.galaxytruckerreloaded.Server.Persistence.ShipDAO; +import lombok.*; + +/** Used to move user from one star to another */ +@Getter +@Setter +@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +public class TravelService { + + /** ShipDAO for database access */ + @NonNull + private ShipDAO shipDAO; + + /** Validate the travel request + * @param s - the ship that wisches to travel + * @return true if the travel request is valid */ + public boolean validateJump(Ship s){ + return false; + } + + /** Jump ship from one star to another + * @param s - the ship to jump + * @param dest - the destination star */ + public void jump(Ship s, Planet dest){} +}