Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 25th, 2011, 01:10 AM
Abro25 Abro25 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 2 Abro25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 25th, 2011, 09:55 AM
MrFujin's Avatar
MrFujin MrFujin is offline
Lord of the Dance
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Oct 2003
Posts: 3,129 MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level)MrFujin User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 22 h 8 m 38 sec
Reputation Power: 1736
It looks nice.

Some comments and/or change of variable name could make it better.
For example, the variable php could use a comment explaining that it is the player hp or be renamed to playerhp.

Reply With Quote
  #3  
Old April 25th, 2011, 06:13 PM
Abro25 Abro25 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 2 Abro25 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m
Reputation Power: 0
Thanks alot MrFujin for giving it a look and thanks for your response!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Orc fight, first code.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap