
April 25th, 2011, 01:10 AM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 2
Time spent in forums: 24 m
Reputation Power: 0
|
|
|
Orc fight, first code.
Hey all, brand new to ruby and coding in general and I was hoping to get a few pointers/comments on my first piece of code. Any feed back would be greatly appreciated!
It's a simple text based battle with an orc.
Code:
orchp = 20
php = 20
hitroll= nil
ardamage = nil
orcdead = false
playerdead = false
playerrun = false
orcatk = nil
orcdmg = nil
orcturn = true
puts 'OMG! It\'s an orc!!!'
while orcdead == false and playerdead == false and playerrun == false
sleep 1
puts 'What do you do? (Run, Attack, or Look) (Look does not take a turn)'
response = gets.chomp.downcase
if response == 'attack'
hitroll = rand(20) + 1
if hitroll > 10
ardamage = rand(6) + 1
sleep 1
puts 'You hit the orc!'
sleep 1
puts 'You did ' + ardamage.to_s + ' damage!'
orchp = orchp - ardamage
if orchp <= 0
sleep 1
puts 'The orc has fallen!'
orcdead = true
orcturn = false
end
else
sleep 1
puts 'You missed!'
end
if orcturn == true
orcatk = rand(20) + 1
if orcatk > 15
orcdmg = rand(6) + 1
sleep 1
puts 'The orc struck you for ' + orcdmg.to_s + ' damage!'
php = php - orcdmg
if php <= 0
sleep 1
puts 'You have fallen!'
playerdead = true
end
else
sleep 1
puts 'The orc missed!'
end
end
elsif response == 'run'
sleep 1
puts 'You ran away!'
playerrun = true
orcturn = false
elsif response == 'look'
sleep 1
puts 'The orc has ' + orchp.to_s + ' HP left!'
sleep 1
puts 'You have ' + php.to_s + ' HP left!'
else
puts 'Invalid command.'
end
end
|