diff --git a/magicmaze/filemap.rb b/magicmaze/filemap.rb index 69bf28b..cd5ba4c 100644 --- a/magicmaze/filemap.rb +++ b/magicmaze/filemap.rb @@ -55,14 +55,23 @@ def initialize( filename, monster_maker = nil ) } end + + def convert_string_to_bytes( str ) + if str.respond_to?(:bytes) then + str.bytes.collect{|i| i } # Ruby 1.9 + else + str # Ruby 1.8 + end + end ## # Extract various data from the header part of the map. - def extract_from_header( header_data ) + def extract_from_header( header_data_str ) + header_data = convert_string_to_bytes( header_data_str ) @checksum = header_data[16] + (header_data[17]<<8) @startx = header_data[24] @starty = header_data[25] @default_wall_tile = header_data[30] - @last_level = header_data[32]&BLOCKED_BIT==BLOCKED_BIT + @last_level = header_data[32] & BLOCKED_BIT == BLOCKED_BIT @title = "" index = 128 @@ -123,7 +132,7 @@ def each_column( &block ) # If the most significant bit is set, it is blocked. # If the coordinate is outside the map, a default block is returned. def get_background_data( x, y ) - row = @map_rows[y] + row = convert_string_to_bytes(@map_rows[y]) row ||= EMPTY_ROW index = x*2 if (index<0||index>=row.size) then @@ -143,7 +152,8 @@ def get_background_tile( x, y ) ## # return object code for the position given. def get_object( x, y ) - object = @map_rows[y][x*2+1] + row = convert_string_to_bytes(@map_rows[y]) + object = row[x*2+1] end alias :get_object_data :get_object diff --git a/magicmaze/graphics.rb b/magicmaze/graphics.rb index 0b63d4c..cad7cab 100644 --- a/magicmaze/graphics.rb +++ b/magicmaze/graphics.rb @@ -490,7 +490,7 @@ def show_help 'Alt :- Cast secondary spell', 'X / Z :- Toggle attack spell', 'A / S :- Toggle secondary spell', - '', + '', # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 'Esc / Q :- Quit playing', 'F9 / R :- Restart level', # '[F4]: Load game [F5]: Save game', @@ -502,7 +502,7 @@ def show_help y_offset = 0 font = @font16 lines.each{|line| - write_smooth_text( line, 5, y_offset, font ) + write_smooth_text( line, 5, y_offset, font ) if line.size.nonzero? # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 on empty string. y_offset+= font.height } diff --git a/magicmaze/images.rb b/magicmaze/images.rb index fd3d149..4489cc1 100644 --- a/magicmaze/images.rb +++ b/magicmaze/images.rb @@ -87,7 +87,7 @@ def write_text( text, x, y, font = @font16 ) end def write_smooth_text( text, x, y, font = @font16,r=255,g=255,b=255 ) - font.drawBlendedUTF8(@screen, text, x,y, r,g,b) + font.drawBlendedUTF8(@screen, text, x,y, r,g,b) # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 on multiline strings. end def set_palette( pal, start_color = 0 ) diff --git a/magicmaze/map.rb b/magicmaze/map.rb index 122ef0e..112a864 100644 --- a/magicmaze/map.rb +++ b/magicmaze/map.rb @@ -10,6 +10,7 @@ ############################################################ require 'magicmaze/tile' +require 'magicmaze/entity' module MagicMaze diff --git a/magicmaze/test_filemap.rb b/magicmaze/test_filemap.rb new file mode 100644 index 0000000..dd92e2a --- /dev/null +++ b/magicmaze/test_filemap.rb @@ -0,0 +1,19 @@ +require 'test/unit' + +require 'magicmaze/filemap' + +class TestFileMap < Test::Unit::TestCase + def setup + end + + def test_loading_filemaps + (1..10).each do|level| + filename = sprintf "data/maps/mm_map.%03d", level + filemap = MagicMaze::FileMap.new( filename ) + assert( filemap ) + gamemap = filemap.to_gamemap + assert( gamemap ) + assert( filemap.title.size.nonzero? ) + end + end +end diff --git a/magicmaze/test_graphics.rb b/magicmaze/test_graphics.rb index 4312b79..73b1d9f 100644 --- a/magicmaze/test_graphics.rb +++ b/magicmaze/test_graphics.rb @@ -47,7 +47,7 @@ def test_write_score def test_show_message @g.show_message("Test") @g.show_message("Testing the message box", false) - @g.show_message("Testing the message box... \n" * 5) + # @g.show_message("Testing the message box... \n" * 5 + "And stop!") # Failed for RubySDL2.0.1 and Ruby1.9.1-p1 end def test_show_long_message diff --git a/magicmaze/test_magicmaze.rb b/magicmaze/test_magicmaze.rb index 43fe9c3..9e0e762 100644 --- a/magicmaze/test_magicmaze.rb +++ b/magicmaze/test_magicmaze.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'magicmaze/test_tile' +require 'magicmaze/test_filemap' require 'magicmaze/test_map' require 'magicmaze/test_movement' require 'magicmaze/test_player'