Virtual Pet Game is an interactive desktop application created in Java using JavaFX. The game allows players to take care of a virtual pet by managing its hunger, health, sleep, and happiness levels. The application also includes features such as inventory management, parental controls to restrict gameplay hours, and a retro aesthetic for an engaging user experience.
To build and run the Virtual Pet Game, ensure you have the following tools installed:
- Java Development Kit (JDK): Version 23.0.1
- Java: Version 23.0.1
- Make Sure JAVA_HOME environment variables are set: Tutorial
- Apache Maven: Version 3.9.9
- Launch4j: Version 3.50 (for bundling into .exe format)
- Open a terminal/command prompt and clone the project in your desired location:
git clone <repo-url>.
YourPathTo Is the path of where you are locating the required files, they are machine INDEPENDENT. My YourPathTo will be different from Yours YourPathTo!!!.
- Navigate to the root of the directory
cd C:\YourPathTo\VirtualPetGame. - Use Maven to clean package the project
mvn clean package. This will generate a jar-with-dependencies JAR file in the target folder. - Ensure the target folder contains the VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jar:
dir targetshould show the two .jar files below:VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jarVirtualPetGame-1.0-SNAPSHOT.jar
Now, to make VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jar into a .exe file, we used Launch4j to bundle all required resources into one folder, and then made the .exe file, hence why the user does not need to have even Java to play the game, since we included a custom jre (java runtime environemnt),however, the user is ofcourse required to have Java if they wish to build and develop the game.
- Command to Create the JRE Folder
jlink --module-path "C:\Program Files\Java\jdk-23.0.1\jmods;C:\YourPathTo\javafx-jmods-23.0.1" --add-modules java.base,java.desktop,javafx.controls,javafx.fxml,javafx.media --output C:\Program Files\jre. This will create a java runtime environment to be bundled inside the final game folder, which will allow users who do not have java installed to play the game. - Copy the JavaFX lib folder
C:\YourPathTo\javafx-jmods-23.0.1\lib, copy the entire lib folder. Put theVirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jarfrom Step 2 and both folders from Step 3.1 and 3.2 into whichever directory you desire. For example:C:\Program Files\GAME - Prepare the Game Folder: Now, create a directory to place all the necessary files. For example, use C:\Program Files\GAME. Inside this folder, place:
- VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jar (from the target folder).
- The jre folder (from the jlink output).
- The lib folder (from JavaFX SDK).
- Download and install Launch4j if you have not already.
- In the
Basictab:- Choose the output file name and its directory, preferebaly, keep it in the same directory you chose for Step 3, here, it is
C:\Program Files\GAMEdo not forget to end the name with .exe - Choose the Jar file to be VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jar in the directory you chose, here, it is
C:\Program Files\GAME\VirtualPetGame-1.0-SNAPSHOT-jar-with-dependencies.jar. - (Optional) Choose a .ico image for your .exe file.
- Keep the
Change Dirto the current directory, which is..
- Choose the output file name and its directory, preferebaly, keep it in the same directory you chose for Step 3, here, it is
- In the
Classpathtab:- Put the Main class as org.example.VirtualPetGame
- Add a New Classpath, type in .\lib and click Accept.
- In the
JREtab:- Put the JRE paths as
.\jre - Put the Min JRE version as 23.
- Put in the JVM options the following:
--module-path ./lib --add-modules javafx.controls,javafx.fxml,javafx.media --add-opens=javafx.base/com.sun.javafx=ALL-UNNAMED.
- Put the JRE paths as
- Click on the gear above in Launch4j to generate the .exe file, it will ask you to input a name for a .xml file, choose your desired name and directory for the generated .xml file, as it will not affect the process.
After generating the .exe file, you are able to run and play the game and distribute it to users who do not even have Java!
The software is very straight forward to use. Run the application by building the project, or by unzipping the GAME zip file and running the .exe file, and navigate your way in the game using the buttons provided.
In the Parental Controls you will be able to have a normal distribution of the sessions played in the game. You will be able to restrict time by setting a range in the format of ##:## where the range is from 00:00 to 23:59.