Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. def print_status()
  2. puts "It's day #{$day}. You have #{$logs} logs and #{$chunks} of chunks."
  3. end
  4.  
  5. def print_action()
  6. 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"
  7. puts "nYour choice:"
  8. end
  9.  
  10. def print_delimiter()
  11. puts "n------------------------------------------------------------"
  12. end
  13.  
  14. def user_interaction()
  15. print_delimiter()
  16. print_status()
  17. print_action()
  18. end
  19.  
  20. def end_day()
  21. puts "nDay has passed and you burned a single chunk."
  22. $day += 1
  23. $chunks -= 1
  24. end
  25.  
  26. $day = 1
  27. $logs = 0
  28. $chunks = 3
  29.  
  30. puts 'You are a logger in 1526. Try to survive.'
  31.  
  32. while $chunks > 0 do
  33.  
  34. user_interaction()
  35. choice = gets.to_i
  36.  
  37. case choice
  38. when 1
  39. chopped_trees = rand(2..4)
  40.  
  41. $logs += chopped_trees
  42.  
  43. puts "nYou cut #{chopped_trees} trees, you got #{chopped_trees} logs from them."
  44.  
  45. end_day()
  46. when 2
  47. if $logs == 0
  48. puts "nYou have no logs to split."
  49. end_day()
  50. next
  51. end
  52.  
  53. logs_to_chop = rand(2..5)
  54.  
  55. if logs_to_chop > $logs
  56. logs_to_chop = $logs
  57. end
  58.  
  59. $logs -= logs_to_chop
  60. $chunks += logs_to_chop*2
  61.  
  62. puts "nYou split #{logs_to_chop} logs to #{logs_to_chop*2} chunks."
  63.  
  64. end_day()
  65. next
  66. when 3
  67. puts "nYou go to sleep."
  68. end_day()
  69. next
  70. when 4
  71. puts "nYou died."
  72. exit
  73. else
  74. puts "nInvalid input"
  75. next
  76. end
  77. end
  78.  
  79. puts 'You run out of chunks. You froze to death.'
  80. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement