Advertisement
iArcsinE

progLang_cat_game_final

Jan 23rd, 2022
2,430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 6.35 KB | None | 0 0
  1. // code written by Raphael Jans Caballegan, Diane Sula, Joshua Franz Sabaot
  2.  
  3. // stats
  4. // health, hunger, sleep array names
  5. String[] stat_names = ["Fitness", "Hunger", "Sleep"]
  6.  
  7. // health, hunger, sleep array values
  8. int[] stats = [100, 100, 100]
  9.  
  10. // mechanics
  11. int days = 5
  12. int actions = 2
  13. int dec_form = 0
  14. String condition = "WIN"
  15.  
  16. // choice array used to validate for the random mood
  17. String[] choice_arr = ["a", "b", "c"]
  18.  
  19. // mood array that is randomly picked each action
  20. String[] mood = ["OUT OF SHAPE", "CRAVING FOOD", "TIRED"]
  21.  
  22. // game end message array
  23. String[] lost = new String[3]
  24. lost[0] = "The cat died because of fatigue!"
  25. lost[1] = "The cat died of excessive eating!"
  26. lost[2] = "The cat died from a nightmare!"
  27.  
  28. // object instantiation
  29. Scanner sc = new Scanner(System.in)
  30. Random rn = new Random()
  31.  
  32. // display cat method according to state
  33. static void displayCat(int state) {
  34.     if (state == 101) {
  35.         println "    /\\_____/\\"
  36.         println "   /  \$   \$  \\"
  37.         println "  ( ==  V  == )"
  38.         println "   )         ("
  39.         println "  (           )"
  40.         println " ( |  |   |  | )"
  41.         println "(__(__)___(__)__)"
  42.     }else if (state > 75 && state <= 100) {
  43.         println "    /\\_____/\\"
  44.         println "   /  ^   ^  \\"
  45.         println "  ( ==  V  == )"
  46.         println "   )         ("
  47.         println "  (           )"
  48.         println " ( |  |   |  | )"
  49.         println "(__(__)___(__)__)"
  50.     } else if (state > 50 && state < 75) {
  51.         println "    /\\_____/\\"
  52.         println "   /  O   O  \\"
  53.         println "  ( ==  _  == )"
  54.         println "   )         ("
  55.         println "  (           )"
  56.         println " ( |  |   |  | )"
  57.         println "(__(__)___(__)__)"
  58.     } else if (state > 0 && state < 50) {
  59.         println "    /\\_____/\\"
  60.         println "   /  O   O  \\"
  61.         println "  ( ==  ^  == )"
  62.         println "   )         ("
  63.         println "  (           )"
  64.         println " ( |  |   |  | )"
  65.         println "(__(__)___(__)__)"
  66.     }  else {
  67.         println "    /\\_____/\\"
  68.         println "   /  x   x  \\"
  69.         println "  ( ==  3  == )"
  70.         println "   )         ("
  71.         println "  (           )"
  72.         println " ( |  |   |  | )"
  73.         println "(__(__)___(__)__)"
  74.     }
  75. }
  76.  
  77. // instruction
  78. println "VIRTUAL CAT GAME"
  79. println " "
  80. println "Instructions:"
  81. println "> To win the game, choose an action that will balance your cat's health for 5 days."
  82. 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."
  83. println "> The selected action(exercising, eating or sleeping) will add value to its corresponding attribute."
  84. println "> The cat's attributes will go down exponentially with the number of days passed."
  85. println "> The game will end when any of the cat's attributes drop to 0 or when you win the game."
  86.  
  87. println " "
  88. println "***************************************************************************************************************"
  89. println " "
  90. println "What do you wanna call your pet cat? "
  91. print "-> "
  92.  
  93. String cat_name = sc.nextLine()
  94.  
  95. println cat_name + "! What a nice name, hope you take care of " + cat_name + " well!"
  96. println " "
  97. println "---------------------------------------------------------------------------------------------------------------"
  98. println " "
  99.  
  100. for (i in 1..days) {
  101.     // lose condition checks every day if any of the attributes are less than or equal to 0
  102.     if (stats[0] <= 0 || stats[1] <= 0 || stats[2] <= 0) {
  103.         condition = "LOSE"
  104.         displayCat(0)
  105.         break
  106.     }
  107.    
  108.     // gets the average of all the attributes
  109.     int ave = (stats[0] + stats[1] + stats[2]) / 3
  110.    
  111.     println ""
  112.     println "DAY: " + i
  113.    
  114.     // displays the cat art based on the average
  115.     displayCat(ave)
  116.     println " "
  117.    
  118.     for (j in 1..actions) {
  119.        
  120.         // randomize mood per action
  121.         int rand_mood = Math.abs(rn.nextInt() % 3) + 1
  122.        
  123.         // display stats
  124.         println " "
  125.         println "Current statistics:"
  126.         println "Previous Deduction: " + (dec_form * 3)
  127.         println "Fitness: " + stats[0]
  128.         println "Hunger: " + stats[1]
  129.         println "Sleep: " + stats[2]
  130.         println " "
  131.         // doesn't work yet
  132.         println "[!<- " + cat_name + " IS " + mood[rand_mood - 1] + " TODAY ->!]"
  133.         // display actions
  134.         println ""
  135.         println "Actions Remaining: " + (actions - j + 1)
  136.         println " "
  137.         println "What should your cat do?: "
  138.         println "a. Exercise"
  139.         println "b. Eat"
  140.         println "c. Sleep"
  141.         print "-> "
  142.        
  143.         // gets input from the user
  144.         String choice = sc.nextLine()
  145.        
  146.         // increment value
  147.         // a formula would be nice
  148.         int i_choice = choice_arr.findIndexOf { it == choice.toLowerCase() }
  149.         int modifier = 0
  150.        
  151.         // bonus message string
  152.         String bonus_msg = ""
  153.        
  154.         // check if action choice corresponds with the current mood
  155.         if (i_choice == rand_mood - 1) {
  156.             modifier = 10
  157.             bonus_msg = "[ + Bonus from giving what " + cat_name + " needed ]"
  158.         } else {
  159.             println "\n[ Didn't give what " + cat_name + " needed! -15 to " + stat_names[rand_mood - 1] + " ]"
  160.             for (k in 0..2) {
  161.                 if (k == rand_mood - 1) {
  162.                     stats[k] -= 15
  163.                 }
  164.             }
  165.         }
  166.        
  167.         // attribute increment formula based on the decrement formula plus the bonus from the mood
  168.         int inc_value = 10 + dec_form + modifier
  169.         String attr;
  170.        
  171.         switch(choice.toLowerCase()) {
  172.             case "a":
  173.                 attr = "Fitness"
  174.                 stats[0] += inc_value
  175.                 break;
  176.             case "b":
  177.                 attr = "Hunger"
  178.                 stats[1] += inc_value
  179.                 break;
  180.             case "c":
  181.                 attr = "Sleep"
  182.                 stats[2] += inc_value
  183.                 break;
  184.             default :
  185.                 println("[ Input invalid ]")
  186.                 break;
  187.         }
  188.         println " "
  189.         println "[ Added " + inc_value + " to " + attr + " ] " + bonus_msg
  190.        
  191.     }
  192.    
  193.     // decrement formula
  194.     // decrement value increases exponentially every in-game day
  195.     dec_form = Math.pow(1 + (4 / i), i)
  196.    
  197.     // applies the dec. formula at the end of each day
  198.     stats[0] -= (dec_form * 3)
  199.     stats[1] -= (dec_form * 3)
  200.     stats[2] -= (dec_form * 3)
  201.    
  202.     println " "
  203.     println "************************************************************"
  204.     println " "
  205.  
  206. }
  207.  
  208. // algo to display the game ending message depending on the greatest attribute value at the end of the game
  209. // stores all the final values of the attributes at the end of the game
  210. int[] finalval = [stats[0], stats[1], stats[2]]
  211.  
  212. int max = finalval.max()                        // gets max value
  213. int i_max = finalval.findIndexOf { it == max }  // finds the index of that max value
  214.  
  215. println "YOU " + condition + "!"
  216. if (condition == "LOSE") {
  217.     println lost[i_max]
  218. } else {
  219.     displayCat(101)
  220.     println "You're a certified cat parent!"
  221. }
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement