赞 | 1 |
VIP | 246 |
好人卡 | 87 |
积分 | 1 |
经验 | 34142 |
最后登录 | 2015-1-15 |
在线时间 | 323 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 323 小时
- 注册时间
- 2010-8-21
- 帖子
- 666
|
回复 79904396 的帖子
终于改好了,花了半节英语课来想....
最后发现没有 $game_actors 不是完全的Array,又只有改- # 全存档等级排行 —— by 沙漠.灰
- # 本来想用冒泡法排的,发现Array有sort!方法,直接用了
- # 默认是根目录下所有的*.rxdata文件
- # 要改的话107行 ("./") 为根目录
- # 比如("./Save/") 为 根目录下Save文件夹(前提要有,不然...嘿嘿)
- # 增加Array方法
- class Array
- # 返回单元所在位子
- def return_num(num)
- for i in 0...self.size
- return i if self[i] == num
- end
- return -1
- end
- end
- #==============================================================================
- # ■ Window_Lv
- #------------------------------------------------------------------------------
- # 显示金钱的窗口。
- #==============================================================================
- class Window_Lv < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化窗口
- #--------------------------------------------------------------------------
- def initialize(data)
- @data = data
- super(0, 0, 640, 480)
- @size = comput
- self.contents = Bitmap.new(width - 32, @size * 32)
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- self.contents.draw_text(4, 0, 580, 32, "等级风云榜",1)
- y = 32
- for lv in @new_actor
- for actor in lv
- if actor[0].name != ""
- self.contents.draw_text(4, y, 200, 32, "名称:#{actor[0].name}")
- self.contents.draw_text(204, y, 200, 32, "等级:#{actor[0].level}")
- self.contents.draw_text(354, y, 250, 32, "所在存档:#{actor[1]}")
- y += 32
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def update
- if Input.press?(Input::UP)
- self.oy -= 2 if self.oy > 0
- end
- if Input.press?(Input::DOWN)
- self.oy += 2 if self.oy < @size * 32 - self.height
- end
- end
- #--------------------------------------------------------------------------
- # ● 再计算数据
- #--------------------------------------------------------------------------
- def comput
- actor_num = 0
- # 计算等级,按高矮排序
- lv_array = []
- for data in @data
- for i in 1..999
- actor = data[0][i]
- break if actor == nil
- lv_array.push(actor.level) if !lv_array.include?(actor.level)
- end
- end
- lv_array.sort!
- lv_array.reverse!
- @new_actor = []
- lv_array.size.times {@new_actor.push([])}
- for data in @data
- for i in 1..999
- actor = data[0][i]
- break if actor == nil
- if actor.name != ""
- actor_num += 1
- num = lv_array.return_num(actor.level)
- @new_actor[num].push([actor,data[1]])
- end
- end
- end
- actor_num
- end
- end
- #==============================================================================
- # ■ Scene_Lv
- #------------------------------------------------------------------------------
- # 处理标题画面的类。
- #==============================================================================
- class Scene_Lv
- #--------------------------------------------------------------------------
- # ● 住处理
- #--------------------------------------------------------------------------
- def main
- # 读取存档
- old_dir = Dir.pwd
- Dir.chdir("./")
- @save_data = Dir["*.rxdata"]
- Dir.chdir(old_dir)
- if @save_data == []
- $scene = Scene_Title.new
- return
- end
- # 生成临时数据保存数据
- @save_actors = []
- # 正式读取
- read_data
- # 生成窗口
- @windows7好贵 = Window_Lv.new(@save_actors)
- # 生成系统对像
- $game_system = Game_System.new
- # 生成标题图形
- @sprite = Sprite.new
- @sprite.bitmap = RPG::Cache.title($data_system.title_name)
- # 演奏标题 BGM
- $game_system.bgm_play($data_system.title_bgm)
- # 停止演奏 ME、BGS
- Audio.me_stop
- Audio.bgs_stop
- # 执行过渡
- Graphics.transition
- # 主循环
- loop do
- # 刷新游戏画面
- Graphics.update
- # 刷新输入信息
- Input.update
- # 刷新画面
- update
- # 如果画面被切换就中断循环
- if $scene != self
- break
- end
- end
- # 装备过渡
- Graphics.freeze
- # 释放命令窗口
- # 释放标题图形
- @sprite.bitmap.dispose
- @sprite.dispose
- @windows7好贵.dispose
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 按下 C 键的情况下
- @windows7好贵.update
- if Input.trigger?(Input::B)
- $scene = Scene_Title.new
- end
- end
- #--------------------------------------------------------------------------
- # ● 读取数据
- #--------------------------------------------------------------------------
- def read_data
- for file in @save_data
- read_save_data(file)
- @save_actors.push([$game_actors,file])
- end
- end
- #--------------------------------------------------------------------------
- # ● 读取存档数据
- # file : 读取用文件对像 (已经打开)
- #--------------------------------------------------------------------------
- def read_save_data(file)
- file = File.open(file, "rb")
- # 读取描绘存档文件用的角色数据
- characters = Marshal.load(file)
- # 读取测量游戏时间用画面计数
- Graphics.frame_count = Marshal.load(file)
- # 读取各种游戏对像
- $game_system = Marshal.load(file)
- $game_switches = Marshal.load(file)
- $game_variables = Marshal.load(file)
- $game_self_switches = Marshal.load(file)
- $game_screen = Marshal.load(file)
- $game_actors = Marshal.load(file)
- $game_party = Marshal.load(file)
- $game_troop = Marshal.load(file)
- $game_map = Marshal.load(file)
- $game_player = Marshal.load(file)
- file.close
- end
- end
复制代码 使用 :$scene = Scene_Lv.new
附:范例
|
|