Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_status()
- puts "It's day #{$day}. You have #{$logs} logs and #{$chunks} of chunks."
- end
- def print_action()
- puts "nWhat will you do? n 1. Cut a tree n 2. Split logs into chunks n 3. Go to sleep n 4. Die and end the simulation"
- puts "nYour choice:"
- end
- def print_delimiter()
- puts "n------------------------------------------------------------"
- end
- def user_interaction()
- print_delimiter()
- print_status()
- print_action()
- end
- def end_day()
- puts "nDay has passed and you burned a single chunk."
- $day += 1
- $chunks -= 1
- end
- $day = 1
- $logs = 0
- $chunks = 3
- puts 'You are a logger in 1526. Try to survive.'
- while $chunks > 0 do
- user_interaction()
- choice = gets.to_i
- case choice
- when 1
- chopped_trees = rand(2..4)
- $logs += chopped_trees
- puts "nYou cut #{chopped_trees} trees, you got #{chopped_trees} logs from them."
- end_day()
- when 2
- if $logs == 0
- puts "nYou have no logs to split."
- end_day()
- next
- end
- logs_to_chop = rand(2..5)
- if logs_to_chop > $logs
- logs_to_chop = $logs
- end
- $logs -= logs_to_chop
- $chunks += logs_to_chop*2
- puts "nYou split #{logs_to_chop} logs to #{logs_to_chop*2} chunks."
- end_day()
- next
- when 3
- puts "nYou go to sleep."
- end_day()
- next
- when 4
- puts "nYou died."
- exit
- else
- puts "nInvalid input"
- next
- end
- end
- puts 'You run out of chunks. You froze to death.'
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement