Last active
August 29, 2015 14:08
-
-
Save Papillard/2dac0b0e16939d09fa24 to your computer and use it in GitHub Desktop.
Fort Boyard nail's game @lewagon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def state_of_the_nail(length) | |
two_digit_length = (length * 100).truncate / 100.0 | |
return "La longueur du clou est de #{two_digit_length} cms" | |
end | |
def hit_nail(length, force) | |
# Give nail length and player force in input, e.g 8, 3 | |
# return new nail's length | |
return length - force * rand(0..1.0) | |
end | |
def display_strength_message(force) | |
if force > 4 | |
puts "that's some heavy hit.." | |
elsif force > 3 | |
puts "you are an average person" | |
else | |
puts "Eat some spinach dude..." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pick_players() | |
players = [] | |
puts "Player one, rentrez votre nom" | |
players << gets.chomp.capitalize | |
puts "Player two, rentrez votre nom" | |
players << gets.chomp.capitalize | |
return players | |
end | |
def ask_player_to_hit(players, position) | |
# Example: | |
# players => ["alex", "boris"] | |
# position => 0 ou 1 | |
puts "Player #{position + 1} (#{players[position]}), let's kick this nail!" | |
puts "Pick a power (from 1 to 5)" | |
end | |
def switch_player(position) | |
if position == 0 | |
new_position = 1 | |
else | |
new_position = 0 | |
end | |
return new_position | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "players" | |
require_relative "nail" | |
puts "Welcome to fort Boyard" | |
players = pick_players() | |
nail_length = 10 | |
puts state_of_the_nail(nail_length) | |
player_number = 0 | |
while nail_length > 0 | |
ask_player_to_hit(players, player_number) | |
force = gets.chomp.to_i | |
display_strength_message(force) | |
nail_length = hit_nail(nail_length, force) | |
puts state_of_the_nail(nail_length) | |
break if nail_length <= 0 | |
player_number = switch_player(player_number) | |
end | |
puts "Bravo #{players[player_number]}, you win" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment