Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #141 from Programmer245/Development-GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-cmyk authored Jun 14, 2024
2 parents f2a95dd + 2027461 commit e711226
Show file tree
Hide file tree
Showing 280 changed files with 1,797 additions and 1,559 deletions.
10 changes: 9 additions & 1 deletion src/main/java/it/polimi/ingsw/am32/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import it.polimi.ingsw.am32.client.View;
import it.polimi.ingsw.am32.client.view.gui.GraphicalUI;
import it.polimi.ingsw.am32.client.view.tui.TextUI;
import it.polimi.ingsw.am32.utilities.Log4J2ConfiguratorWrapper;
import org.apache.logging.log4j.Level;

import java.io.PrintStream;
import java.util.InputMismatchException;
Expand All @@ -11,7 +13,7 @@
/**
* The main class on the client side of the application.
* Prompts the user to choose whether to play the game in GUI or TUI mode.
* After the user has chosen, calls the appropriate view object.
* After the user has chosen, call the appropriate view object.
*
* @author Jie
*/
Expand All @@ -25,7 +27,13 @@ public class Client {
*/
private static final PrintStream out= new PrintStream(System.out);

/**
* The main method displays a welcome message and calls the chooseUI method to prompt the user to choose a UI type.
* @param args Command line arguments
*/
public static void main(String[] args){
// Configure log4j2 logger to log only warnings and above
Log4J2ConfiguratorWrapper.setLogLevelAndConfigure(Level.WARN);
out.println("Welcome to Codex Naturalis");
chooseUI();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/it/polimi/ingsw/am32/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import it.polimi.ingsw.am32.network.ClientAcceptor.SKClientAcceptor;
import it.polimi.ingsw.am32.network.ServerNode.RMIServerNode;
import it.polimi.ingsw.am32.network.ServerNode.SKServerNode;
import it.polimi.ingsw.am32.utilities.Log4J2ConfiguratorWrapper;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -58,6 +60,8 @@ public class Server {
* @param args usual startup arguments
*/
public static void main(String[] args){
// Configure log4j2 logger to log only info and above
Log4J2ConfiguratorWrapper.setLogLevelAndConfigure(Level.INFO);
logger.info("The server is now starting");
new Server(args).start();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/it/polimi/ingsw/am32/chat/ChatMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public String getMessageContent() {
return messageContent;
}

/**
* Convert the message to an Array of 4 Strings representing the message.
* @return An Array of 4 Strings representing the message
*/
public String[] toArray() {
return new String[]{senderNickname, recipientNickname, Boolean.toString(multicastFlag), messageContent};
}

@Override
public String toString() {
return "ChatMessage{" +
Expand Down
97 changes: 97 additions & 0 deletions src/main/java/it/polimi/ingsw/am32/client/ChatMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package it.polimi.ingsw.am32.client;

import it.polimi.ingsw.am32.client.exceptions.MalformedMessageException;

import java.util.Objects;

/**
* This class represents a chat message in the system.
* It contains the sender's nickname, the recipient's nickname, a flag indicating if the message is multicast,
* and the content of the message.
*
* @author Lorenzo
* @author Anto
*/
@SuppressWarnings("ClassCanBeRecord")
public class ChatMessage {
private final String senderNickname;
private final String recipientNickname;
private final boolean multicastFlag;
private final String messageContent;

/**
* Constructs a new ChatMessage with the given parameters.
*
* @param senderNickname The nickname of the sender of the message
* @param recipientNickname The nickname of the recipient of the message
* @param multicastFlag A flag indicating if the message is multicast or not
* @param messageContent The content of the message
*/
public ChatMessage(String senderNickname, String recipientNickname, boolean multicastFlag, String messageContent) {
this.senderNickname = senderNickname;
// Sender nickname can be null if the message is sent by the system but cannot be empty
if (Objects.equals(senderNickname, "")) {
throw new MalformedMessageException("Sender nickname cannot be empty");
}
this.recipientNickname = recipientNickname;
this.multicastFlag = multicastFlag;
// Recipient nickname can be null if the message is multicast but cannot be empty
if (Objects.equals(recipientNickname, "")) {
throw new MalformedMessageException("Recipient nickname cannot be empty");
}
if (recipientNickname == null && !multicastFlag) {
throw new MalformedMessageException("Recipient nickname cannot be null if the message is not multicast");
}
this.messageContent = messageContent;
// Message content cannot be null or empty
if (messageContent == null || messageContent.isEmpty()) {
throw new MalformedMessageException("Message content cannot be empty or null");
}
}

/**
* Returns the sender's nickname.
*
* @return The sender's nickname
*/
public String getSenderNickname() {
return senderNickname;
}

/**
* Returns the recipient's nickname.
*
* @return The recipient's nickname
*/
public String getRecipientNickname() {
return recipientNickname;
}

/**
* Returns the multicast flag.
*
* @return The multicast flag
*/
public boolean isMulticastFlag() {
return multicastFlag;
}

/**
* Returns the content of the message.
*
* @return The content of the message
*/
public String getMessageContent() {
return messageContent;
}

@Override
public String toString() {
return "ChatMessage{" +
"senderNickname='" + senderNickname + '\'' +
", recipientNickname='" + recipientNickname + '\'' +
", multicastFlag=" + multicastFlag +
", messageContent='" + messageContent + '\'' +
'}';
}
}
57 changes: 53 additions & 4 deletions src/main/java/it/polimi/ingsw/am32/client/PlayerPub.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,74 @@
* class contains all the information that the player can request to know about the other players.
*/
public class PlayerPub {
/**
* The colour of the player.
*/
private String colour;
/**
* The points of the player.
*/
private int points;
/**
* The field of the player that contains the information of the cards placed on the field.
*/
private final ArrayList<CardPlacedView> field;
/**
* The resources of the player in the field with order: PLANT, FUNGI, ANIMAL, INSECT, QUILL, INKWELL, MANUSCRIPT.
*/
private int[]resources;
/**
* The boolean value that indicates if the player is online or offline.
*/
private boolean isOnline;

/**
* The constructor of the class that initializes the player's public information with the given parameters.
* @param colour The colour of the player.
* @param points The points of the player.
* @param field The field of the player that contains the information of the cards placed on the field.
* @param resources The resources of the player in the field.
* @param isOnline The boolean value that indicates if the player is online or offline.
*/
public PlayerPub( String colour, int points,ArrayList<CardPlacedView> field,int[]resources,boolean isOnline){
this.colour = colour;
this.points = points;
this.field = field;
this.resources = resources;
this.isOnline = isOnline;
}
public String getColour() {

/**
* The getter method for the colour of the player.
* @return The colour of the player.
*/
public String getColour() {
return colour;
}
public int getPoints() {

/**
* The getter method for the points of the player.
* @return The points of the player.
*/
public int getPoints() {
return points;
}
public ArrayList<CardPlacedView> getField() {

/**
* The getter method for the field of the player.
* @return The field of the player.
*/
public ArrayList<CardPlacedView> getField() {
return field;
}

/**
* The getter method for the resources of the player.
* @return The array of integers that stores the resources of the player in the field.
*/
public int[] getResources(){
return resources;
}

/**
* update the resources of the player with the new resources received from the message.
* @param resources the new version of the resources.
Expand All @@ -56,9 +95,19 @@ public void updatePoints(int points){
public void addToField(CardPlacedView card){
this.field.add(card);
}

/**
* The setter method for the colour of the player to update the colour of the player.
* @param colour the new colour of the player.
*/
public void updateColour(String colour){
this.colour = colour;
}

/**
* The setter method for the boolean value that indicates if the player is online or offline.
* @param isOnline the current status of the player.
*/
public void updateOnline(boolean isOnline){
this.isOnline = isOnline;
}
Expand Down
Loading

0 comments on commit e711226

Please sign in to comment.