From: Steve Rees Date: 2011-01-13T07:02:07+09:00 Subject: random orc game I am learning, slowly, how to use ruby. This is a small game I made, will be changing the random win/lose decider to a question/answer system. If anyone has time to give it a quick test as it is and tell me where certain parts arent working and why, I would really appreciate it. One of the main parts which doesnt work as i expect it to, no matter how I have changed the order and the wording is the code near the bottom of the script which counts player lives used when health reaches zero. It appears to wait until orc health is zero to process the player's health, even if player's health is a minus number. I can post this as an attachment if this is unsuiably long as text. def ask question goodAnswer = false while (not goodAnswer) puts question response = gets.chomp attack = rand(11) attacker = rand(11) if (response.to_s == 'fight') goodAnswer = true if attack.to_i >= attacker.to_i answer = true and (damage = (attack.to_i - attacker.to_i)) puts 'You Win by ' + (attack.to_i - attacker.to_i).to_s + 'hitpoints' gets puts 'You are Strong!' gets else answer = false puts 'You lose by ' + (attack.to_i - attacker.to_i).to_s + 'hitpoints' gets puts 'You should have run!' gets end else puts 'Please answer fight' end end answer end hair = ['Lank', 'Greasy', 'Skanky', 'Dirty', 'Smelly'] colour = ['green', 'brown', 'red', 'black', 'wormy', 'slick'] puts 'Your Health begins at 100 hitpoints, you have 5 lives' print 'A queue of Orcs is lining up to attack you, press enter to continue...' initialise = gets reply = 'yes' health = 100 orchealth = 100 orcs = 0 lives = 0 while reply == 'yes' matches = ask 'Do you attack? (type:fight)' puts 'Did you win?' gets puts puts matches if matches == false then health = (health - 50) orcheath = orchealth gets puts puts 'The Orc\'s health is now ' + orchealth.to_s gets puts 'Your health is now ' + health.to_s puts gets puts 'Would you like to fight again? (please answer yes to play again or enter to quit' reply = gets.chomp else matches == true health = health orchealth = (orchealth - 50) puts puts 'The Orc\'s health is now ' + orchealth.to_s gets puts 'Your health remains at ' + health.to_s puts gets puts 'Would you like to fight again? (please answer yes to play again or enter to quit' reply = gets.chomp while (orchealth == 0) or (health == 0) while orchealth <= 0 orcs = (orcs + 1) and orchealth = 100 puts 'The number of orcs killed so far is: ' + orcs.to_s gets puts puts 'A new Orc arrives to fight, he has ' + hair[rand(4)].to_s + ', ' + colour[rand(5)].to_s + ' hair, his health is 100' gets end while health <= 0 lives = (lives + 1) and health = 100 puts 'The number your of lives used so far is: ' + lives.to_s gets puts puts 'You use up a life and your health is now 100 again' gets end while lives >=5 puts 'you die' reply = 'no' end end end end puts 'Goodbye and farewell...' -- Posted via http://www.ruby-forum.com/.