Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // code written by Raphael Jans Caballegan, Diane Sula, Joshua Franz Sabaot
- // stats
- // health, hunger, sleep array names
- String[] stat_names = ["Fitness", "Hunger", "Sleep"]
- // health, hunger, sleep array values
- int[] stats = [100, 100, 100]
- // mechanics
- int days = 5
- int actions = 2
- int dec_form = 0
- String condition = "WIN"
- // choice array used to validate for the random mood
- String[] choice_arr = ["a", "b", "c"]
- // mood array that is randomly picked each action
- String[] mood = ["OUT OF SHAPE", "CRAVING FOOD", "TIRED"]
- // game end message array
- String[] lost = new String[3]
- lost[0] = "The cat died because of fatigue!"
- lost[1] = "The cat died of excessive eating!"
- lost[2] = "The cat died from a nightmare!"
- // object instantiation
- Scanner sc = new Scanner(System.in)
- Random rn = new Random()
- // display cat method according to state
- static void displayCat(int state) {
- if (state == 101) {
- println " /\\_____/\\"
- println " / \$ \$ \\"
- println " ( == V == )"
- println " ) ("
- println " ( )"
- println " ( | | | | )"
- println "(__(__)___(__)__)"
- }else if (state > 75 && state <= 100) {
- println " /\\_____/\\"
- println " / ^ ^ \\"
- println " ( == V == )"
- println " ) ("
- println " ( )"
- println " ( | | | | )"
- println "(__(__)___(__)__)"
- } else if (state > 50 && state < 75) {
- println " /\\_____/\\"
- println " / O O \\"
- println " ( == _ == )"
- println " ) ("
- println " ( )"
- println " ( | | | | )"
- println "(__(__)___(__)__)"
- } else if (state > 0 && state < 50) {
- println " /\\_____/\\"
- println " / O O \\"
- println " ( == ^ == )"
- println " ) ("
- println " ( )"
- println " ( | | | | )"
- println "(__(__)___(__)__)"
- } else {
- println " /\\_____/\\"
- println " / x x \\"
- println " ( == 3 == )"
- println " ) ("
- println " ( )"
- println " ( | | | | )"
- println "(__(__)___(__)__)"
- }
- }
- // instruction
- println "VIRTUAL CAT GAME"
- println " "
- println "Instructions:"
- println "> To win the game, choose an action that will balance your cat's health for 5 days."
- println "> The cat will have a random mood/feeling for each day that will either have a penalty or a bonus depending on your chosen action."
- println "> The selected action(exercising, eating or sleeping) will add value to its corresponding attribute."
- println "> The cat's attributes will go down exponentially with the number of days passed."
- println "> The game will end when any of the cat's attributes drop to 0 or when you win the game."
- println " "
- println "***************************************************************************************************************"
- println " "
- println "What do you wanna call your pet cat? "
- print "-> "
- String cat_name = sc.nextLine()
- println cat_name + "! What a nice name, hope you take care of " + cat_name + " well!"
- println " "
- println "---------------------------------------------------------------------------------------------------------------"
- println " "
- for (i in 1..days) {
- // lose condition checks every day if any of the attributes are less than or equal to 0
- if (stats[0] <= 0 || stats[1] <= 0 || stats[2] <= 0) {
- condition = "LOSE"
- displayCat(0)
- break
- }
- // gets the average of all the attributes
- int ave = (stats[0] + stats[1] + stats[2]) / 3
- println ""
- println "DAY: " + i
- // displays the cat art based on the average
- displayCat(ave)
- println " "
- for (j in 1..actions) {
- // randomize mood per action
- int rand_mood = Math.abs(rn.nextInt() % 3) + 1
- // display stats
- println " "
- println "Current statistics:"
- println "Previous Deduction: " + (dec_form * 3)
- println "Fitness: " + stats[0]
- println "Hunger: " + stats[1]
- println "Sleep: " + stats[2]
- println " "
- // doesn't work yet
- println "[!<- " + cat_name + " IS " + mood[rand_mood - 1] + " TODAY ->!]"
- // display actions
- println ""
- println "Actions Remaining: " + (actions - j + 1)
- println " "
- println "What should your cat do?: "
- println "a. Exercise"
- println "b. Eat"
- println "c. Sleep"
- print "-> "
- // gets input from the user
- String choice = sc.nextLine()
- // increment value
- // a formula would be nice
- int i_choice = choice_arr.findIndexOf { it == choice.toLowerCase() }
- int modifier = 0
- // bonus message string
- String bonus_msg = ""
- // check if action choice corresponds with the current mood
- if (i_choice == rand_mood - 1) {
- modifier = 10
- bonus_msg = "[ + Bonus from giving what " + cat_name + " needed ]"
- } else {
- println "\n[ Didn't give what " + cat_name + " needed! -15 to " + stat_names[rand_mood - 1] + " ]"
- for (k in 0..2) {
- if (k == rand_mood - 1) {
- stats[k] -= 15
- }
- }
- }
- // attribute increment formula based on the decrement formula plus the bonus from the mood
- int inc_value = 10 + dec_form + modifier
- String attr;
- switch(choice.toLowerCase()) {
- case "a":
- attr = "Fitness"
- stats[0] += inc_value
- break;
- case "b":
- attr = "Hunger"
- stats[1] += inc_value
- break;
- case "c":
- attr = "Sleep"
- stats[2] += inc_value
- break;
- default :
- println("[ Input invalid ]")
- break;
- }
- println " "
- println "[ Added " + inc_value + " to " + attr + " ] " + bonus_msg
- }
- // decrement formula
- // decrement value increases exponentially every in-game day
- dec_form = Math.pow(1 + (4 / i), i)
- // applies the dec. formula at the end of each day
- stats[0] -= (dec_form * 3)
- stats[1] -= (dec_form * 3)
- stats[2] -= (dec_form * 3)
- println " "
- println "************************************************************"
- println " "
- }
- // algo to display the game ending message depending on the greatest attribute value at the end of the game
- // stores all the final values of the attributes at the end of the game
- int[] finalval = [stats[0], stats[1], stats[2]]
- int max = finalval.max() // gets max value
- int i_max = finalval.findIndexOf { it == max } // finds the index of that max value
- println "YOU " + condition + "!"
- if (condition == "LOSE") {
- println lost[i_max]
- } else {
- displayCat(101)
- println "You're a certified cat parent!"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement