Package model.users
Class UsersManagerModel
java.lang.Object
model.users.UsersManagerModel
Manages user profiles in the game, including creating, selecting, saving, and loading users.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcreateUser(String name, int profilePictureIndex) Creates a new user with the specified name and profile picture index.booleandoesUserAlreadyExist(String name) Checks if a user with the specified name already exists.Returns the current user.static UsersManagerModelReturns the singleton instance of the UsersManagerModel.getUsers()Returns a list of all users, sorted by last selected time in descending order.voidLoads user profiles from disk.voidSaves all user profiles to disk.voidselectProfile(String name) Selects the user profile with the specified name.voidsetCurrentUser(User currentUser) Sets the current user.voidupdateCurrentUserInfo(boolean victory) Updates the current user's information based on the game result.
-
Method Details
-
getInstance
Returns the singleton instance of the UsersManagerModel.- Returns:
- the singleton instance
-
createUser
Creates a new user with the specified name and profile picture index.Saves the new user to disk and selects the profile.
If a user with the same name already exists, the new user is not created.
When created the user is selected as the current user.
- Parameters:
name- the name of the new userprofilePictureIndex- the index of the profile picture for the new user
-
selectProfile
Selects the user profile with the specified name. Updates the last selected time and saves the users to disk.- Parameters:
name- the name of the user to select
-
saveUsers
public void saveUsers()Saves all user profiles to disk. -
loadUsers
public void loadUsers()Loads user profiles from disk. If no users are found, creates a default user. -
updateCurrentUserInfo
public void updateCurrentUserInfo(boolean victory) Updates the current user's information based on the game result. Increases the number of games played and increases the number of wins if the player won.- Parameters:
victory- true if the player won the game, false otherwise
-
setCurrentUser
Sets the current user.- Parameters:
currentUser- the user to set as the current user
-
getUsers
Returns a list of all users, sorted by last selected time in descending order.- Returns:
- the list of users
-
getCurrentUser
Returns the current user.- Returns:
- the current user
-
doesUserAlreadyExist
Checks if a user with the specified name already exists.- Parameters:
name- the name to check- Returns:
- true if the user already exists, false otherwise
-