Skip to content

Instantly share code, notes, and snippets.

@koduki
Created December 15, 2014 12:31
Show Gist options
  • Save koduki/75b3463a0c4c4f6d4102 to your computer and use it in GitHub Desktop.
Save koduki/75b3463a0c4c4f6d4102 to your computer and use it in GitHub Desktop.
class Character
attr_accessor :name, :hp, :df
def initialize name, hp
@name = name
@hp = hp
@atk = 2
@df = 1
end
def atack
@atk * rand(3)
end
end
def battle c1, c2
dmg = c2.atack - c1.df
c1.hp -= dmg
puts "#{c2.name} atack! #{c1.name} is #{dmg} damage."
end
puts "==========="
puts "Game Start "
puts "==========="
c1 = Character.new "u1", 10
c2 = Character.new "enamy", 10
while true
if c1.hp <= 0
puts "#{c1.name} win."
break
elsif c2.hp <= 0
puts "#{c1.name} lose."
break
end
battle c1, c2
battle c2, c1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment