You are on page 1of 3

import java.util.

Scanner;

/*
Project: Lovable Digital Pet
Project Description: A simulation of a pet, can be fed, played with, bathed etc.
Name: Arsalan Atif
Date created: 28-02-2024
*/

public class Tamagotchi_Arsalan {


public static void main(String[] args) {

// Initialize stats of 300 energy and 300 ickiness


int[] stats = {300, 300};

String face = "(´ε` )";

// Display starting message


startingMessage(face,stats);
petStats(stats);

// Run the game for 6 turns


for (int i = 0; i < 6; i++){
if (i == 3){
System.out.println("You have 3 turns left");

System.out.println("---------------------------------------------------------------
------");
}
String updater = petInteraction();
stats = (petUpdater(updater, stats));
petStats(stats);
}

// Display ending message


String final_face = finalForm(stats);
endingMessage(final_face);
}

/** A method that prints the starting message, based on the initialized stats
* @param face The face of the Tamagotchi
* @param stats An array containing the stats of the Tamagotchi
*/
public static void startingMessage(String face, int[] stats){
System.out.println("Please take care of me! I am smol and powerless...\n");
System.out.println(face);
}

/**
* Prompts the user to choose if they'd like to play, feed, exercise or bathe
their pet. Returns their response in string format
* */
public static String petInteraction(){
Scanner user_input = new Scanner(System.in);
System.out.println("What do you want to do? Enter feed, exercise, play, or
bathe: ");
System.out.println("---------------------------------------------------------------
------");
String response = user_input.nextLine();
return response;
}

/**
* Takes the return statement from petInteraction to update the stats array
based on user response
* @param stats An array containing the stats of the Tamagotchi
* @param updater The response from the user taken by petInteraction
*/
public static int[] petUpdater(String updater, int[] stats){
if ("feed".equals(updater)){
stats[0] += 500;
}
else if (updater.equals("exercise")){
stats[0] -= 400;
}

else if (updater.equals("play")){
stats[1] += 450;
}

else if (updater.equals("bathe")){
stats[1] -= 800;
}

return stats;
}

/** Takes the current stats of the pet and prints them
*
* @param stats An array containing the stats of the Tamagotchi
*/
public static void petStats(int[] stats){

System.out.println("---------------------------------------------------------------
------");
System.out.println("Your tamagotchi's current stats are: ");
System.out.println("Energy: " + stats[0]);
System.out.println("Ickiness: " + stats[1]);

System.out.println("---------------------------------------------------------------
------");
}

/**
* Determines the form of the pet based on stats and returns the face of the
pet
* @param stats An array containing the stats of the Tamagotchi
*/
public static String finalForm(int[] stats){
String face = "";
if (stats[0] >= 1500 && stats[1] >= 1500){
face = "(ノ◕ヮ◕)ノ*:・゚✧";
}
else if (stats[0] > 1500 && stats[1] < 1500){
face = "ᕙ(⇀‸↼‶)ᕗ";
}
else if (stats[0] < 1500 && stats[1] >= 1500){
face = "ˁ( ⦿ᴥ⦿ )ˀ";
}
else if (stats[0] < 1500 && stats[1] < 1500){
face = "ヽ( ̄(エ) ̄)ノ";
}
return face;
}

/** Gets the face of the pet and prints the ending message after 6 loops
*
* @param final_face The final form of the Tamagotchi
*/
public static void endingMessage(String final_face){
System.out.println("Congrats! You have fully raised your tamagotchi to
adulthood!\n");

System.out.println(final_face);
System.out.println("\nThank you, caregiver! I am off to live my life!");
}
}

You might also like