this is a try of making an offline version of the great fxm freebasic syntax challenges.
There is some memory leaks for the moment and this is only a enigma reader. Still lacking the user entry methods, and any scoring method (based on success of execution).
About this last point, it would be nice to have the fbc path returned by an intrinsic command rather than searching the disk.
Code: Select all
''FXM FREEBASIC CHALLENGES MADE LIVE!
''> see on internet freebasic forum for the raw material:
''> http://www.freebasic.net/forum/viewtopic.php?f=17&t=25257#p227097
''notes of this first version:
'' -> memory leaking with images? when enigma switches
'' -> draw string on the images misses some pixels lines!?
#include "fbgfx.bi"
#define _freebasicExecutable "C:\FreeBASIC-1.05.0-win32-mingworg\fbc"
#define _tempSourceFileId "enigmatempsourcefile"
#define _MIN(a, b) iif((a)<(b), (a), (b))
#define _MAX(a, b) iif((a)>(b), (a), (b))
type BUTTON
declare constructor()
declare constructor(byval TLCX as integer, _
byval TLCY as integer, _
byval Wdt as integer, _
byval Hgt as integer, _
byref Txt as const string)
declare sub TestMouse()
declare sub DrawButton()
as integer _topLeftCornerX
as integer _topLeftCornerY
as integer _width
as integer _height
as string _text
as double _lastClickTime
as double _buttonClickDelay
as boolean _hasMouseOver
as boolean _hasMouseClick
end type
constructor BUTTON()
dim as integer scrW, scrH
screenInfo scrW, scrH
'
with THIS
._text => "BTN"
._topLeftCornerX => scrW\2
._topLeftCornerY => scrH\2
._width => _MAX(scrW\4, (len(._text)*8))
._height => scrH\4
._text => "btn"
._lastClickTime => -1
._buttonClickDelay => .5
._hasMouseOver => FALSE
._hasMouseClick => FALSE
end with
end constructor
constructor BUTTON(byval TLCX as integer, _
byval TLCY as integer, _
byval Wdt as integer, _
byval Hgt as integer, _
byref Txt as const string)
with THIS
._topLeftCornerX => TLCX
._topLeftCornerY => TLCY
._width => Wdt
._height => Hgt
._text => Txt
._lastClickTime => -1
._buttonClickDelay => .5
._hasMouseOver => FALSE
._hasMouseClick => FALSE
end with
end constructor
sub BUTTON.TestMouse()
dim as integer gmX, gmY, gmWheel, gmBtn
getMouse gmX, gmY, gmWheel, gmBtn
'
if gmX=-1 orElse gmY=-1 then exit sub
'
if gmX>=THIS._topLeftCornerX andAlso _
gmX<=THIS._topLeftCornerX + THIS._width andAlso _
gmY>=THIS._topLeftCornerY andAlso _
gmY<=THIS._topLeftCornerY + THIS._height then
if not THIS._hasMouseOver then THIS._hasMouseOver = TRUE
if gmBtn>0 then
if not THIS._hasMouseClick then THIS._hasMouseClick = TRUE
else
if THIS._hasMouseClick then THIS._hasMouseClick = FALSE
end if
else
if THIS._hasMouseOver then THIS._hasMouseOver = FALSE
if THIS._hasMouseClick then THIS._hasMouseClick = FALSE
end if
end sub
sub BUTTON.DrawButton()
THIS.TestMouse()
'
line (THIS._topLeftCornerX, THIS._topLeftCornerY)- _
step(THIS._width, THIS._height), _
7, _
bf
line (THIS._topLeftCornerX, THIS._topLeftCornerY)- _
step(THIS._width, THIS._height), _
2, _
b
if THIS._hasMouseClick then
line (THIS._topLeftCornerX, THIS._topLeftCornerY)- _
step(THIS._width, THIS._height), _
10, _
bf
elseIf THIS._hasMouseOver then
line (THIS._topLeftCornerX, THIS._topLeftCornerY)- _
step(THIS._width, THIS._height), _
11, _
bf
end if
draw string ((THIS._topLeftCornerX - (len(THIS._text )*8)\2 + THIS._width\2), _
THIS._topLeftCornerY + THIS._height\2), _
left(THIS._text, THIS._width\8)
end sub
type STRINGBLOC
as string _stringLines(any)
end type
type ENIGMA
declare constructor()
declare constructor(byval EnigmaIndex as integer)
declare destructor()
declare sub GetEnigma(byval EnigmaIndex as integer=0)
declare sub CreateEnigmaTitleImage()
declare sub CreateEnigmaInstructionImage()
declare sub CreateEnigmaCodeImage()
declare sub CreateUserCodeBlocImage()
declare sub GetUserCodeBlocText(byval BlocIndex as integer=0)
declare sub BuildExecutable()
as integer _dataIndex
as string _title
as integer _instructionLinesTotalCount
as string _instructionLines(any)
as integer _codeBlocTotalCount
as STRINGBLOC _codeLinesBlocs(any)
as integer _userInsertedCodeBlocTotalCount
as STRINGBLOC _userInsertedCodeLinesBlocs(any)
as integer _fontWidth
as integer _fontHeight
as integer _imgWidth
as integer _imgHeight
as fb.IMAGE ptr _titleImage
as fb.IMAGE ptr _instructionImage
as fb.IMAGE ptr _codeBlocImage(any)
as fb.IMAGE ptr _userCodeBlocImage(any)
end type
constructor ENIGMA()
with THIS
._dataIndex => 0
._fontWidth => iif(._fontWidth<=0, 8, ._fontWidth)
._fontHeight => iif(._fontHeight<=0, 8, ._fontHeight)
end with
THIS.GetEnigma(THIS._dataIndex)
with THIS
._instructionLinesTotalCount => uBound(THIS._instructionLines) + 1
._codeBlocTotalCount => uBound(THIS._codeLinesBlocs) + 1
._userInsertedCodeBlocTotalCount => uBound(THIS._userInsertedCodeLinesBlocs) + 1
end with
'
'compute the max string length to set up the images width
dim as integer maxLineLength => 0
if len(THIS._title)>maxLineLength then
maxLineLength = len(THIS._title)
end if
for index as integer = 0 to THIS._instructionLinesTotalCount - 1
if len(THIS._instructionLines(index))>maxLineLength then
maxLineLength = len(THIS._instructionLines(index))
end if
next index
for blocIndex as integer = 0 to uBound(THIS._codeLinesBlocs)
for lineIndex as integer = 0 to uBound(THIS._codeLinesBlocs(blocIndex)._stringLines)
if len(THIS._codeLinesBlocs(blocIndex)._stringLines(lineIndex))>maxLineLength then
maxLineLength = len(THIS._codeLinesBlocs(blocIndex)._stringLines(lineIndex))
end if
next lineIndex
next blocIndex
for blocIndex as integer = 0 to uBound(THIS._userInsertedCodeLinesBlocs)
for lineIndex as integer = 0 to uBound(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines)
if len(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines(lineIndex))>maxLineLength then
maxLineLength = len(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines(lineIndex))
end if
next lineIndex
next blocIndex
'
'make the images
THIS._imgWidth => THIS._fontWidth*THIS._fontWidth + 4
THIS.CreateEnigmaTitleImage()
THIS.CreateEnigmaInstructionImage()
THIS.CreateEnigmaCodeImage()
THIS.CreateUserCodeBlocImage()
end constructor
constructor ENIGMA(byval EnigmaIndex as integer)
with THIS
._dataIndex => EnigmaIndex
._fontWidth => iif(._fontWidth<=0, 8, ._fontWidth)
._fontHeight => iif(._fontHeight<=0, 8, ._fontHeight)
end with
THIS.GetEnigma(THIS._dataIndex)
with THIS
._instructionLinesTotalCount => uBound(THIS._instructionLines) + 1
._codeBlocTotalCount => uBound(THIS._codeLinesBlocs) + 1
._userInsertedCodeBlocTotalCount => uBound(THIS._userInsertedCodeLinesBlocs) + 1
end with
'
'compute the max string length to set up the images width
dim as integer maxLineLength => 0
if len(THIS._title)>maxLineLength then
maxLineLength = len(THIS._title)
end if
for index as integer = 0 to THIS._instructionLinesTotalCount - 1
if len(THIS._instructionLines(index))>maxLineLength then
maxLineLength = len(THIS._instructionLines(index))
end if
next index
for blocIndex as integer = 0 to uBound(THIS._codeLinesBlocs)
for lineIndex as integer = 0 to uBound(THIS._codeLinesBlocs(blocIndex)._stringLines)
if len(THIS._codeLinesBlocs(blocIndex)._stringLines(lineIndex))>maxLineLength then
maxLineLength = len(THIS._codeLinesBlocs(blocIndex)._stringLines(lineIndex))
end if
next lineIndex
next blocIndex
for blocIndex as integer = 0 to uBound(THIS._userInsertedCodeLinesBlocs)
for lineIndex as integer = 0 to uBound(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines)
if len(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines(lineIndex))>maxLineLength then
maxLineLength = len(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines(lineIndex))
end if
next lineIndex
next blocIndex
'
'make the images
THIS._imgWidth => THIS._fontWidth*THIS._fontWidth + 4
THIS.CreateEnigmaTitleImage()
THIS.CreateEnigmaInstructionImage()
THIS.CreateEnigmaCodeImage()
THIS.CreateUserCodeBlocImage()
end constructor
destructor ENIGMA()
/'
imageDestroy(THIS._titleImage)
imageDestroy(THIS._instructionImage)
for index as integer = 0 to uBound(THIS._codeBlocImage)
imageDestroy(THIS._codeBlocImage(index))
next index
for index as integer = 0 to uBound(THIS._userCodeBlocImage)
imageDestroy(THIS._userCodeBlocImage(index))
next index
erase THIS._codeBlocImage
erase THIS._userCodeBlocImage
'/
end destructor
sub ENIGMA.GetEnigma(byval EnigmaIndex as integer=0)
#macro _INCREASECODEBLOCARRAY()
redim preserve THIS._codeLinesBlocs(uBound(THIS._codeLinesBlocs) + 1)
#endMacro
#macro _INCREASEUSERCODEBLOCARRAY()
redim preserve THIS._userInsertedCodeLinesBlocs(uBound(THIS._userInsertedCodeLinesBlocs) + 1)
#endMacro
#macro _INCREASECODEBLOCARRAYLINECONTENT()
redim preserve _
(THIS._codeLinesBlocs(uBound(THIS._codeLinesBlocs))._stringLines) _
(uBound(THIS._codeLinesBlocs(uBound(THIS._codeLinesBlocs))._stringLines) + 1)
#endMacro
#macro _INCREASEUSERCODEBLOCARRAYLINECONTENT()
redim preserve _
(THIS._userInsertedCodeLinesBlocs(uBound(THIS._userInsertedCodeLinesBlocs))._stringLines) _
(uBound(THIS._userInsertedCodeLinesBlocs(uBound(THIS._userInsertedCodeLinesBlocs))._stringLines) + 1)
#endMacro
#macro _CODEBLOCARRAYLINECONTENT()
THIS._codeLinesBlocs(uBound(THIS._codeLinesBlocs))._stringLines _
(uBound(THIS._codeLinesBlocs(uBound(THIS._codeLinesBlocs))._stringLines))
#endMacro
#macro _USERCODEBLOCARRAYLINECONTENT()
THIS._userInsertedCodeLinesBlocs(uBound(THIS._userInsertedCodeLinesBlocs))._stringLines _
(uBound(THIS._userInsertedCodeLinesBlocs(uBound(THIS._userInsertedCodeLinesBlocs))._stringLines))
#endMacro
'
'get_data of the enigma at the enigma index
dim as string stringdata => "none"
dim as integer enigmaCurrentBloc => -1
restore datasectionLabel
do
read stringdata : if stringdata="<endofdata>" then exit sub
if trim(lCase(stringdata))="<startenig>" then enigmaCurrentBloc += 1
loop until (enigmaCurrentBloc=EnigmaIndex)
'
'get_title
read THIS._title
'
'get_instruction
do
read stringdata
redim preserve THIS._instructionLines(uBound(THIS._instructionLines) + 1)
THIS._instructionLines(uBound(THIS._instructionLines)) => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
THIS._instructionLines(uBound(THIS._instructionLines)) => "_"
'
'get_code
_INCREASECODEBLOCARRAY()
_INCREASECODEBLOCARRAYLINECONTENT()
_CODEBLOCARRAYLINECONTENT() => "'--->"
'
do
if stringdata="<startenigcod>" then
do
read stringdata
_INCREASECODEBLOCARRAYLINECONTENT()
_CODEBLOCARRAYLINECONTENT() => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
_CODEBLOCARRAYLINECONTENT() => ""
'
if stringdata="<endenig>" then
exit sub
elseIf stringdata="<endofdata>" then
exit sub
elseIf stringdata="<startins>" then
_INCREASEUSERCODEBLOCARRAY()
do
read stringdata
_INCREASEUSERCODEBLOCARRAYLINECONTENT()
_USERCODEBLOCARRAYLINECONTENT() => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<endins>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
_USERCODEBLOCARRAYLINECONTENT() => ""
if stringdata="<endenig>" then exit sub
if stringdata="<endofdata>" then exit sub
else
_INCREASECODEBLOCARRAY()
do
read stringdata
_INCREASECODEBLOCARRAYLINECONTENT()
_CODEBLOCARRAYLINECONTENT() => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<endins>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
_CODEBLOCARRAYLINECONTENT() => ""
if stringdata="<endenig>" then exit sub
if stringdata="<endofdata>" then exit sub
end if
else
if stringdata="<startins>" then
_INCREASEUSERCODEBLOCARRAY()
do
read stringdata
_INCREASEUSERCODEBLOCARRAYLINECONTENT()
_USERCODEBLOCARRAYLINECONTENT() => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<endins>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
_USERCODEBLOCARRAYLINECONTENT() => ""
if stringdata="<endenig>" then exit sub
if stringdata="<endofdata>" then exit sub
else
_INCREASECODEBLOCARRAY()
do
read stringdata
_INCREASECODEBLOCARRAYLINECONTENT()
_CODEBLOCARRAYLINECONTENT() => stringdata
loop until (stringdata="<startenigcod>" orElse _
stringdata="<endins>" orElse _
stringdata="<startins>" orElse _
stringdata="<endenig>" orElse _
stringdata="<endenigcod>" orElse _
stringdata="<endofdata>")
_CODEBLOCARRAYLINECONTENT() => ""
if stringdata="<endenig>" then exit sub
if stringdata="<endofdata>" then exit sub
end if
end if
loop
'
#undef _INCREASECODEBLOCARRAY
#undef _INCREASEUSERCODEBLOCARRAY
#undef _INCREASECODEBLOCARRAYLINECONTENT
#undef _INCREASEUSERCODEBLOCARRAYLINECONTENT
#undef _CODEBLOCARRAYLINECONTENT
#undef _USERCODEBLOCARRAYLINECONTENT
end sub
sub ENIGMA.CreateEnigmaTitleImage()
imageDestroy(THIS._titleImage)
'
THIS._titleImage => imageCreate (THIS._imgWidth*8, _
THIS._fontHeight + 4, _
15, _
8)
draw string THIS._titleImage, (1, 1), THIS._title, 0
draw string THIS._titleImage, (2, 2), THIS._title
end sub
sub ENIGMA.CreateEnigmaInstructionImage()
imageDestroy(THIS._instructionImage)
'
THIS._instructionImage => imageCreate (THIS._imgWidth*8, _
THIS._fontHeight*uBound(THIS._instructionLines) + 4, _
15, _
8)
for index as integer = 0 to uBound(THIS._instructionLines)
draw string THIS._instructionImage, _
(2, 2 + index*8), _
THIS._instructionLines(index)
next index
end sub
sub ENIGMA.CreateEnigmaCodeImage()
for index as integer = 0 to uBound(THIS._codeBlocImage)
imageDestroy(THIS._codeBlocImage(index))
next index
erase THIS._codeBlocImage
'
redim THIS._codeBlocImage(THIS._codeBlocTotalCount - 1)
for index as integer = 0 to THIS._codeBlocTotalCount - 1
dim as integer imageHeight => _
THIS._fontHeight*uBound(THIS._codeLinesBlocs(index)._stringLines) + 4
THIS._codeBlocImage(index) => imageCreate (THIS._imgWidth*8, imageHeight, 15, 8)
next index
for blocIndex as integer = 0 to THIS._codeBlocTotalCount - 1
for lineIndex as integer = 0 to uBound(THIS._codeLinesBlocs(blocIndex)._stringLines)
draw string THIS._codeBlocImage(blocIndex), _
(2, 2 + lineIndex*8), _
THIS._codeLinesBlocs(blocIndex)._stringLines(lineIndex)
next lineIndex
next blocIndex
end sub
sub ENIGMA.CreateUserCodeBlocImage()
for index as integer = 0 to uBound(THIS._userCodeBlocImage)
imageDestroy(THIS._userCodeBlocImage(index))
next index
erase THIS._userCodeBlocImage
'
redim THIS._userCodeBlocImage(THIS._userInsertedCodeBlocTotalCount - 1)
for index as integer = 0 to THIS._userInsertedCodeBlocTotalCount - 1
dim as integer imageHeight => _
THIS._fontHeight*uBound(THIS._userInsertedCodeLinesBlocs(index)._stringLines) + 4
THIS._userCodeBlocImage(index) => imageCreate (THIS._imgWidth*8, imageHeight, 14, 8)
next index
for blocIndex as integer = 0 to THIS._userInsertedCodeBlocTotalCount - 1
for lineIndex as integer = 0 to uBound(THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines)
draw string THIS._userCodeBlocImage(blocIndex), _
(2, 2 + lineIndex*8), _
THIS._userInsertedCodeLinesBlocs(blocIndex)._stringLines(lineIndex)
next lineIndex
next blocIndex
end sub
sub ENIGMA.GetUserCodeBlocText(byval BlocIndex as integer=0)
'
end sub
sub ENIGMA.BuildExecutable()
'
end sub
type IMAGEBOX
declare constructor()
declare constructor(byval TLCX as integer, _
byval TLCY as integer, _
byval Wdt as integer, _
byval Hgt as integer)
declare destructor()
declare sub TestMouse()
declare sub DrawImageBox()
as integer _topLeftCornerX
as integer _topLeftCornerY
as integer _width
as integer _height
as FB.IMAGE ptr _image
as boolean _hasMouseOver
as boolean _hasMouseClick
end type
constructor IMAGEBOX()
dim as integer scrW, scrH
screenInfo scrW, scrH
with THIS
._topLeftCornerX => .1*scrW - 2
._topLeftCornerY => .1*scrH - 2
._width => .8*scrW + 4
._height => .6*scrH + 4
._hasMouseOver => FALSE
._hasMouseClick => FALSE
end with
'
imageDestroy(THIS._image)
THIS._image => imageCreate( THIS._width -4, THIS._height - 4, 1, 8)
end constructor
constructor IMAGEBOX(byval TLCX as integer, _
byval TLCY as integer, _
byval Wdt as integer, _
byval Hgt as integer)
with THIS
._topLeftCornerX => TLCX
._topLeftCornerY => TLCY
._width => Wdt
._height => Hgt
._hasMouseOver => FALSE
._hasMouseClick => FALSE
end with
'
imageDestroy(THIS._image)
THIS._image => imageCreate( THIS._width -4, THIS._height - 4, 1, 8)
end constructor
destructor IMAGEBOX()
'
end destructor
sub IMAGEBOX.TestMouse()
dim as integer gmX, gmY, gmWheel, gmBtn
getMouse gmX, gmY, gmWheel, gmBtn
'
if gmX=-1 orElse gmY=-1 then exit sub
'
if gmX>=THIS._topLeftCornerX andAlso _
gmX<=THIS._topLeftCornerX + THIS._width andAlso _
gmY>=THIS._topLeftCornerY andAlso _
gmY<=THIS._topLeftCornerY + THIS._height then
if not THIS._hasMouseOver then THIS._hasMouseOver = TRUE
if gmBtn>0 then
if not THIS._hasMouseClick then THIS._hasMouseClick = TRUE
else
if THIS._hasMouseClick then THIS._hasMouseClick = FALSE
end if
else
if THIS._hasMouseOver then THIS._hasMouseOver = FALSE
if THIS._hasMouseClick then THIS._hasMouseClick = FALSE
end if
end sub
sub IMAGEBOX.DrawImageBox()
THIS.TestMouse()
'
if THIS._hasMouseClick then
line (THIS._topLeftCornerX, THIS._topLeftCornerY)-_
step(THIS._width, THIS._height), _
10, _
bf
line (THIS._topLeftCornerX + 1, THIS._topLeftCornerY + 1)-_
step(THIS._width - 2, THIS._height - 2), _
8, _
bf
elseIf THIS._hasMouseOver then
line (THIS._topLeftCornerX, THIS._topLeftCornerY)-_
step(THIS._width, THIS._height), _
2, _
bf
line (THIS._topLeftCornerX + 1, THIS._topLeftCornerY + 1)-_
step(THIS._width - 2, THIS._height - 2), _
8, _
bf
else
line (THIS._topLeftCornerX, THIS._topLeftCornerY)-_
step(THIS._width, THIS._height), _
3, _
bf
line (THIS._topLeftCornerX + 1, THIS._topLeftCornerY + 1)-_
step(THIS._width - 2, THIS._height - 2), _
8, _
bf
end if
'
put (THIS._topLeftCornerX + 2, THIS._topLeftCornerY + 2), _
THIS._image, _
PSET
end sub
'-----------------------------------------------------------------
'-----------------------------------------------------------------
'get the desktop size and raise 80% of it as the application screen
dim as integer deskW, deskH
screenInfo deskW, deskH
dim as integer scrW => .8*deskW
dim as integer scrH => .8*deskH
screenRes scrW, scrH, 8, 1, fb.GFX_NO_FRAME
color 12, 8 : cls
'--------------------------------------ML
dim as IMAGEBOX titleBox => IMAGEBOX(.1*scrW, .02*scrH, .8*scrW, .08*scrH)
dim as IMAGEBOX codeBox => IMAGEBOX(.1*scrW, .1*scrH, .8*scrW, .6*scrH)
dim as IMAGEBOX inputBox => IMAGEBOX(.2*scrW, .72*scrH, .7*scrW, .24*scrH)
dim as BUTTON forwardEnigmaSelector => BUTTON(.1*scrW, .7*scrH + 24, 100 - .1*scrW, 24, ">>")
dim as BUTTON backwardEnigmaSelector => BUTTON(.1*scrW, .7*scrH + 54, 100 - .1*scrW, 24, "<<")
dim as integer enigmaIndex => 0
dim as ENIGMA enigmaObject => ENIGMA()
do
if forwardEnigmaSelector._hasMouseClick then
titleBox => IMAGEBOX(.1*scrW, .02*scrH, .8*scrW, .08*scrH)
codeBox => IMAGEBOX(.1*scrW, .1*scrH, .8*scrW, .6*scrH)
inputBox => IMAGEBOX(.2*scrW, .72*scrH, .7*scrW, .24*scrH)
enigmaObject => ENIGMA(1)
end if
if backwardEnigmaSelector._hasMouseClick then
titleBox => IMAGEBOX(.1*scrW, .02*scrH, .8*scrW, .08*scrH)
codeBox => IMAGEBOX(.1*scrW, .1*scrH, .8*scrW, .6*scrH)
inputBox => IMAGEBOX(.2*scrW, .72*scrH, .7*scrW, .24*scrH)
enigmaObject => ENIGMA(0)
end if
'
screenLock()
cls
forwardEnigmaSelector.DrawButton()
backwardEnigmaSelector.DrawButton()
'
put titleBox._image, (2, 4), enigmaObject._titleImage, PSET
put titleBox._image, (2, 20), enigmaObject._instructionImage, PSET
'
for index as integer = 0 to uBound(enigmaObject._codeBlocImage)
dim as integer imgW, imgH
if index>0 then
imageInfo enigmaObject._codeBlocImage(index - 1), imgW, imgH
end if
put codeBox._image, (2, imgH + 2 + index*2), enigmaObject._codeBlocImage(index), PSET
next index
'
for index as integer = 0 to uBound(enigmaObject._userCodeBlocImage)
dim as integer imgW, imgH
if index>0 then
imageInfo enigmaObject._userCodeBlocImage(index - 1), imgW, imgH
end if
put inputBox._image, (2, imgH + 4 + index*2), enigmaObject._userCodeBlocImage(index), PSET
next index
'
titleBox.DrawImageBox()
codeBox.DrawImageBox()
inputBox.DrawImageBox()
screenUnlock()
'
sleep 15
loop until inkey=chr(27)
getKey()
'-----------------------------------------------------------------
'-----------------------------------------------------------------
datasectionLabel:
'E0
data "<startenig>"
data "title - 1 line"
data "instruction - until next section reached or instruction ended"
data "<startenigcod>"
data "<startins>"
data "insertion zoneA - until insertion bloc ended"
data "<endins>"
data "codeA - until next section reached or code bloc ended"
data "<startins>"
data "insertion zoneB - until insertion bloc ended"
data "<endins>"
data "codeB - - until next section reached or code bloc ended"
data "<endenigcod>"
data "ignored - waiting enigma bloc ending"
data "<endenig>"
'E1
data "<startenig>"
data "Enigma #1, force 1 (for the beginning)"
data "Without modifying the code already existing, only insert your own code"
data "one line is sufficient here so that the program works as requested"
data "<startenigcod>"
data "Type UDT Extends Object"
data " Public:"
data " Declare Function checkAddr (Byval pu As Any Ptr) As String"
data " Private:"
data " Declare Operator @ () As Any Ptr"
data " Dim As Any Ptr dummy"
data "End Type"
data "Function UDT.checkAddr (Byval pu As Any Ptr) As String"
data " If pu = Cast(Byte Ptr, @This.dummy) - Offsetof(UDT, dummy) Then"
data " Return ""Good address"""
data " Else"
data " Return ""Bad address"""
data " End If"
data "End Function"
data ""
data "Dim As UDT u"
data "Dim As Any Ptr p"
data "' Other lines of code and allocations may follow here"
data ""
data "'p = @u ' error 201: Illegal member access, UDT.operator.@"
data "'"
data "' Insert below the right code to assign the address of u to p"
data "' so that calling u.checkAddr(p) returns ""Good address"""
data "'--------------------- Begin insertion ----------------------"
data "<startins>"
data ""
data "<endins>"
data "'---------------------- End insertion -----------------------"
data ""
data "Print u.checkAddr(p)"
data ""
data "Sleep"
data "<endenigcod>"
data "<endenig>"
'
'add new enigma data hereafter - see E0 for the requisites...
'
data "<endofdata>" ''very important: data section terminator
'eof-------------------------------------------------------------.