赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 5550 |
最后登录 | 2014-3-21 |
在线时间 | 37 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 37 小时
- 注册时间
- 2008-6-13
- 帖子
- 99
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
话说那个recipe似乎是食谱= =
主代码在下面- class TCItem
- attr_accessor :kind
- attr_accessor :num
- attr_accessor :amount
- def initialize(kind, num, amount)
- @kind = kind
- @num = num
- @amount = amount
- end
- def kind
- return @kind
- end
- def kind=(newkind)
- @kind = newkind
- end
- def num
- return @num
- end
- def num=(newnum)
- @num = newnum
- end
- def amount
- return @amount
- end
- def amount=(newamount)
- @amount = newamount
- end
- def gain
- if @kind = 1
- $game_party.gain_item(@num, @amount)
- elsif @kind = 2
- $game_party.gain_weapon(@num, @amount)
- elsif @kind = 3
- $game_party.gain_armor(@num, @amount)
- elsif @kind = 0
- $game_party.gain_gold(@amount)
- end
- end
- def lose
- if @kind = 1
- $game_party.lose_item(@num, @amount)
- elsif @kind = 2
- $game_party.lose_weapon(@num, @amount)
- elsif @kind = 3
- $game_party.lose_armor(@num, @amount)
- elsif @kind = 0
- $game_party.lose_gold(@amount)
- end
- end
- def to_string
- if @kind = 1
- return $data_item[@num].name + "(物品) × " + @amount.to_s
- elsif @kind = 2
- return $data_weapon[@num].name + "(武器) × " + @amount.to_s
- elsif @kind = 3
- return $data_armor[@num].name + "(防具) × " + @amount.to_s
- elsif @kind = 0
- return "金钱 " + @amount.to_s + " " + $data_system.words.gold
- end
- end
- def is_had
- if @kind = 1
- return $game_party.item_number(@num) >= @amount
- elsif @kind = 2
- return $game_party.weapon_number(@num) >= @amount
- elsif @kind = 3
- return $game_party.armor_number(@num) >= @amount
- elsif @kind = 0
- return $game_party.gold >= @amount
- end
- end
- end
- class TCRecipe
- attr_accessor :materialkinds
- attr_accessor :material
- attr_accessor :productkinds
- attr_accessor :product
- attr_accessor :name
- def initialize(name, ms, ps)
- @name = name
- @material = ms
- @product = ps
- @materialkinds = ms.length
- @productkinds = ps.length
- end
- def name
- return @name
- end
- def list_of_material
- if @materialkinds = 0
- return "无"
- elsif @materialkinds = 1
- return @material[1].to_string
- else
- q = ""
- @material.each{|unit| q << (unit.to_string + " ")}
- return q.strip
- end
- end
- def list_of_product
- if @productkinds = 0
- return "无"
- elsif @productkinds = 1
- return @product[1].to_string
- else
- q = ""
- @product.each{|unit| q << (unit.to_string + " ")}
- return q.strip
- end
- end
- def is_can_use
- q = true
- @material.each{|unit| q = q and unit.is_had}
- return q
- end
- def use_it
- @material.each{|unit| unit.lose}
- @product.each{|unit| unit.gain}
- end
- end
复制代码 测试时的代码是这样- a1 = TCItem.new(1, 1, 3)
- a2 = TCItem.new(1, 2, 1)
- a3 = TCItem.new(0, 0, 1000)
- b1 = TCItem.new(1, 3, 1)
- b2 = TCItem.new(2, 1, 1)
- b3 = TCItem.new(3, 1, 1)
- a = [a1, a2, a3]
- b = [b1, b2, b3]
- $reci = TCRecipe.new("test", a, b)
- p $reci.name
- p $reci.is_can_use
- p $reci.list_of_material
- p $reci.list_of_product
复制代码 结果打印出来的结果是
"test"
true
"无"
"无"
也就是说"原料"数组和“成品”数组没有被读入
求高手挑刺,到底是哪里出了问题
|
|