| 赞 | 13 |
| VIP | |
| 好人卡 | |
| 积分 | 16 |
| 经验 | |
| 最后登录 | 2017-7-6 |
| 在线时间 | 1564 小时 |
- 梦石
- 0
- 星屑
- 1580
- 在线时间
- 1564 小时
- 注册时间
- 2008-7-30
- 回帖
- 4207

|
发表于 2011-4-3 12:44:55
|
显示全部楼层
本帖最后由 DeathKing 于 2011-4-3 12:45 编辑
1、从RGSS来说,Input模块应该可以检测到F12的敲击,就是不知道是Input的优先级高,还是重置的优先级高。当然,可以利用F12重置游戏时,对于某些特殊情况可以引起StackTooDeepError的特点,来捕获错误,并退出。
2、考虑到Array的可以容纳的对象可以是不同的,所以还是作弊为上策。
class Array
def max
return self.sort.last
end
end
3、a != b 是因为 a 和 b 的 hash 不一样,而 Fixnum 类的 == 是根据 hash 来判断的。下面的方法或许有点暴力,直接重定义 == 方法。
class Fixnum
def ==(obj)
return self.class == obj.class
end
end
4、Foo 被认为是常量标识符,defined?(Foo) 会检查是否定义了Foo常量,而 Foo() 即使是大写字母开头,也被认为是一个方法。
5、利用三角函数,这样,x坐标大概要移动4个像素。
move_x = (5 * cos(27 / ((2 * Math::PI))).to_i
moev_y = (5 * sin(27 / ((2 * Math::PI))).to_i
6、没猜测出来。
7、有点乱,有点麻烦。
class Array
def dispose_bad_bitmap
max_area = 0
the_bad = -1
self.each_index do |index|
next unless self[index].is_a?(Bitmap)
temp_area = self[index].width * self[index].height
if temp_areo > max_area
max_area = temp_areo
the_bad = index
end
end
self[the_bad].dispose if the_bad != -1
end
end
8、ary = [0,1,2,3,4,5]
ary = ary.permutation(4).to_a
ary.each do |e|
if e[0] != 0
if e.include?(2) and e.include?(3)
i = e.index(2)
if e[i+1] != 3 and e[i-1] != 3
puts e.to_s
end
end
end
end
输出:
[1, 2, 0, 3]
[1, 2, 4, 3]
[1, 2, 5, 3]
[1, 3, 0, 2]
[1, 3, 4, 2]
[1, 3, 5, 2]
[2, 0, 3, 1]
[2, 0, 3, 4]
[2, 0, 3, 5]
[2, 1, 3, 0]
[2, 1, 3, 4]
[2, 1, 3, 5]
[2, 4, 3, 0]
[2, 4, 3, 1]
[2, 4, 3, 5]
[2, 5, 3, 0]
[2, 5, 3, 1]
[2, 5, 3, 4]
[3, 0, 1, 2]
[3, 0, 2, 1]
[3, 0, 2, 4]
[3, 0, 2, 5]
[3, 0, 4, 2]
[3, 0, 5, 2]
[3, 1, 0, 2]
[3, 1, 2, 0]
[3, 1, 2, 4]
[3, 1, 2, 5]
[3, 1, 4, 2]
[3, 1, 5, 2]
[3, 4, 0, 2]
[3, 4, 1, 2]
[3, 4, 2, 0]
[3, 4, 2, 1]
[3, 4, 2, 5]
[3, 4, 5, 2]
[3, 5, 0, 2]
[3, 5, 1, 2]
[3, 5, 2, 0]
[3, 5, 2, 1]
[3, 5, 2, 4]
[3, 5, 4, 2]
[4, 2, 0, 3]
[4, 2, 1, 3]
[4, 2, 5, 3]
[4, 3, 0, 2]
[4, 3, 1, 2]
[4, 3, 5, 2]
[5, 2, 0, 3]
[5, 2, 1, 3]
[5, 2, 4, 3]
[5, 3, 0, 2]
[5, 3, 1, 2]
[5, 3, 4, 2]
8、MathN库里面已经有了……不写了。要走了……
|
|