Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103T-T12-4#75 from JJtan2002/add-role-…
Browse files Browse the repository at this point in the history
…to-game

Add Role field to Game
  • Loading branch information
Kitty-001 authored Oct 15, 2024
2 parents 7d052ff + b9b81c1 commit 92660e8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 24 deletions.
41 changes: 17 additions & 24 deletions src/main/java/seedu/address/model/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,37 @@ public class Game {
public final String gameName;
public final Username username;
public final SkillLevel skillLevel;
public final Role role;


/**
* Constructs a {@code Game} without a username.
* Constructs a {@code Game}.
*
* @param gameName A valid Game name.
* @param username (Optional) A username.
* @param skillLevel (Optional) A skill level.
* @param role (Optional) A role.
*/
public Game(String gameName) {
public Game(String gameName, String username, String skillLevel, String role) {
requireNonNull(gameName);
checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS);
this.gameName = gameName;
this.username = null;
this.skillLevel = null;
this.username = username != null ? new Username(username) : null;
this.skillLevel = skillLevel != null ? new SkillLevel(skillLevel) : null;
this.role = role != null ? new Role(role) : null;
}

// Overloaded constructors for convenience
public Game(String gameName) {
this(gameName, null, null, null);
}

/**
* Constructs a {@code Game} with a username.
*
* @param gameName A valid Game name.
*/
public Game(String gameName, String username) {
requireNonNull(gameName);
checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS);
this.gameName = gameName;
this.username = new Username(username);
this.skillLevel = null;
this(gameName, username, null, null);
}

/**
* Constructs a {@code Game} with a username.
*
* @param gameName A valid Game name.
*/
public Game(String gameName, String username, String skillLevel) {
requireNonNull(gameName);
checkArgument(isValidGameName(gameName), MESSAGE_CONSTRAINTS);
this.gameName = gameName;
this.username = new Username(username);
this.skillLevel = new SkillLevel(skillLevel);
this(gameName, username, skillLevel, null);
}

/**
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/seedu/address/model/game/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package seedu.address.model.game;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Describes the Person's skill level in a Game.
*/
public class Role {

private static final String MESSAGE_CONSTRAINTS =
"Role should not be blank";

/*
* Regex expression matches Strings that contain at least one non-whitespace character.
*/
private static final String VALIDATION_REGEX = "^(?!\\s*$).+";

private final String role;

/**
* Constructs a {@code Role}.
*
* @param role a valid skill level or rank.
*/
public Role(String role) {
requireNonNull(role);
checkArgument(isValidRole(role), MESSAGE_CONSTRAINTS);
this.role = role;
}

/**
* Returns true if a given string is a valid Role.
*/
public static boolean isValidRole(String test) {
return test.matches(VALIDATION_REGEX);
}

/**
* Getter for role field.
*/
public String getRole() {
return role;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof Role)) {
return false;
}

Role otherRole = (Role) other;
return role.equals(otherRole.role);
}

@Override
public int hashCode() {
return role.hashCode();
}

/**
* Format state as text for viewing.
*/
public String toString() {
return role;
}

}

0 comments on commit 92660e8

Please sign in to comment.