var grablevel : flexible array 1 .. 1 of string % Each different object group has its own spot in this array, before we parse each obj into individual chars.
var mapPartsArray : array 1 .. 100, 1 .. 7 of string % Our array for storing each different object parsed into individual chars.
var curMapObject : string % This is the string of the current type of object we are parsing
var blockcounter : int % This is counting what individual block we are on.
var lngth : int % Show the length of the
var mapfile : int % this is the pointer turing uses for the I/O stream for the mapfile
var curObjectType : int % This is the type of the object we are parsing. IE: the ground blocks are a "1"
var usrchoice : int % A variable for removal later. This is currently to test the loading of different mapfiles
var numbObjects : int % How many objects are in the map file. Should be the standard, but this is a fallback so the program doesn't crash if a user gives us a malformed mapfile.
put "Please enter the map file to load."
get usrchoice
if usrchoice = 1 then % these two if statements are to check if the program can handle different file lengths
open : mapfile, "levels/1.txt", get % eventually this will be removed and dynamically generate a list of levels for the user to choose
end if
if usrchoice = 2 then
open : mapfile, "levels/2.txt", get
end if
numbObjects := 0
curObjectType := 1
loop % grabbing the data from the level
exit when eof (mapfile) % exit the loop when we've reached the end of the mapfile
get : mapfile, grablevel (upper (grablevel)) % grabbing the text
new grablevel, upper (grablevel) + 1 % on the next loop move onto the next line in the map file
put "Success! Map object #", curObjectType, " was parsed correctly: " .. % let's see if this succedes after each loop
put grablevel (curObjectType) % put the current ASCII character string into the grablevel array that holds the basic objects, not yet parsed to individual chars.
curObjectType := curObjectType + 1 % every time we parse a new line, we also move onto the next map object.
numbObjects := numbObjects + 1 % add up the total number of different objects in the map. See the def. by the variable 'numbObjects' for a complete description.
%delay (500)
end loop
%delay (1000)
curObjectType := 1
blockcounter := 1
loop % Let's loop to parse all the map objects sections into characters in the 'mapPartsArray' array.
curMapObject := grablevel (curObjectType) % setting the current type of object we are parsing
lngth := length (curMapObject) % grabbing the length of the
put grablevel (curObjectType), " :: curObjectType" % print the current map file section we are parsing
put curMapObject, " :: curMapObject" % make sure that the current "block" of code was inserted into it's string properly
put curObjectType, " :: curObjectType" % more debug printing, this one shows what map object type we are parsing currently.
put " "
%delay (500)
blockcounter := 1
loop % loop until we parse the whole string into the array
mapPartsArray (blockcounter, curObjectType) := curMapObject (1) % make the the location in the array specified by 'blockcounter' be equal to the first char of the current "block" of the map file
%delay (50) % slow so we can see what is going on
put mapPartsArray (blockcounter, curObjectType).. % make sure things are being parsed correctly
blockcounter := blockcounter + 1 % lets add up how many blocks we've inspected
curMapObject := curMapObject (2 .. lngth) % shave off the first char of curMapObject. It's been stored in an array, we don't need it anymore, since it's been stored in an array.
lngth := length (curMapObject) % grab the new length after shaving off the first char
exit when lngth = 0 % exit the loop when we've parsed the whole string
end loop
put " "
curObjectType := curObjectType + 1 % why not move onto the next map object?
numbObjects := numbObjects - 1
exit when numbObjects = 0 % end the loop once we've parsed all the map objects :: must be one higher then the actual # of objects
end loop