require "common"
-------------------------------------------------------------------------------
--  initialization
-------------------------------------------------------------------------------
local objLetterTemplate = obj( "letterTemplate" )
local objLetters = obj( "letters" )
delObjects( children( objLetters ) )
set ( "Hint", "enabled", "false")
randSeed()
set ( "btnAnswer", "enabled", "false")
function randChar()
    local c_nLetters = 26
    return string.char( math.random( c_nLetters ) + string.byte( "A" ) - 1 )
end

local cMainCh = randChar()
for i = 0, 9 do
    for j = 0, 9 do
        wait ( 0.1 )
        local objLetter = create( objLetterTemplate, "l" .. i .. j, objLetters )
        set( objLetter, "visible", "true" )
        local n = 100 - (9 - i)*10 - (9 - j) - 1
        if (n == (i + 1)*10 - i - 1) then
            set( objLetter, "text", cMainCh )
        else
            local ch = randChar()
            set( objLetter, "text", ch )
        end
    end   
end
set( "lblAnswerLetter", "text", "''" .. cMainCh .. "''" )
set ( "btnAnswer", "enabled", "true")
set( "lettersBG", "visible", "true" )

function OnHideLetters()
    for i = 9, 0, -1 do
        for j = 9, 0, -1 do
            wait ( 0.1 )
            local objLetter = obj( "l" .. i .. j, objLetters )
            delete( objLetter )
        end   
    end
end

while true do
    wait( 0.5 )
end
