Darn can't edit my post at all...
Well I've updated my code for the .t file it's much better! I had to detect carriage returns so stuffs alinging proper, but I'm still upside down! I think it's a for loop somewhere but having trouble finding it.
Edit: Added maxy + 200 - the Y axis on the drawing font for the walls to fix it.
Sorry for the long post below, spoiler doesn't seem to be hiding with a button for "Show"
Spoiler: |
Turing: |
var debug : boolean := false
/* Counts the number of mazes */
var dir := Dir.Current
var fileName : string
var stream : int := Dir.Open (dir )
var counter : int := 0
loop
fileName := Dir.Get (stream )
exit when fileName = ""
if length (fileName ) > 4 then
if Str.Lower (fileName (length (fileName ) - 3 .. length (fileName ))) = ".txt" then
counter + = 1
end if
end if
end loop
Dir.Close (stream )
/* Adds the maze names into an array */
var file : array 1 .. counter of string
counter := 0
stream := Dir.Open (dir )
loop
fileName := Dir.Get (stream )
exit when fileName = ""
if length (fileName ) > 4 then
if Str.Lower (fileName (length (fileName ) - 3 .. length (fileName ))) = ".txt" then
counter + = 1
file (counter ) := fileName
end if
end if
end loop
/* Load datafrom all mazes into arrays */
View.Set ("text")
var ch : char := ' '
var fileID : int
var row : int := 0
var column : int := 0
var numOfRows, numOfColumns : array 1 .. counter of int
for i : 1 .. counter % Go through each file
open : fileID, file (i ), get
loop
exit when eof (fileID )
get : fileID, ch
column + = 1
if ch = '\n' then
column := 0
row + = 1
end if
end loop
close : fileID
row + = 1
%put file (i), "\n", column, " x ", row, "\n"
%put "Putting ", row, " into numOfRows (", i, ")"
numOfRows (i ) := row
%put "Putting ", column, " into numOfColumns (", i, ")"
numOfColumns (i ) := column
column := 0
row := 0
end for
for i : 1 .. counter
%put numOfRows (i), 'x', numOfColumns (i)
end for
var maze : array 1 .. counter, 1 .. 99, 1 .. 99 of char
for i : 1 .. counter
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
maze (i, x, y ) := '*' % Empties array
end for
end for
end for
var charX : int := 0
var charY : int := 1
for i : 1 .. counter % go through each file
open : fileID, file (i ), get
loop
exit when eof (fileID )
get : fileID, ch
/*
charX += 1
if charX = numOfColumns (i) then
charX := 1
if charY < numOfRows (i) then
charY += 1
end if
end if
if not ch = '\n' then
%put charX, " ", charY, " ", maze (i, charX, charY), " is now ", ch
maze (i, charX, charY) := ch
end if
*/
charX + = 1
if ch = '\n' then
charY + = 1
charX := 0
else
maze (i, charX, charY ) := ch
%put charX, "/", charY, "=", maze (i, charX, charY), " " ..
end if
end loop
%put " "
charX := 0
charY := 1
close : fileID
end for
for i : 1 .. 3
for c : 1 .. 3
%put maze (1, c, i) ..
end for
%put ""
end for
%Input.Pause
View.Set ("graphics;offscreenonly")
var mouseX, mouseY, button, updown : int
var boxX, boxY : int := 0
var boxWidth, boxHeight : int := 5
var col : int := white
var fontSize : int := 7
var charFont : int := Font.New ("Sans Serif:" + intstr (fontSize ))
var nameFont : int := Font.New ("Sans Serif:14")
var levelFontSize : int := 20
var levelFont : int := Font.New ("Sans Serif:" + intstr (levelFontSize ))
var heightY : int := 60
var topText : string := ""
var firstTime : boolean := true
var outputID : int
for i : 1 .. 3
for s : 1 .. 3
%put maze (1, i, s) ..
end for
end for
loop
Mouse.Where (mouseX, mouseY, button )
Draw.FillBox (0, 0, maxx, maxy, black)
Font.Draw (topText, maxx div 2 - 40, maxy - 50, nameFont, white)
topText := "Select a Level"
for i : 1 .. counter
heightY := 60
boxX := i * 50 - 30
if boxX > maxx - 50 then
boxX - = maxx - 39
heightY - = 35
%levelFontSize -= 12
%Font.Free(levelFont)
%levelFont := Font.New ("Serif:" + intstr(levelFontSize))
end if
if mouseX >= 20 + boxX and mouseX <= 50 + boxX and mouseY >= heightY - 10 and mouseY <= heightY + 20 then
col := yellow
% DRAW PREVIEW
topText := file (i )
for y : 1 ..numOfRows (i )
for x : 1 .. numOfColumns (i )
Font.Draw (maze (i, x, y ), x * fontSize + (maxx div 6), (maxy - y * fontSize + (maxy div 3))- 250, charFont, white)
%Font.Draw (intstr (x) + "x" + intstr (y), x * 40 + (maxx div 6), y * 40 + (maxy div 2), defFontID, white)
end for
end for
if button = 1 then
if not firstTime then
Window.Close (outputID )
end if
firstTime := false
Mouse.ButtonWait ("up", mouseX, mouseY, button, updown )
outputID := Window.Open ("text,position:" + intstr (maxx * 2 - 30) + "," + intstr (maxy - 300))
for y : 1 .. numOfRows (i )
for x : 1 .. numOfColumns (i )
put maze (i, x, y ) ..
end for
put ""
end for
open : fileID, file (i ), get
loop
exit when eof (fileID )
get : fileID, ch
charX + = 1
if charX = numOfColumns (i ) then
charX := 1
if charY < numOfRows (i ) then
charY + = 1
end if
end if
%put ch ..
end loop
close : fileID
if debug then
put "DONE"
end if
Window.SetActive (defWinID )
end if
else
col := white
end if
%Draw.FillBox (20 + boxX, heightY - 10, 50 + boxX, heightY + 20, blue)
%Draw.Box (20 + boxX, heightY - 10, 50 + boxX, heightY + 20, brightred)
Font.Draw (intstr (i ), boxX + 20, heightY - 5, levelFont, col )
end for
View.Update
cls
end loop
|
| |