Package model.users

Class UsersManagerModel

java.lang.Object
model.users.UsersManagerModel

public class UsersManagerModel extends Object
Manages user profiles in the game, including creating, selecting, saving, and loading users.
  • Method Details

    • getInstance

      public static UsersManagerModel getInstance()
      Returns the singleton instance of the UsersManagerModel.
      Returns:
      the singleton instance
    • createUser

      public void createUser(String name, int profilePictureIndex)
      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 user
      profilePictureIndex - the index of the profile picture for the new user
    • selectProfile

      public void selectProfile(String name)
      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

      public void setCurrentUser(User currentUser)
      Sets the current user.
      Parameters:
      currentUser - the user to set as the current user
    • getUsers

      public ArrayList<User> getUsers()
      Returns a list of all users, sorted by last selected time in descending order.
      Returns:
      the list of users
    • getCurrentUser

      public User getCurrentUser()
      Returns the current user.
      Returns:
      the current user
    • doesUserAlreadyExist

      public boolean doesUserAlreadyExist(String name)
      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