Package model.users

Class User

java.lang.Object
model.users.User
All Implemented Interfaces:
Serializable

public class User extends Object implements 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
    Constructor
    Description
    User(String name, int profilePictureIndex)
    Constructs a User with the specified name and profile picture index.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the best score of the user.
    long
    Returns the last selected time of the user.
    Returns the name of the user.
    int
    Returns the number of games played by the user.
    int
    Returns the profile picture index of the user.
    int
    Returns the number of games won by the user.
    int
    Returns the hash code of the user, based on the user's name (username is unique to each user).
    void
    Increases the number of games played by the user by one.
    void
    Increases the number of games won by the user by one.
    static User
    reed(String fileName)
    Reads the user data from a file and returns a User object.
    void
    save(String fileName)
    Saves the user data to a file.
    void
    setScore(int score)
    Sets the score of the user.
    void
    Updates the last selected time of the user to the current system time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • User

      public User(String name, int profilePictureIndex)
      Constructs a User with the specified name and profile picture index.
      Parameters:
      name - the name of the user
      profilePictureIndex - the index of the user's profile picture
  • Method Details

    • save

      public void save(String fileName)
      Saves the user data to a file.
      Parameters:
      fileName - the name of the file to save the user data to
    • reed

      public static User reed(String fileName)
      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).
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of the 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

      public String 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