This commit is contained in:
Joshua Perry 2023-02-01 20:37:58 +00:00
parent 59bb95c941
commit 86d524417a
10 changed files with 3 additions and 605 deletions

View File

@ -1,126 +0,0 @@
package com.r0r5chach;
import java.text.DecimalFormat;
/**
* Class that defines the various attributes and methods associated with a Valorant Player
* @author r0r5chach
*/
public abstract class Competitor {
/**
* The format to use when converting decimal numbers to strings
*/
protected static final DecimalFormat df = new DecimalFormat("0.00");
/**
* The number of the player in the competition
*/
protected int playerNumber;
/**
* The name of the player in the competition
*/
protected Name playerName;
/**
* The level the player plays at in the competition
* These are derived from the first 4 ranks of the normal game
*/
protected Rank playerLevel;
/**
* The scores the player has received
*/
protected int[] scores;
/**
* Constructs an object with attributes matching the parameters passed
* @param playerNumber the number of the player
* @param playerName the name of the player
* @param playerLevel the level of the player
*/
public Competitor(int playerNumber, Name playerName, Rank playerLevel, int[] scores) {
this.playerNumber = playerNumber;
this.playerName = playerName;
this.playerLevel = playerLevel;
this.scores = scores;
}
/**
* Set the player's number to that of the parameter
* @param playerNumber the new number of the player
*/
public void setPlayerNumber(int playerNumber) {
this.playerNumber = playerNumber;
}
/**
* Set the player's name to that of the parameter
* @param playerName the new name of the player
*/
public void setPlayerName(Name playerName) {
this.playerName = playerName;
}
/**
* Set the player's level to that of the parameter
* @param playerLevel the new level of the player
*/
public void setPlayerLevel(Rank playerLevel) {
this.playerLevel = playerLevel;
}
/**
* Set the player's scores
* @param scores the new scores for the player
*/
public void setScores(int[] scores) {
this.scores = scores;
}
/**
* Get the player's number
* @return the player's number
*/
public int getPlayerNumber() {
return this.playerNumber;
}
/**
* Get the player's name
* @return the player's name
*/
public Name getPlayerName() {
return this.playerName;
}
/**
* Get the player's level
* @return the player's level
*/
public Rank getPlayerLevel() {
return this.playerLevel;
}
/**
* Get the player's scores
* @return an array containing the scores
*/
public int[] getScores() {
return this.scores;
}
/**
* Calculates and then returns the overall score of the player.
* The score is calculated by taking the natural log of each score and then dividing the sum by 1.93
* @return an aggregate of the individual scores the player has achieved
*/
public double getOverallScore() {
double output = 0;
for (int score: getScores()) {
if (Math.log(score) != Double.NEGATIVE_INFINITY) {
output += Math.log(score); //get the sum of the natural log of the scores
}
}
output /= 1.93; //divide the sum by 1.93
return Double.parseDouble(df.format(output)); //df.format() allows the scores to be formatted to 2 decimal places
}
/**
* Get all the attributes of the player
* @return all attributes of the player in a formatted string
*/
public abstract String getFullDetails();
/**
* Get the important attributes of the player
* @return a formatted string containing the playerNumber, playerName, and overall score
*/
public String getShortDetails() {
return "CN " + getPlayerNumber() + " (" + getPlayerName().getInitials() + ") has overall score " + getOverallScore();
}
}

View File

@ -1,95 +0,0 @@
package com.r0r5chach;
import java.util.Arrays;
import com.r0r5chach.r6.R6Attacker;
import com.r0r5chach.r6.R6Defender;
import com.r0r5chach.valorant.ValorantAgent;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
public class CompetitorRow {
private SimpleIntegerProperty playerNumber;
private SimpleStringProperty playerName;
private SimpleObjectProperty<Rank> playerLevel;
private SimpleStringProperty scores;
private SimpleStringProperty favoriteAgent;
private SimpleStringProperty favoriteAttacker;
private SimpleStringProperty favoriteDefender;
public CompetitorRow(int playerNumber, Name playerName, Rank playerLevel, int[] scores) {
this.playerNumber = new SimpleIntegerProperty(playerNumber);
this.playerName = new SimpleStringProperty(playerName.getFullName());
this.playerLevel = new SimpleObjectProperty<Rank>(playerLevel);
this.scores = new SimpleStringProperty(Arrays.toString(scores).replace("[", "").replace("]", ""));
this.favoriteAgent = new SimpleStringProperty("N/A");
this.favoriteAttacker = new SimpleStringProperty("N/A");
this.favoriteDefender = new SimpleStringProperty("N/A");
}
public CompetitorRow(int playerNumber, Name playerName, Rank playerLevel, int[] scores, ValorantAgent favoriteAgent) {
this.playerNumber = new SimpleIntegerProperty(playerNumber);
this.playerName = new SimpleStringProperty(playerName.getFullName());
this.scores = new SimpleStringProperty(Arrays.toString(scores).replace("[", "").replace("]", ""));
this.playerLevel = new SimpleObjectProperty<Rank>(playerLevel);
this.favoriteAgent = new SimpleStringProperty(favoriteAgent.getAgent());
this.favoriteAttacker = new SimpleStringProperty("N/A");
this.favoriteDefender = new SimpleStringProperty("N/A");
}
public CompetitorRow(int playerNumber, Name playerName, Rank playerLevel, int[] scores, R6Attacker favoriteAttacker, R6Defender favoriteDefender) {
this.playerName = new SimpleStringProperty(playerName.getFullName());
this.playerNumber = new SimpleIntegerProperty(playerNumber);
this.scores = new SimpleStringProperty(Arrays.toString(scores).replace("[", "").replace("]", ""));
this.playerLevel = new SimpleObjectProperty<Rank>(playerLevel);
this.favoriteAgent = new SimpleStringProperty("N/A");
this.favoriteAttacker = new SimpleStringProperty(favoriteAttacker.getAttacker());
this.favoriteDefender = new SimpleStringProperty(favoriteDefender.getDefender());
}
public void setPlayerNumber(int newValue) {
this.playerNumber.set(newValue);
}
public void setPlayerName(String newValue) {
this.playerName.set(newValue);
}
public void setPlayerLevel(Rank newValue) {
this.playerLevel.set(newValue);
}
public void setScores(String newValue) {
this.scores.set(newValue);
}
public void setFavoriteAgent(String newValue) {
this.favoriteAgent.set(newValue);
}
public void setFavoriteAttacker(String newValue) {
this.favoriteAttacker.set(newValue);
}
public void setFavoriteDefender(String newValue) {
this.favoriteDefender.set(newValue);
}
public int getPlayerNumber() {
return this.playerNumber.get();
}
public String getPlayerName() {
return this.playerName.get();
}
public Rank getPlayerLevel() {
return this.playerLevel.get();
}
public String getScores() {
return this.scores.get();
}
public String getFavoriteAgent() {
return this.favoriteAgent.get();
}
public String getFavoriteAttacker() {
return this.favoriteAttacker.get();
}
public String getFavoriteDefender() {
return this.favoriteDefender.get();
}
}

View File

@ -1,131 +0,0 @@
package com.r0r5chach;
/**
* Class that defines a name and it's parts
* @author John.Kanyaru@northampton.ac.uk
*/
public class Name {
/**
* The first name of the stored name
*/
private String firstName;
/**
* The middle name of the stored name
*/
private String middleName;
/**
* The last name of the stored name
*/
private String lastName;
/**
* Construct a name that does not contain a middle name
* @param fName the first name of the name to be stored
* @param lName the last name of the name to be stored
*/
public Name(String fName, String lName) {
firstName = fName;
middleName = "";
lastName = lName;
}
/**
* Construct a name that does have a middle name
* @param fName the first name of the name to be stored
* @param mName the middle name of the name to be stored
* @param lName the last name of the name to be stored
*/
public Name(String fName, String mName, String lName) {
firstName = fName;
middleName = mName;
lastName = lName;
}
/**
* Construct a name from a single string
* @param fullName the first, middle, and last names of the name to be stored separated by whitespace
*/
public Name (String fullName) {
int spacePos1 = fullName.indexOf(' ');
firstName = fullName.substring(0, spacePos1);
int spacePos2 = fullName.lastIndexOf(' ');
if (spacePos1 == spacePos2)
middleName = "";
else
middleName = fullName.substring(spacePos1+1, spacePos2);
lastName = fullName.substring(spacePos2 + 1);
}
/**
* Get the first name of the stored name
* @return the first name of the stored name
*/
public String getFirstName() {return firstName; }
/**
* Get the middle name of the stored name
* @return the middle name of the stored name
*/
public String getMiddleName() { return middleName; }
/**
* Get the last name of the stored name
* @return the last name of the stored name
*/
public String getLastName() {return lastName; }
/**
* Set the stored name's first name to that of the parameter
* @param fn the new first name
*/
public void setFirstName(String fn) {
firstName = fn;
}
/**
* Set the stored name's middle name to that of the parameter
* @param mn the new middle name
*/
public void setMiddleName(String mn) {
middleName = mn;
}
/**
* Set the stored name's last name to that of the parameter
* @param ln the new last name
*/
public void setLastName(String ln) {
lastName = ln;
}
/**
* Get the first and last name of the stored name
* @return a formatted string containing both the first and last names
*/
public String getFirstAndLastName() {
return firstName + " " + lastName;
}
/**
* Get the last and first names of the stored name
* @return a formatted string contains both the first and last names in reverse order
*/
public String getLastCommaFirst() {
return lastName + ", "+ firstName;
}
/**
* Get the full stored name
* @return a string containing the first, middle, and last names
*/
public String getFullName() {
String result = firstName + " ";
if (!middleName.equals("")) {
result += middleName + " ";
}
result += lastName;
return result;
}
/**
* Get the initials of the stored name
* @return a string containing the initials
* @author r0r5chach
*/
public String getInitials() {
String result = firstName.substring(0,1);
if (!middleName.equals("")) {
result += middleName.substring(0,1);
}
result += lastName.substring(0,1);
return result;
}
}

View File

@ -1,33 +0,0 @@
package com.r0r5chach;
import java.util.Locale;
/**
* All levels a ValorantPlayer can be
* @author r0r5chach
*/
public enum Rank {
/**
* First Level
*/
BRONZE,
/**
* Second Level
*/
SILVER,
/**
* Third Level
*/
GOLD,
/**
* Four Level
*/
PLATINUM;
/**
* Get the name of a level
* @return a formatted string containing the level name
*/
public String getRank() {
return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalizes the first letter and makes sure the other letters are lowercase
}
}

View File

@ -1,43 +0,0 @@
package com.r0r5chach.r6;
import java.util.Locale;
public enum R6Attacker {
GRIM,
SENS,
OSA,
FLORES,
ZERO,
ACE,
IANA,
KALI,
AMARU,
NOKK,
GRIDLOCK,
NOMAD,
MAVERICK,
LION,
FINKA,
DOKKAEBI,
ZOFIA,
YING,
JACKAL,
HIBANA,
CAPITAO,
BLACKBEARD,
BUCK,
SLEDGE,
THATCHER,
ASH,
THERMITE,
MONTAGNE,
TWITCH,
BLITZ,
IQ,
FUZE,
GLAZ;
public String getAttacker() {
return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalizes the first letter and makes sure the other letters are lowercase
}
}

View File

@ -1,43 +0,0 @@
package com.r0r5chach.r6;
import java.util.Locale;
public enum R6Defender {
SOLIS,
AZAMI,
THORN,
THUNDERBIRD,
ARUNI,
MELUSI,
ORYX,
WAMAI,
GOYO,
WARDEN,
MOZZIE,
KAID,
CLASH,
MAESTRO,
ALIBI,
VIGIL,
ELA,
LESION,
MIRA,
ECHO,
CAVEIRA,
VALKYRIE,
FROST,
MUTE,
SMOKE,
CASTLE,
PULSE,
DOC,
ROOK,
JAGER,
BANDIT,
TACHANKA,
KAPKAN;
public String getDefender() {
return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalizes the first letter and makes sure the other letters are lowercase
}
}

View File

@ -1,44 +0,0 @@
package com.r0r5chach.r6;
import java.util.Arrays;
import com.r0r5chach.Competitor;
import com.r0r5chach.Name;
import com.r0r5chach.Rank;
public class R6Player extends Competitor{
private R6Attacker favoriteAttacker;
private R6Defender favoriteDefender;
public R6Player(int playerNumber, Name playerName, Rank playerLevel, R6Attacker favoriteAttacker, R6Defender favoriteDefender, int[] scores) {
super(playerNumber, playerName, playerLevel, scores);
this.favoriteAttacker = favoriteAttacker;
this.favoriteDefender = favoriteDefender;
}
public void setFavoriteAttacker(R6Attacker favoriteAttacker) {
this.favoriteAttacker = favoriteAttacker;
}
public void setFavoriteDefender(R6Defender favoriteDefender) {
this.favoriteDefender = favoriteDefender;
}
public R6Attacker getFavoriteAttacker() {
return this.favoriteAttacker;
}
public R6Defender getFavoriteDefender() {
return this.favoriteDefender;
}
public String getFullDetails() {
return "Player Number: " + getPlayerNumber() +
"\nName: " + getPlayerName().getFullName() +
"\nPlayer Level: " + getPlayerLevel().getRank() +
"\nScores: " + Arrays.toString(getScores()).replace("[","").replace("]", "") + //replace() allows the array to not be surrounded by brackets
"\nOverall Score: " + getOverallScore() +
"\nFavorite Attacker: " + getFavoriteAttacker().getAttacker() +
"\nFavorite Defender: " + getFavoriteDefender().getDefender();
}
}

View File

@ -1,37 +0,0 @@
package com.r0r5chach.valorant;
import java.util.Locale;
/**
* All Characters a ValorantPlayer can play
* @author r0r5chach
*/
public enum ValorantAgent {
BRIMSTONE,
VIPER,
OMEN,
KILLJOY,
CYPHER,
SOVA,
SAGE,
PHOENIX,
JETT,
REYNA,
RAZE,
BREACH,
SKYE,
YORU,
ASTRA,
KAYO,
CHAMBER,
NEON,
FADE,
HARBOR;
/**
* Get the name of the character
* @return a formatted string containing the character name
*/
public String getAgent() {
return this.name().charAt(0) + this.name().substring(1).toLowerCase(Locale.ROOT); //Capitalizes the first letter and makes sure the other letters are lowercase
}
}

View File

@ -1,51 +0,0 @@
package com.r0r5chach.valorant;
import java.util.Arrays;
import com.r0r5chach.Competitor;
import com.r0r5chach.Name;
import com.r0r5chach.Rank;
/**
* Class that defines the various attributes and methods associated with a Valorant Player
* @author r0r5chach
*/
public class ValorantPlayer extends Competitor {
private ValorantAgent favoriteAgent;
/**
* Constructs an object with attributes matching the parameters passed
* @param playerNumber the number of the player
* @param playerName the name of the player
* @param playerLevel the level of the player
* @param favoriteAgent the character the player plays most
*/
public ValorantPlayer(int playerNumber, Name playerName, Rank playerLevel, ValorantAgent favoriteAgent, int[] scores) {
super(playerNumber, playerName, playerLevel, scores);
this.favoriteAgent = favoriteAgent;
}
/**
* Set the player's most played character to that of the parameter
* @param favoriteAgent the new most played character of the player
*/
public void setFavoriteAgent(ValorantAgent favoriteAgent) {
this.favoriteAgent = favoriteAgent;
}
/**
* Get the player's most played character
* @return the player's most played character
*/
public ValorantAgent getFavoriteAgent() {
return this.favoriteAgent;
}
/**
* Get all the attributes of the player
* @return all attributes of the player in a formatted string
*/
public String getFullDetails() {
return "Player Number: " + getPlayerNumber() +
"\nName: " + getPlayerName().getFullName() +
"\nPlayer Level: " + getPlayerLevel().getRank() +
"\nScores: " + Arrays.toString(getScores()).replace("[","").replace("]", "") + //replace() allows the array to not be surrounded by brackets
"\nOverall Score: " + getOverallScore() +
"\nFavorite Agent: " + getFavoriteAgent().getAgent();
}
}

View File

@ -5,6 +5,7 @@ module com.r0r5chach {
opens com.r0r5chach to javafx.fxml; opens com.r0r5chach to javafx.fxml;
exports com.r0r5chach; exports com.r0r5chach;
exports com.r0r5chach.r6; exports com.r0r5chach.competitor;
exports com.r0r5chach.valorant; exports com.r0r5chach.competitor.r6;
exports com.r0r5chach.competitor.valorant;
} }