Package model.users
Class User
java.lang.Object
model.users.User
- All Implemented Interfaces:
Serializable
Represents a user in the game. This class contains all the information about the user and provides methods to access and save this information to disk using the Serializable interface.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the best score of the user.longReturns the last selected time of the user.getName()Returns the name of the user.intReturns the number of games played by the user.intReturns the profile picture index of the user.intReturns the number of games won by the user.inthashCode()Returns the hash code of the user, based on the user's name (username is unique to each user).voidIncreases the number of games played by the user by one.voidIncreases the number of games won by the user by one.static UserReads the user data from a file and returns a User object.voidSaves the user data to a file.voidsetScore(int score) Sets the score of the user.voidUpdates the last selected time of the user to the current system time.
-
Constructor Details
-
User
Constructs a User with the specified name and profile picture index.- Parameters:
name- the name of the userprofilePictureIndex- the index of the user's profile picture
-
-
Method Details
-
save
Saves the user data to a file.- Parameters:
fileName- the name of the file to save the user data to
-
reed
Reads the user data from a file and returns a User object.- Parameters:
fileName- the name of the file to read the user data from- Returns:
- the User object read from the file, or null if an error occurs
-
hashCode
public int hashCode()Returns the hash code of the user, based on the user's name (username is unique to each user). -
updateLastSelectedTime
public void updateLastSelectedTime()Updates the last selected time of the user to the current system time. -
setScore
public void setScore(int score) Sets the score of the user. Updates the score if the new score is higher than the best score.- Parameters:
score- the new score of the user
-
increaseGames
public void increaseGames()Increases the number of games played by the user by one. -
increaseWins
public void increaseWins()Increases the number of games won by the user by one. -
getName
Returns the name of the user.- Returns:
- the name of the user
-
getProfilePictureIndex
public int getProfilePictureIndex()Returns the profile picture index of the user.- Returns:
- the profile picture index of the user
-
getBestScore
public int getBestScore()Returns the best score of the user.- Returns:
- the best score of the user
-
getPlayedGames
public int getPlayedGames()Returns the number of games played by the user.- Returns:
- the number of games played by the user
-
getWonGames
public int getWonGames()Returns the number of games won by the user.- Returns:
- the number of games won by the user
-
getLastSelectedTime
public long getLastSelectedTime()Returns the last selected time of the user.- Returns:
- the last selected time of the user
-