Advertisement
Qpel

objektinis dalele

Mar 21st, 2018
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.34 KB | None | 0 0
  1. class Ckolba
  2.   class Cdalele
  3. ##----------------------------------------------------------------    
  4.     def initialize (x,y)
  5.       i=0
  6.       @x=x
  7.       @y=y
  8.     end
  9. ##----------------------------------------------------------------      
  10.     def Soulis (temp)
  11.       if temp<10
  12.         @dx=0
  13.         @dy=0
  14.       end
  15.       if ((temp>=10) and (temp<=20))  
  16.         @dx=1
  17.         @dy=1
  18.       end
  19.       if temp>20
  20.         @dx=3
  21.         @dy=3
  22.       end
  23.       @x+=rand(-@dx..@dx)
  24.       @y+=rand(-@dy..@dy)
  25.       if(temp>=10)
  26.         print "x=",@x," y=",@y,"\n"
  27.       end
  28.     end
  29.   end
  30. ##----------------------------------------------------------------    
  31.   def initialize()
  32.     @dalele=Cdalele.new(0,0)
  33.     @dalele.Soulis(0)
  34.   end
  35. ##----------------------------------------------------------------      
  36.   def Sildimas(temp,k)
  37.     print "Temperatura= ", temp,"\n"
  38.     if (temp<10)
  39.       print "Visos #{k} daleliu nepajudejo"
  40.     else
  41.       for j in 1..k
  42.         @temp=temp
  43.         @k=k
  44.         print "#{j}-os daleles pozicija: "
  45.         @dalele.Soulis(@temp)
  46.       end
  47.     end
  48.   end
  49. end
  50. ##----------------------------------------------------------------
  51. for i in 1..2
  52.   t=rand(0..30)
  53.   print "#{i}-a kolba","\n"
  54.   print "Pradine daleles pozicija kolboje: "
  55.   kolba=Ckolba.new()
  56.   kolba.Sildimas(t,20)
  57.   print "\n"
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement