forked from IF-LK-2020/wordle
146 lines
2.7 KiB
Java
146 lines
2.7 KiB
Java
import java.time.LocalDate;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
public class User {
|
|
private String connectionID;
|
|
private String username;
|
|
private String password;
|
|
private int timesPlayed;
|
|
private float winPercentage;
|
|
private int currentStreak;
|
|
private int maxStreak;
|
|
private int lastDayWOTDPlayed;
|
|
private int state;
|
|
private int[] wonInTurn;
|
|
private Game game;
|
|
|
|
public User(String pConnectionID) {
|
|
connectionID = pConnectionID;
|
|
game = new Game();
|
|
wonInTurn = new int[6];
|
|
}
|
|
|
|
public Game getGame() {
|
|
return game;
|
|
}
|
|
|
|
public String getConnectionID() {
|
|
return connectionID;
|
|
}
|
|
|
|
public int getCurrentStreak() {
|
|
return currentStreak;
|
|
}
|
|
|
|
public int getLastDayWOTDPlayed() {
|
|
return lastDayWOTDPlayed;
|
|
}
|
|
|
|
public int getMaxStreak() {
|
|
return maxStreak;
|
|
}
|
|
|
|
public int getTimesPlayed() {
|
|
return timesPlayed;
|
|
}
|
|
|
|
public int getState() {
|
|
return state;
|
|
}
|
|
|
|
public float getWinPercentage() {
|
|
return winPercentage;
|
|
}
|
|
|
|
public int getWonInTurnIndex(int index) {
|
|
return wonInTurn[index];
|
|
}
|
|
|
|
public int[] getWonInTurn() {
|
|
return wonInTurn;
|
|
}
|
|
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public void setConnectionID(String connectionID) {
|
|
this.connectionID = connectionID;
|
|
}
|
|
|
|
public void setCurrentStreak(int currentStreak) {
|
|
this.currentStreak = currentStreak;
|
|
if (maxStreak < currentStreak) {
|
|
maxStreak = currentStreak;
|
|
}
|
|
}
|
|
|
|
public void setMaxStreak(int maxStreak) {
|
|
this.maxStreak = maxStreak;
|
|
}
|
|
|
|
private int getTotalWins() {
|
|
int w = 0;
|
|
for (int i = 0; i < wonInTurn.length; i++) {
|
|
w += wonInTurn[i];
|
|
}
|
|
return w;
|
|
}
|
|
|
|
public void updateWinPercentage() {
|
|
winPercentage = (int) (getTotalWins() / timesPlayed) * 100;
|
|
}
|
|
|
|
public void updateLastDayWOTDPlayed() {
|
|
lastDayWOTDPlayed = (int) ChronoUnit.DAYS.between(LocalDate.ofEpochDay(0), LocalDate.now());
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public void setState(int state) {
|
|
this.state = state;
|
|
}
|
|
|
|
public void setTimesPlayed(int timesPlayed) {
|
|
this.timesPlayed = timesPlayed;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public void setWinPercentage(float winPercentage) {
|
|
this.winPercentage = winPercentage;
|
|
}
|
|
|
|
public void setWonInTurnIndex(int content, int index) {
|
|
wonInTurn[index] = content;
|
|
}
|
|
|
|
public void increaseWonInTurnIndex(int index) {
|
|
wonInTurn[index]++;
|
|
}
|
|
|
|
public boolean loggedIn() {
|
|
if (password != null && username != null) {
|
|
return (!password.equals("") && !username.equals(""));
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public String[] getLastGuesses() {
|
|
return game.getGuesses();
|
|
}
|
|
|
|
public void setLastDayWOTDPlayed(int time) {
|
|
lastDayWOTDPlayed = time;
|
|
}
|
|
}
|