Skip to content

Commit

Permalink
metric totals
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealEmissions committed Mar 21, 2024
1 parent 0c70007 commit ff619b7
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
23 changes: 23 additions & 0 deletions core/src/uk/ac/york/student/player/PlayerEnergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
import org.jetbrains.annotations.Range;
import uk.ac.york.student.game.GameTime;

/**
* The PlayerEnergy class represents the energy level of a player in the game.
Expand Down Expand Up @@ -34,6 +35,28 @@ public PlayerEnergy() {
* By default, the energy level is set to 1 (full energy).
*/
private @Range(from=0, to=1) float energy = getDefault();
/**
* The total amount of energy accumulated by the player across all days of the game.
* This is a float value that starts at 0 and increases as the player gains more energy.
* This value is incremented when the player sleeps based on what their energy level is at that given time.
*/
private float totalEnergy = 0f;

public float getMaxTotal() {
return GameTime.getDays();
}

public float getTotal() {
return totalEnergy;
}

public void setTotal(float total) {
this.totalEnergy = total;
}

public void increaseTotal(float amount) {
this.totalEnergy += amount;
}
/**
* Returns the default energy level for the player.
* This is a float value of 1, representing full energy.
Expand Down
24 changes: 24 additions & 0 deletions core/src/uk/ac/york/student/player/PlayerHappiness.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
import org.jetbrains.annotations.Range;
import uk.ac.york.student.game.GameTime;

/**
* The PlayerHappiness class implements the PlayerMetric interface.
Expand Down Expand Up @@ -33,6 +34,29 @@ public PlayerHappiness() {
* It is initially set to 1, indicating that the player starts the game being very happy.
*/
private @Range(from=0, to=1) float happiness = getDefault();
/**
* The total amount of happiness accumulated by the player across all days of the game.
* This is a float value that starts at 0 and increases as the player becomes happier.
* This value is incremented when the player sleeps based on what their happiness level is at that given time.
*/
private float totalHappiness = 0f;

public float getMaxTotal() {
return GameTime.getDays();
}

public float getTotal() {
return totalHappiness;
}

public void setTotal(float total) {
this.totalHappiness = total;
}

public void increaseTotal(float amount) {
this.totalHappiness += amount;
}

/**
* This method is used to get the default happiness level for a player.
* The default happiness level is set to 1.0, indicating that a player starts the game at full happiness.
Expand Down
5 changes: 5 additions & 0 deletions core/src/uk/ac/york/student/player/PlayerMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public interface PlayerMetric {
void decrease(float amount);
float getDefault();

void setTotal(float total);
void increaseTotal(float amount);
float getTotal();
float getMaxTotal();

/**
* Dispose resources when they are no longer needed.
* By default, it disposes the skin.
Expand Down
50 changes: 49 additions & 1 deletion core/src/uk/ac/york/student/player/PlayerScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,41 @@
* The score is then converted to a string representation of a degree class.
*/
public interface PlayerScore {
/**
* Calculate a score for the player based on their energy, study level, and happiness.
* The score is calculated using the provided weightings for each parameter.
* The weightings are used to determine the importance of each parameter in the final score.
*
* @param energy The player's energy level.
* @param maxEnergy The maximum possible energy level.
* @param studyLevel The player's study level.
* @param maxStudyLevel The maximum possible study level.
* @param happiness The player's happiness level.
* @param maxHappiness The maximum possible happiness level.
* @return The player's score, calculated based on the provided parameters and weightings.
*/
default float calculateScore(float energy, float maxEnergy, float studyLevel, float maxStudyLevel, float happiness, float maxHappiness) {
float energyWeighting = 1.2f;
float studyWeighting = 2f;
float happinessWeighting = 1f;

float energyScore = (energy / maxEnergy) * energyWeighting;
float studyScore = (studyLevel / maxStudyLevel) * studyWeighting;
float happinessScore = (happiness / maxHappiness) * happinessWeighting;

float totalScore = energyScore + studyScore + happinessScore;
float maxPossibleScore = energyWeighting + studyWeighting + happinessWeighting;

return (totalScore / maxPossibleScore) * 100;
}


/**
* Calculate a score for the player based on their energy, study time, and the game's difficulty level.
* The score is calculated using a specific algorithm that has diminishing returns for the amount of work the player has done.
* The algorithm also allows for a choice of difficulties, with a custom difficulty range.
*
* @deprecated
* @param energy The player's energy level.
* @param maxEnergy The maximum possible energy level.
* @param studyTime The time the player has spent studying.
Expand All @@ -22,6 +52,7 @@ public interface PlayerScore {
* @param maxDifficulty The maximum possible difficulty level.
* @return The player's score, calculated based on the provided parameters.
*/
@Deprecated(forRemoval = true)
default int calculateScore(float energy, float maxEnergy, float studyTime,
float maxStudyTime, int difficulty,
int maxDifficulty) {
Expand All @@ -42,10 +73,26 @@ default int calculateScore(float energy, float maxEnergy, float studyTime,
return (int) Math.round(percentScoreDouble);
}

/**
* Overload of the calculateScore method that only requires energy and study time parameters.
* This method assumes a default difficulty level of 1 for both the game and the maximum possible difficulty.
*
* @deprecated
* @param energy The player's energy level.
* @param maxEnergy The maximum possible energy level.
* @param studyTime The time the player has spent studying.
* @param maxStudyTime The maximum possible study time.
* @return The player's score, calculated based on the provided parameters and the default difficulty level.
*/
@Deprecated(forRemoval = true)
default int calculateScore(float energy, float maxEnergy, float studyTime, float maxStudyTime) {
return calculateScore(energy, maxEnergy, studyTime, maxStudyTime, 1, 1);
}
/**
* Overload of the calculateScore method that accepts integer parameters.
* This method simply converts the integer parameters to floats and calls the other calculateScore method.
*
* @deprecated
* @param energy The player's energy level.
* @param maxEnergy The maximum possible energy level.
* @param studyTime The time the player has spent studying.
Expand All @@ -54,6 +101,7 @@ default int calculateScore(float energy, float maxEnergy, float studyTime,
* @param maxDifficulty The maximum possible difficulty level.
* @return The player's score, calculated based on the provided parameters.
*/
@Deprecated(forRemoval = true)
default int calculateScore(int energy, int maxEnergy, int studyTime,
int maxStudyTime, int difficulty,
int maxDifficulty) {
Expand All @@ -71,7 +119,7 @@ default int calculateScore(int energy, int maxEnergy, int studyTime,
* @return A string representation of a degree class.
*/
@Contract(pure = true)
default @NotNull String convertScoreToString(int score) {
default @NotNull String convertScoreToString(float score) {
if (score >= 70) {
return "First-class Honours";
} else if (score >= 60) {
Expand Down
24 changes: 24 additions & 0 deletions core/src/uk/ac/york/student/player/PlayerStudyLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
import org.jetbrains.annotations.Range;
import uk.ac.york.student.game.GameTime;

/**
* The PlayerStudyLevel class represents the study level of a player in the game.
Expand Down Expand Up @@ -35,6 +36,29 @@ public PlayerStudyLevel() {
*/
private @Range(from=0, to=1) float studyLevel = 0.1f;

/**
* The total amount of study accumulated by the player across all days of the game.
* This is a float value that starts at 0 and increases as the player studies more.
* This value is incremented when the player sleeps based on what their study level is at that given time.
*/
private float totalStudy = 0f;

public float getMaxTotal() {
return GameTime.getDays();
}

public float getTotal() {
return totalStudy;
}

public void setTotal(float total) {
this.totalStudy = total;
}

public void increaseTotal(float amount) {
this.totalStudy += amount;
}

/**
* This method is used to get the default study level for a player.
* The default study level is set to 0.1, indicating that a player starts the game with a study level of 0.1.
Expand Down

0 comments on commit ff619b7

Please sign in to comment.