class
Oyuncu
attr_accessor :isim, :can, :hasar
def initialize(gelenIsim, gelenCan, gelenHasar)
@isim = gelenIsim
@can = gelenCan
@hasar = gelenHasar
end
def yasiyorMu
@can > 0
end
def saldir(rakip)
rakip.can -= self.hasar
end
def to_s
"#{isim} - - - Can: #{can}, hasar: #{hasar}"
end
end
def
dovus(oyuncu1, oyuncu2)
while oyuncu1.yasiyorMu && oyuncu2.yasiyorMu
oyuncu1.saldir(oyuncu2)
oyuncu2.saldir(oyuncu1)
bilgi(oyuncu1, oyuncu2)
end
if oyuncu1.yasiyorMu
puts "#{oyuncu1.isim} Kazandi!"
elsif oyuncu2.yasiyorMu
puts "#{oyuncu2.isim} Kazandi"
else
puts "Round Berabere"
end
end
def bilgi(*n)
n.each { |x| puts x }
end
#oyuncu objelerini oluşturalım
oyuncu1
=
Oyuncu.new("Ali", 1+rand(100), 1+rand(12))
oyuncu2
=
Oyuncu.new("Veli", 1+rand(100), 1+rand(12))
#oyuncu bilgilerini gösterelim
puts
"Oyuncularin Ozellikleri"
bilgi(oyuncu1, oyuncu2)
#Dovus Basliyor
puts
"DOVUS BASLASIN!"
dovus(oyuncu1, oyuncu2)
Hiç yorum yok:
Yorum Gönder