加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
求教,我根据《RGSS3教程大家写.pdf》照搬例子,为什么报错……
class Vector attr_reader :X,:y @@n = 0 def self.sum(*vecs) x = y = 0 vecs.each{|v|x+=v.x;y+=v.y} Vector.new(x,y) end def initialize(x,y) @x = x @y = y @@n +=1 end def Vector.report @@n end NULL = Vector.new(0,0) end a = Vector.new(1,2) b = Vector.new(2,4) c = Vector.sum(a,b,Vector::NULL) msgbox "("+c.x.to_s+","+c.y.to_s+")"
class Vector
attr_reader :X,:y
@@n = 0
def self.sum(*vecs)
x = y = 0
vecs.each{|v|x+=v.x;y+=v.y}
Vector.new(x,y)
end
def initialize(x,y)
@x = x
@y = y
@@n +=1
end
def Vector.report
@@n
end
NULL = Vector.new(0,0)
end
a = Vector.new(1,2)
b = Vector.new(2,4)
c = Vector.sum(a,b,Vector::NULL)
msgbox "("+c.x.to_s+","+c.y.to_s+")"
|