Skip to content

Instantly share code, notes, and snippets.

@maximedelpit
Created January 14, 2015 18:08
Show Gist options
  • Save maximedelpit/5d560fca7b6043180f8f to your computer and use it in GitHub Desktop.
Save maximedelpit/5d560fca7b6043180f8f to your computer and use it in GitHub Desktop.
Livecode_oranger.rb
class Oranger
attr_reader :age, :height, :fruits
def initialize
@age = 0
@height = 0
@fruits = 0
@alive = true
end
def one_year_passes
@age +=1
@fruits = 0
@alive = compute_health
if dead? == false
@height += 1 if @age <= 10
grow_fruit
end
end
def pick_a_fruit
if @fruits > 0
@fruits -= 1
return 1
else
return 0
end
end
def dead?
!@alive
end
private
def compute_health
return false unless @alive
if @age <= 50
true
elsif 50 < @age && @age <= 100
return [true, false].sample
else
false
end
end
def grow_fruit
if @age > 5 && @age <= 10
@fruits = 100
elsif @age > 10 && @age <= 15
@fruits = 200
else
@fruits = 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment