-
Notifications
You must be signed in to change notification settings - Fork 30
write game #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
valerieshoskes
wants to merge
1
commit into
paircolumbus:master
Choose a base branch
from
valerieshoskes:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
write game #23
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could try using a heredoc for these multi-line strings:
https://ruby-doc.org/core-2.2.2/doc/syntax/literals_rdoc.html