-
Notifications
You must be signed in to change notification settings - Fork 27
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
Samantha Berk & Winifred Irarrazaval - Word-Guess - Octos #15
base: master
Are you sure you want to change the base?
Changes from all commits
0ae40de
4799fb9
dcad84f
e181549
60c4b57
5788c33
1189e67
20aeb5e
4c3b029
c812334
33a239e
cbe4bd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
require 'colorize' | ||
class Picture | ||
attr_accessor :parachute_man, :life | ||
def initialize | ||
@parachute_strings = [' \\ ' ,' |','_','| ', ' /'] | ||
@life = 4 | ||
top | ||
print_strings | ||
puts | ||
bottom | ||
|
||
end | ||
def top | ||
puts " _________".colorize(:blue) | ||
puts ' / \ '.colorize(:blue) | ||
puts ' / _ _ _ \ '.colorize(:blue) | ||
puts ' |/ \\ / \\ / \\|'.colorize(:blue) | ||
end | ||
|
||
def bottom | ||
puts ' o (_} o '.colorize(:white) | ||
puts ' \\/.X.\\/'.colorize(:white) | ||
puts ' |_|'.colorize(:white) | ||
puts ' // \\\\ '.colorize(:white) | ||
puts ' \\\\ //'.colorize(:white) | ||
puts ' U U'.colorize(:white) | ||
end | ||
def print_strings | ||
@parachute_strings.each do |string| | ||
print string.colorize(:magenta) | ||
end | ||
end | ||
|
||
# def removing_strings | ||
# case | ||
# when @life == 4 | ||
# print_strings | ||
# when @life == 3 | ||
# @parachute_strings[-1] = " " | ||
# print_strings | ||
# when @life == 2 | ||
# @parachute_strings[-1] = " " | ||
# @parachute_strings[-2] = " " | ||
# print_strings | ||
# when @life == 1 | ||
# @parachute_strings[-1] = " " | ||
# @parachute_strings[-2] = " " | ||
# @parachute_strings[-4] = " " | ||
# print_strings | ||
# when @life == 0 | ||
# @parachute_strings[-1] = " " | ||
# @parachute_strings[-2] = " " | ||
# @parachute_strings[-4] = " " | ||
# @parachute_strings[0] = " " | ||
# print_strings | ||
def remove1 | ||
@parachute_strings[-1] = " " | ||
print_strings | ||
end | ||
def remove2 | ||
@parachute_strings[-1] = " " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that this code is duplicated, but it's also a tricky thing to figure out how to print only what you want. What if you modified the def print_strings(lives_left)
# strings before the center strap
(0...2).each do |i|
if i <= lives_left
print @parachute_strings[i].colorize(:magenta)
else
print " " * @parachute_strings[i].length
end
end
# center strap
print @parachute_strings[2]
# strings after the strap
(3...5).each do |i|
if i <= lives_left
print @parachute_strings[i].colorize(:magenta)
else
print " " * @parachute_strings[i].length
end
end
end The center strap makes the whole thing much more complex - maybe it would be best to just take it out. |
||
@parachute_strings[-2] = " " | ||
print_strings | ||
end | ||
def remove3 | ||
@parachute_strings[-1] = " " | ||
@parachute_strings[-2] = " " | ||
@parachute_strings[-4] = " " | ||
print_strings | ||
end | ||
def remove4 | ||
@parachute_strings[-1] = " " | ||
@parachute_strings[-2] = " " | ||
@parachute_strings[-4] = " " | ||
@parachute_strings[0] = " " | ||
print_strings | ||
end | ||
|
||
# end | ||
|
||
end | ||
|
||
|
||
class Game | ||
attr_accessor :secret_word_array, :user_input, :life, :correct_guesses_array, :picture, :incorrect_guesses | ||
|
||
def initialize(secret_word, picture, life) | ||
@picture = picture | ||
@secret_word_array = secret_word | ||
@user_input = 0 | ||
@incorrect_guesses = [] | ||
@correct_guesses_array = Array.new(@secret_word_array.length, "_") | ||
@life = life | ||
end | ||
|
||
# Method to compare user_input to secret_word | ||
def compare(guess) | ||
@user_input = guess | ||
@secret_word_array.each do |letter| | ||
if letter == @user_input | ||
@correct_guesses_array[@secret_word_array.index(letter)] = letter | ||
end | ||
end | ||
if @correct_guesses_array.include?(@user_input) == false | ||
@incorrect_guesses << @user_input | ||
|
||
puts "\n False guesses :#{@incorrect_guesses}" | ||
@picture.top | ||
case @life | ||
when 4 | ||
@picture.remove1 | ||
when 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we made the above change, here we would replace this entire case statement with: @picture.print_strings(@life) |
||
@picture.remove2 | ||
when 2 | ||
@picture.remove3 | ||
when 1 | ||
@picture.remove4 | ||
# @picture.removing_strings | ||
end | ||
@life -= 1 | ||
puts | ||
@picture.bottom | ||
end | ||
end | ||
end | ||
word_list = ["cat", "dog", "horse", "bird"] | ||
|
||
|
||
parachute_man = Picture.new() | ||
new_game = Game.new(word_list.sample.split(""), parachute_man, parachute_man.life ) | ||
puts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the initial life count comes from the picture, it's a little redundant to pass both into the constructor here. |
||
|
||
|
||
# get user input | ||
puts "--------------------" | ||
puts " W O R D G A M E" | ||
puts "--------------------" | ||
puts "Welcome to the guessing game\n" | ||
puts "The secret word:" | ||
puts "#{new_game.correct_guesses_array}" | ||
puts "--------------------" | ||
puts "Lives: #{new_game.life}" | ||
puts "Please guess your first letter: " | ||
guess = gets.chomp.to_s.downcase | ||
new_game.compare(guess) | ||
puts "#{new_game.correct_guesses_array}" | ||
puts "------------------" | ||
|
||
|
||
until new_game.life == 0 || (new_game.correct_guesses_array == new_game.secret_word_array) | ||
puts "Lives: #{new_game.life}" | ||
puts "Guess another letter:" | ||
guess = gets.chomp.to_s.downcase | ||
while new_game.incorrect_guesses.include?(guess) | ||
puts "You already tried that letter- it's still not the right answer! Choose another." | ||
guess = gets.chomp.to_s.downcase | ||
end | ||
new_game.compare(guess) | ||
puts "#{new_game.correct_guesses_array}" | ||
|
||
puts "------------------" | ||
end | ||
if new_game.life == 0 | ||
puts "-----------------------" | ||
puts "You C R A S H E D!! Bye" | ||
puts "-----------------------" | ||
else new_game.correct_guesses_array == new_game.secret_word_array | ||
puts "--------------------------" | ||
puts "you won! Beautiful landing!" | ||
puts "--------------------------" | ||
end |
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.
This file should be named
word_guess.rb
. Without the suffix, GitHub doesn't know to syntax highlight it!