diff --git a/Valeries-Game/controller.rb b/Valeries-Game/controller.rb new file mode 100644 index 0000000..215cb5d --- /dev/null +++ b/Valeries-Game/controller.rb @@ -0,0 +1,45 @@ +require_relative 'view' +require_relative 'model' + +class GameController + include GameView + + def run! + Print::intro + pet_type = Print::get_pet_type + pet_name = Print::get_pet_name(pet_type) + my_pet = Pet.new({ + :petName => pet_name, + :petType => pet_type + }) + loop do + Print::menu(my_pet) + case Print::fetch_user_input + when "1" + my_pet.feed + when "2" + my_pet.provide_water + when "3" + my_pet.play + when "4" + my_pet.clean_waste + when "5" + my_pet.tuck_in + when "q" + puts "We're done" + exit + else + Print::error_message + end + if my_pet.nutrition >= 20 && my_pet.hydration >= 20 && my_pet.socialization >= 20 && my_pet.cleanliness >= 20 && my_pet.energy >= 20 + Print::win + exit + elsif my_pet.nutrition <= 0 || my_pet.hydration <= 0 || my_pet.socialization <= 0 || my_pet.cleanliness <= 0 || my_pet.energy <= 0 + Print::lose + exit + end + end + + end +end +GameController.new.run! \ No newline at end of file diff --git a/Valeries-Game/model.rb b/Valeries-Game/model.rb new file mode 100644 index 0000000..b230db6 --- /dev/null +++ b/Valeries-Game/model.rb @@ -0,0 +1,44 @@ +class Pet + attr_accessor :petName, :petType, :nutrition, :hydration, :socialization, :cleanliness, :energy + + def initialize args + @petName = args[:petName] + @petType = args[:petType] + @nutrition = 15 + @hydration = 15 + @socialization = 15 + @cleanliness = 15 + @energy = 15 + end + + def feed + @nutrition += 3 + @hydration -= 1 + @cleanliness -= 1 + @energy -= 1 + end + + def provide_water + @hydration += 3 + @cleanliness -= 1 + end + + def play + @nutrition -= 1 + @hydration -= 1 + @socialization += 3 + @energy -= 1 + end + + def clean_waste + @socialization -= 1 + @cleanliness += 3 + end + + def tuck_in + @nutrition -= 1 + @hydration -= 1 + @socialization -= 1 + @energy += 4 + end +end diff --git a/Valeries-Game/view.rb b/Valeries-Game/view.rb new file mode 100644 index 0000000..cba2b31 --- /dev/null +++ b/Valeries-Game/view.rb @@ -0,0 +1,78 @@ +module GameView + module Print + class << self + def intro + puts "Welcome to the Virtual Pet Foster Simulator!" + #puts "Type \"Quit\" at any time to quit the game" + puts "Raise all attributes to 20, and a family will adopt your pet!" + puts "If a single attribute falls to 0, animal control will assign a more suitable foster..." + end + def get_pet_type + loop do + puts "Would you like to foster a cat or a dog?" + puts "Please type cat or dog." + petType = gets.chomp.downcase + return petType if petType == "cat" || petType == "dog" + end + end + def get_pet_name(petType) + puts "What is your #{petType}'s name?" + petName = gets.chomp + puts "#{petName} is almost ready to go!" + puts "All their attributes are at 15, so they need some more work." + return petName + end + def menu(pet) + if pet.petType == "cat" + puts " /\\___/\\" + puts " ( ^ ^ )" + puts " ( =!= )" + puts " ( )" + puts " ( )" + puts " ( oo oo )))))))))))" + else + puts " ___ " + puts " //^ ^\\\\" + puts " (/(_•_)\\)" + puts " _/''*''\\_" + puts " (,,,)^(,,,) " + end + puts "Here is #{pet.petName}'s current state:" + puts "Nutrition is at: #{pet.nutrition}" + puts "Hydration is at: #{pet.hydration}" + puts "Socialization is at: #{pet.socialization}" + puts "Cleanliness is at: #{pet.cleanliness}" + puts "Energy is at: #{pet.energy}" + puts "Press 1 to feed, 2 to provide water, 3 to play," + puts "4 to clean up waste, or 5 to tuck in for the night" + end + def fetch_user_input(question=nil) + puts question if question + print "> " + gets.chomp + end + def error_message + puts "That's not a command key. Try again!" + end + def win + puts "You took excellent care of your pet!" + puts "A wonderful family is adopting them, and they'll always remember their time with you!" + puts "__ __ _____ _ _ _ _ _ " + puts "\\ \\ / / | __ \\ (_) | | (_) | || |" + puts " \\ \\_/ /__ _ _ | | | | _ __| | | |_| || |" + puts " \\ / _ \\| | | | | | | || |/ _` | | |__ || |" + puts " | | (_) | |_| | | |__| || | (_| | | | | ||_|" + puts " |_|\\___ /\\__,_| | _____/|_|\\__,_| |_| \\__(_)" + puts "Press any key to exit" + gets.chomp + end + def lose + puts "You haven't been taking care of your pet very well.." + puts "Animal control was called in time, they're going to a better foster family." + puts "YOU LOSE!" + puts "Press any key to exit" + gets.chomp + end + end +end +end