From 5294d9779dec5b36ccdf1c87b768bddf91179171 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Thu, 26 May 2016 15:28:44 +0200 Subject: Elaborate doc --- src/ch/epfl/xblast/client/Client.java | 47 +++++++++++++------------- src/ch/epfl/xblast/client/Main.java | 2 +- src/ch/epfl/xblast/client/XBlastComponent.java | 24 ++++++------- src/ch/epfl/xblast/server/Main.java | 2 +- src/ch/epfl/xblast/server/Server.java | 44 ++++++++++++------------ 5 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/ch/epfl/xblast/client/Client.java b/src/ch/epfl/xblast/client/Client.java index 8ccea00..24ca727 100644 --- a/src/ch/epfl/xblast/client/Client.java +++ b/src/ch/epfl/xblast/client/Client.java @@ -40,7 +40,7 @@ public class Client { private static class Channel { /** - * Transform a buffer to a list of bytes. + * Transforms a buffer to a list of bytes. * * @param buf given buffer * @return the list of bytes built from the given buffer @@ -55,7 +55,7 @@ public class Client { } /** - * Create the UDP communication Channel. + * Creates the UDP communication Channel. * * @return the UDP communication Channel */ @@ -98,7 +98,7 @@ public class Client { } /** - * Close the Channel. + * Closes the Channel. */ void closeChannel() { try { @@ -109,7 +109,7 @@ public class Client { } /** - * Send an action through the Channel. + * Sends an action through the Channel. * * @param action action to send */ @@ -118,9 +118,9 @@ public class Client { } /** - * Receive a GameState through the Channel. + * Receives a GameState through the Channel. * - * @param block + * @param block wait for an incoming game state before returning * @return the received GameState */ List receiveGameState(boolean block) { @@ -134,7 +134,7 @@ public class Client { } /** - * Send a byte through the Channel. + * Sends a byte through the Channel. * * @param b byte to send */ @@ -143,7 +143,7 @@ public class Client { } /** - * Send the content of a buffer. + * Sends the content of a buffer. * * @param b buffer containing the bytes to send */ @@ -156,9 +156,9 @@ public class Client { } /** - * Receive data from the Channel. + * Receives data from the Channel. * - * @param block + * @param block wait for an incoming byte before returning * @return the received data */ private Optional> receive(boolean block) { @@ -182,7 +182,7 @@ public class Client { private static class GUI { /** - * Build the window. + * Builds the window. * * @param content content of the window * @return the frame @@ -199,7 +199,8 @@ public class Client { } /** - * Attach the keyboard events handler to the component. + * Attaches the keyboard event handler to the component. + * * @param comp component * @param actionConsumer actionConsumer corresponding to the keyboardEventHandler */ @@ -225,7 +226,7 @@ public class Client { } /** - * Build and display the GUI. + * Builds and display the GUI. */ public void display() { buildFrame(this.gameComponent); @@ -233,7 +234,7 @@ public class Client { } /** - * Update the displayed GameState. + * Updates the displayed GameState. * * @param gs new GameState to be displayed * @param p Player ID corresponding to the client @@ -245,7 +246,7 @@ public class Client { } /** - * Deserialize the players' IDs. + * Deserializes the players' IDs. * * @param b a given byte * @return the Player ID corresponding to the given byte @@ -262,7 +263,7 @@ public class Client { } /** - * Deserialize a received GameState. + * Deserializes a received GameState. * * @param b the serialized GameState * @return the deserialized GameState @@ -282,7 +283,7 @@ public class Client { private final GUI gui; /** - * Instatiates a new client. + * Instantiates a new client. * * @param host hostname * @param port port @@ -293,7 +294,7 @@ public class Client { } /** - * Run the whole client. + * Runs the whole client. */ public void run() { this.displayGUI(); @@ -303,7 +304,7 @@ public class Client { } /** - * Display the Graphical User Interface. + * Displays the Graphical User Interface. */ private void displayGUI() { try { @@ -315,7 +316,7 @@ public class Client { } /** - * Launch the game. + * Launches the game. */ private void runGame() { while (true) @@ -323,7 +324,7 @@ public class Client { } /** - * Connect to the server and fetch the new GameState. + * Connects to the server and fetch the new GameState. */ private void establishConnection() { Thread joinThread = new Thread(this::sendJoinRequest); @@ -333,7 +334,7 @@ public class Client { } /** - * Fetch the new GameState. + * Fetches the new GameState. */ private void updateGameState() { List serializedGameState = this.channel.receiveGameState(true); @@ -347,7 +348,7 @@ public class Client { } /** - * Send a "Join" request to the server. + * Sends a "Join" request to the server. */ private void sendJoinRequest() { while (!Thread.currentThread().isInterrupted()) { diff --git a/src/ch/epfl/xblast/client/Main.java b/src/ch/epfl/xblast/client/Main.java index 1a3cc6c..e6f6ced 100644 --- a/src/ch/epfl/xblast/client/Main.java +++ b/src/ch/epfl/xblast/client/Main.java @@ -16,7 +16,7 @@ public final class Main { /** * Start a new client. * - * @param args arguments given to the client (i.e. port & address of the server) + * @param args arguments given to the client (address and port of the server to connect to) */ public static void main(String[] args) { String host = ArgumentChecker.getOrNull(args, 0); diff --git a/src/ch/epfl/xblast/client/XBlastComponent.java b/src/ch/epfl/xblast/client/XBlastComponent.java index 42c7ab9..f90d6ee 100644 --- a/src/ch/epfl/xblast/client/XBlastComponent.java +++ b/src/ch/epfl/xblast/client/XBlastComponent.java @@ -65,7 +65,7 @@ public final class XBlastComponent extends JComponent { } /** - * Build a list containing the positions of the elements of a line. + * Builds a list containing the positions of the elements of a line. * * @param elementDim dimension of the every element of the line * @param len length of the line @@ -79,7 +79,7 @@ public final class XBlastComponent extends JComponent { } /** - * Build the list of the positions of the scores' line elements. + * Builds the list of the positions of the scores' line elements. * * @return the list of the positions of the scores' line elements. */ @@ -91,7 +91,7 @@ public final class XBlastComponent extends JComponent { } /** - * Build the list of the positions of the time "line" elements. + * Builds the list of the positions of the time "line" elements. * * @return the list of the positions of the time "line" elements. */ @@ -103,7 +103,7 @@ public final class XBlastComponent extends JComponent { } /** - * Built the map linking the players' ID to the location of their scores on the grid. + * Builds the map linking the players' ID to the location of their scores on the grid. * * @param vShift vertical position of the scores on the grid * @return map linking the players' ID to the location of their scores on the grid @@ -118,7 +118,7 @@ public final class XBlastComponent extends JComponent { } /** - * Compute the position of a player on the grid. + * Computes the position of a player on the grid. * * @param p given player * @return the player's position on the grid @@ -144,7 +144,7 @@ public final class XBlastComponent extends JComponent { private static final Color TXT_COLOR = Color.WHITE; /** - * Draw a string on the graphic context at the given point. + * Draws a string on the graphic context at the given point. * * @param g the graphic context * @param pos position on the graphic context @@ -157,7 +157,7 @@ public final class XBlastComponent extends JComponent { } /** - * Draw an image on the graphic at the given point. + * Draws an image on the graphic at the given point. * * @param g the graphic context * @param pos position on the graphic context. @@ -168,7 +168,7 @@ public final class XBlastComponent extends JComponent { } /** - * Draw images given their location on the graphic context. + * Draws images given their location on the graphic context. * * @param g the graphic context * @param m map linking images to points on the graphic context @@ -179,7 +179,7 @@ public final class XBlastComponent extends JComponent { } /** - * Draw strings given their location on the graphic context. + * Draws strings given their location on the graphic context. * * @param g the graphic context * @param m map linking strings to their locations @@ -203,7 +203,7 @@ public final class XBlastComponent extends JComponent { } /** - * Sort the players in order to have the current player at first. + * Sorts the players in order to have the current player at first. * * @param players list of the players * @param currentPlayerID player ID of the current player (the player playing on this client) @@ -231,7 +231,7 @@ public final class XBlastComponent extends JComponent { private PlayerID playerID; /** - * Display the given GameState from the point of view of the given playerID. + * Displays the given GameState from the point of view of the given playerID. * * @param gs GameState to be displayed * @param pid playerID related to the view @@ -253,7 +253,7 @@ public final class XBlastComponent extends JComponent { } /** - * Draw the component. + * Draws the component. * * @param g0 the Graphics context */ diff --git a/src/ch/epfl/xblast/server/Main.java b/src/ch/epfl/xblast/server/Main.java index eb29aec..7ae5582 100644 --- a/src/ch/epfl/xblast/server/Main.java +++ b/src/ch/epfl/xblast/server/Main.java @@ -16,7 +16,7 @@ public final class Main { /** * Starts a new server. * - * @param args arguments given to the server + * @param args arguments given to the server (number of clients, listening interface, port) */ public static void main(String[] args) { Integer expectedClients = ArgumentChecker.parseIntOrNull(ArgumentChecker.getOrNull(args, 0)); diff --git a/src/ch/epfl/xblast/server/Server.java b/src/ch/epfl/xblast/server/Server.java index 3f486c6..074b2a7 100644 --- a/src/ch/epfl/xblast/server/Server.java +++ b/src/ch/epfl/xblast/server/Server.java @@ -34,7 +34,7 @@ public class Server { public static final byte OBSERVER = -1; /** - * Print a log message on the console. + * Prints a log message on the console. * * @param message message to be printed */ @@ -48,7 +48,7 @@ public class Server { private static class Channel { /** - * Transform a list of bytes to an array of bytes. + * Transforms a list of bytes to an array of bytes. * * @param l the given list of bytes * @return the array built from the given list @@ -63,7 +63,7 @@ public class Server { } /** - * Create the socket which will be listened. + * Creates the socket which will be listened to. * * @param host hostname * @param port port to be listened @@ -77,7 +77,7 @@ public class Server { } /** - * Open a UDP channel. + * Open an UDP channel. * * @param iface listened socket * @return a UDP channel @@ -119,7 +119,7 @@ public class Server { } /** - * Close the channel. + * Closes the channel. */ void closeChannel() { try { @@ -130,9 +130,9 @@ public class Server { } /** - * Accept the registration of a new client. + * Accepts the registration of a new client. * - * @param registrations + * @param registrations number of expected registrations * @return a list of the clients. */ List acceptRegistrations(int registrations) { @@ -148,7 +148,7 @@ public class Server { } /** - * Collect actions from the players. + * Collects actions from the players. * * @return a list map containing the actions related to each player */ @@ -166,10 +166,10 @@ public class Server { } /** - * Send data through the socket. + * Sends data through the socket. * * @param content data to be send - * @param dst recepient of the data + * @param dst recipient of the data */ void send(List content, SocketAddress dst) { try { @@ -181,9 +181,9 @@ public class Server { } /** - * Receive a Byte from the socket. + * Receives a Byte from the socket. * - * @param block + * @param block wait for an incoming byte before returning * @return an Optional containing the received data */ private Optional> receiveByte(boolean block) { @@ -202,9 +202,9 @@ public class Server { } /** - * Receive a player action from the socket. + * Receives a player action from the socket. * - * @param block + * @param block wait for an incoming action before returning * @return an Optional containing the received player action */ private Optional> receiveAction(boolean block) { @@ -218,7 +218,7 @@ public class Server { } /** - * Accept an action from the socket. + * Accepts an action from the socket. * * @return the accepted action */ @@ -233,7 +233,7 @@ public class Server { } /** - * Accept the registration of a player + * Accepts the registration of a player. * * @return the address of the new player */ @@ -254,7 +254,7 @@ public class Server { private final Channel channel; /** - * Required number of player to start a game (up to 4). + * Required number of player to start a game. */ private final int expectedClients; @@ -277,7 +277,7 @@ public class Server { } /** - * Run the whole server. + * Runs the whole server. */ public void run() { log("Starting the server..."); @@ -287,7 +287,7 @@ public class Server { } /** - * Handle the registration of new clients. + * Handles the registration of new clients. */ private void acceptClientRegistrations() { List clients = this.channel.acceptRegistrations(this.expectedClients); @@ -296,7 +296,7 @@ public class Server { } /** - * Launch the Game. + * Launches the Game. */ private void runGame() { GameState gameState = GameState.DEFAULT_GAME_STATE; @@ -314,7 +314,7 @@ public class Server { } /** - * Update the given GameState to the next tick. + * Updates the given GameState to the next tick. * * @param gs the given GameState * @return the updated GameState @@ -325,7 +325,7 @@ public class Server { } /** - * Send the GameState to every player. + * Sends the GameState to every player. * * @param gs the GameState to be send. */ -- cgit v1.2.3