Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions bike.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#SEBA's example of walking through classes

# class Bike

# attr_reader :brand

# def initialize(args ={})
# @brand = args[:brand]
# @year = args[:year]
# @color = args[:color]
# end


# def self.create_bikes_array(array_of_args)
# array_of_args.map do |args|
# Bike.new(args)
# end

# end

# def self.return_an_inst_of_bike(bike_arg_hash)
# p self
# Bike.new(bike_arg_hash)

# end

# def create_bikes_array(array_of_args)
# p self
# end

# end


# b1 = {brand: "scott", year: 2016, color: "red"}
# b2 = {brand: "specialized", year: 2016, color: "blue"}
# b3 = {brand: "Releigh", year: 2016, color: "white"}

# bike = Bike.new(b1)
# # p Bike.create_bikes_array([b1,b2,b3])
# # p bike
# # p Bike.return_an_inst_of_bike(b1)
# bike.create_bikes_array("hi")


# arr = Bike.create_bikes_array([b1, b2, b3])
# p arr[0][:brand]

# [< Instance of Bike 1>, <Instance of Bike 2>, <Instance of Bike 3>]

# Stretch print this baby ["scott", "specialized", "Releigh"]
4 changes: 3 additions & 1 deletion driver_code_release_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
p (game.guess(2) == "Too low!")

puts "Wrong guess deducts from remaining guesses"
# p game.remaining_guesses
p (game.remaining_guesses == 4)

puts "Repeated guesses do not cost the user anything"
p (game.guess(2) == "Too low!")
p (game.remaining_guesses == 4)

p game.remaining_guesses
puts "Wrong guess receives feedback"
p (game.guess(11) == "Too high!")

Expand Down Expand Up @@ -75,3 +76,4 @@
puts "Outcome is recorded correctly for lost game"
p (losing_game.has_won? == false)
p (losing_game.has_lost? == true)

83 changes: 83 additions & 0 deletions guessing_game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
class GuessingGame

attr_accessor :congrats_message, :secret_num, :guesses, :remaining_guesses


def initialize(secret_num,remaining_guesses)
@secret_num = secret_num
@remaining_guesses = remaining_guesses
@congrats_message = "Yay, you won!"
@has_won = false
@has_lost = false
@guessed_numbers = []
end

def has_won?
@has_won
end

def has_lost?
@has_lost
end

def guess(number)
output = ""
if has_lost? == false && has_won? == false
if !@guessed_numbers.include?(number)
@remaining_guesses -= 1
@guessed_numbers << number
end

if number < @secret_num
output = "Too low!"
end

if number > @secret_num
output = "Too high!"
end

if @remaining_guesses == 1
output = "Too high! WARNING: Only one guess left!"
end

if number == @secret_num
output = "#{@congrats_message} The number was #{@secret_num}"
@has_won = true
return output
end
if @remaining_guesses == 0 && @has_won == false
@has_lost = true
output = "You lost! The number was #{@secret_num}"
return output
end
end
if @has_won
output = "You already won. The number was #{@secret_num}"
end

if @has_lost
output ="You already lost. The number was #{@secret_num}"
end
output
end
end

# def guessed_nums
# @guessed_numbers.each do |num|

# end

# @guessed_numbers.each do |exisiting_nums|
# if exisiting_nums = number
# puts "you guessed"
# else
# if number < @secret_num
# return "Too low!"
# @remaining_guesses -= 1
# elsif number > @secret_num
# return "Too high!"
# @remaining_guesses -= 1
# end
# end
# end