FOR nCol := 1 to 9
WITH OBJECT oBrw:aCols[ nCol ]
:lAllowSizing := .F.
END
NEXT
Function Main()
Local odlg
Local aSudoku := { { 0, 0, 0, 2, 0, 3, 8, 0, 1 }, ;
{ 0, 0, 0, 7, 0, 6, 0, 5, 2 }, ;
{ 2, 0, 0, 0, 0, 0, 0, 7, 9 }, ;
{ 0, 2, 0, 1, 5, 7, 9, 3, 4 }, ;
{ 0, 0, 3, 0, 0, 0, 1, 0, 0 }, ;
{ 9, 1, 7, 3, 8, 4, 0, 2, 0 }, ;
{ 1, 8, 0, 0, 0, 0, 0, 0, 6 }, ;
{ 7, 3, 0, 6, 0, 1, 0, 0, 0 }, ;
{ 6, 0, 5, 8, 0, 9, 0, 0, 0 } }
DEFINE DIALOG oDlg SIZE 81*5,81*5;
COLOR CLR_BLACK,CLR_WHITE
@ 1,1 XBROWSE oBrw OF oDlg array aSudoku ;
LINES CELL cols{ 1,2,3,4,5,6,7,8,9 } ;
HEADER "1", "2", "3", "4","5","6","7","8","9" ;
COLSIZES 25,25,25,25,25,25,25,25,25 ;
SIZE 140,100 NOBORDER
Ut_BrwRowConfig( oBrw )
oBrw:CreateFromCode()
aeval( oBrw:aCols, { |oCols| oCols:nEditType := EDIT_GET } )
ACTIVATE DIALOG oDlg
RETURN NIL
FUNCTION Ut_BrwRowConfig( oBrw )
oBrw:lRecordSelector := .F. // .t.
oBrw:lAllowRowSizing := .F.
oBrw:lColDividerComplete := .t. // .f.
oBrw:lAllowColSwapping := .f.
oBrw:lAllowColHiding := .f.
oBrw:lFastEdit := .f.
oBrw:nRowSel := 1
oBrw:nColSel := 1
oBrw:nColOffset := 1
oBrw:nFreeze := 0
oBrw:nCaptured := 0
oBrw:nLastEditCol := 0
oBrw:nStretchCol := -1
oBrw:lRecordSelector := .F.
oBrw:lHScroll := .F.
oBrw:lVScroll := .F.
oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY // LINESTYLE_NOLINES
* oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW // MARQSTYLE_SOLIDCELL
oBrw:lheader:=.f.
RETURN nil
#include "FiveWin.ch"
#include "xbrowse.ch"
FUNCTION MAIN()
Local odlg, oSay[9]
Local aSudoku := { { " ", " ", " ", "2", " ", "3", "8", " ", "1" }, ;
{ " ", " ", " ", "7", " ", "6", " ", "5", "2" }, ;
{ "2", " ", " ", " ", " ", " ", " ", "7", "9" }, ;
{ " ", "2", " ", "1", "5", "7", "9", "3", "4" }, ;
{ " ", " ", "3", " ", " ", " ", "1", " ", " " }, ;
{ "9", "1", "7", "3", "8", "4", " ", "2", " " }, ;
{ "1", "8", " ", " ", " ", " ", " ", " ", "6" }, ;
{ "7", "3", " ", "6", " ", "1", " ", " ", " " }, ;
{ "6", " ", "5", "8", " ", "9", " ", " ", " " } }
Local aPrompt := { " a", " b", " c", " d", " e", " f", " g", " h", " i" }
DEFINE DIALOG oDlg SIZE 81*5,81*5;
COLOR CLR_BLACK,CLR_WHITE PIXEL
I := 1
nRow := 20
FOR I := 1 TO 9
@ nRow, 8 SAY oSay[I] PROMPT aPrompt[I] SIZE 12, 9 COLOR 0, 16772055 PIXEL
nRow := nRow +9
NEXT
@ 10, 20 XBROWSE oBrw OF oDlg ARRAY aSudoku ;
LINES CELL cols{ 1,2,3,4,5,6,7,8,9 } ;
HEADER "1", "2", "3", "4","5","6", "7","8","9" ;
COLSIZES 25, 25, 25, 25, 25, 25, 25, 25, 25, 25 ;
SIZE 125, 91 NOBORDER PIXEL
oBrw:bLClicked := { | nRow, nCol | C_ACTION( aSudoku, oBrw:KeyNo(), oBrw:SelectedCol():nCreationOrder, aPrompt ) }
Ut_BrwRowConfig( oBrw )
oBrw:CreateFromCode()
aeval( oBrw:aCols, { |oCols| oCols:nEditType := EDIT_GET, ;
oCols:lAllowSizing := .F., ;
oCols:nDataStrAlign := AL_CENTER } )
ACTIVATE DIALOG oDlg
RETURN NIL
// ---------
FUNCTION C_ACTION(aSudoku, nRPos, nCPos, aPrompt)
IF EMPTY( aSudoku[nRPos][nCPos] )
MsgAlert( "Row : " + aPrompt[nRPos] + CRLF + ;
"Col : " + ALLTRIM(STR(nCPos)), "Position" )
ENDIF
RETURN(NIL)
// ------
FUNCTION Ut_BrwRowConfig( oBrw )
oBrw:lRecordSelector := .F. // .t.
oBrw:lAllowRowSizing := .F.
oBrw:lColDividerComplete := .t. // .f.
oBrw:lAllowColSwapping := .f.
oBrw:lAllowColHiding := .f.
oBrw:lFastEdit := .f.
oBrw:nRowSel := 1
oBrw:nColSel := 1
oBrw:nColOffset := 1
oBrw:nFreeze := 0
oBrw:nCaptured := 0
oBrw:nLastEditCol := 0
oBrw:nStretchCol := -1
oBrw:lRecordSelector := .F.
oBrw:lHScroll := .F.
oBrw:lVScroll := .F.
oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY // LINESTYLE_NOLINES
* oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW // MARQSTYLE_SOLIDCELL
oBrw:lheader :=.t.
RETURN nil
Function SudokuLoad(nLevel)
Local aLoadstring:= Load_File_Sudoku(nLevel)
Local nConteggioSudoku:=Len(aLoadstring)
Local nSudoku:= nRandom(nConteggioSudoku-1)+1
Local nBlocchi,nCelle ,nGet:= 0
Local cSudoku:= alltrim(aLoadstring[nSudoku])
Local atest:= {}
Local anumeri := {}
Local cNumeri:=""
Local nNumero:= 0
local arows:= {}
local acols:= {}
Local ncol:= 0
For nBlocchi=1 to 9
For nCelle=1 to 9
ncol+= 1
nNumero+=1
If alltrim(StrChar( cSudoku, nNumero ))=="0"
cStringa:=" "
else
cStringa:=alltrim(StrChar( cSudoku, nNumero))
endif
aadd( acols, cStringa)
IF nCol== 9
aadd( arows, {acols[1],;
acols[2],;
acols[3],;
acols[4],;
acols[5],;
aCols[6],;
acols[7],;
aCols[8],;
aCols[9]} )
nCol:= 0
acols:= {}
endif
next
next
return arows
Function Load_File_Sudoku(nLevel)
Local cPathdata:=".\data\"
Local cFile:=cPathdata+"level"+alltrim(str(nLevel))+".txt"
Local aTest := {}
Local n
Local oText
oText:= TTxtFile():New( cFile )
FOR n = 1 to oText:RecCount()
AADD( aTest, oText:ReadLine() )
// MsgAlert( aTest[n], "Array-line : " + ALLTRIM(STR(n)) )
oText:Skip()
NEXT
oText:Close()
Return atest
//Project sudoku with xbrowse
#include "Fivewin.ch"
#include "Xbrowse.ch"
Static oSquare
Static aData
Static aSudoku
Static aOriginal
static oSayText1
static cMessage
FUNCTION MAIN()
Local odlg, oSay[9]
Local aPrompt := { "a", "b", "c", "d", "e", "f", "g", "h", "i" }
Local oFontSquare
cMessage :="MESSAGE"
aData:= {}
aSudoku := SudokuLoad(1) //nLevl1
aOriginal:= aSudoku
//create the aData
For n=1 to 9
aadd( aData,{aprompt[n],aSudoku[1][n],;
aSudoku[2][n],;
aSudoku[3][n],;
aSudoku[4][n],;
aSudoku[5][n],;
aSudoku[6][n],;
aSudoku[7][n],;
aSudoku[8][n],;
aSudoku[9][n],;
})
next
DEFINE FONT oFontSquare NAME "Ms Sans Serif" SIZE 0, -22
DEFINE DIALOG oDlg SIZE 81*5,81*5;
COLOR CLR_BLACK,CLR_WHITE PIXEL ;
Title "Sudoku with Xbrowse"
@ 10, 20 XBROWSE oSquare OF oDlg ARRAY aData ;
LINES CELL cols{ 1,2,3,4,5,6,7,8,9,10 } ;
HEADER "","1", "2", "3", "4","5","6", "7","8","9" ;
COLSIZES 25,30, 30, 30, 30, 30, 30, 30, 30, 30, 30 ;
SIZE 156,156 NOBORDER PIXEL FONT oFontSquare
@ 180,10 say oSayText1 Prompt cMessage OF oDlg size 150,10 PIXEL TRANSPARENT update
oSquare:aCols[ 1 ]:bClrStd = { || { , 15195087 } }
oSquare:aCols[1]:nDataStrAlign := AL_CENTER
For n= 2 to 10
oSquare:aCols[n]:bClrstd := {|| { 0, SudokuBackColor() } }
oSquare:aCols[n]:nDataStrAlign := AL_CENTER
oSquare:aCols[n]:lAllowSizing := .F.
oSquare:aCols[n]:nEditType := EDIT_GET
next
*oSquare:bLClicked := { | nRow, nCol | C_ACTION(oSquare, aSudoku, oSquare:KeyNo(), oSquare:SelectedCol():nCreationOrder, aPrompt ) }
Ut_BrwRowConfig( oSquare )
oSquare:bchange := { || oSayText1:SetText(WichNumber(aOriginal,aData)) }
oSquare:CreateFromCode()
ACTIVATE DIALOG oDlg
RETURN NIL
Function Colore_Grid()
Local nColor
Local nCol:= oSquare:SelectedCol():nCreationOrder
Do case
case nCol <= 3
Do case
case oSquare:KeyNo() <=3
nColor:= CLR_HCYAN
case oSquare:KeyNo() > 3 .and. oSquare:KeyNo() <=6
nColor := CLR_YELLOW
case oSquare:KeyNo() >6
nColor := CLR_HGRAY
Endcase
case nCol > 3 .and. nCol <= 6
Do case
case oSquare:KeyNo() <=3
nColor:= CLR_YELLOW
case oSquare:KeyNo() > 3 .and. oSquare:KeyNo() <=6
nColor := CLR_HRED
case oSquare:KeyNo() >6
nColor := CLR_HCYAN
Endcase
case nCol > 6
Do case
case oSquare:KeyNo() <=3
nColor:= CLR_HCYAN
case oSquare:KeyNo() > 3 .and. oSquare:KeyNo() <=6
nColor := CLR_YELLOW
case oSquare:KeyNo() >6
nColor := CLR_HGRAY
Endcase
Endcase
return nColor
function SudokuBackColor()
local rowindex := oSquare:KeyNo()
local colindex := oSquare:SelectedCol():nCreationOrder
do case
case rowindex <= 3 // first row
do case
case colindex <= 3 // first col
return CLR_HCYAN
case colindex > 3 .and. colindex <= 6 // second col
return CLR_YELLOW
case colindex > 6 // third col
return CLR_HCYAN
endcase
case rowindex > 3 .and. rowindex <= 6 // second row
do case
case colindex <= 3 // first col
return CLR_HCYAN
case colindex > 3 .and. colindex <= 6 // second col
return CLR_YELLOW
case colindex > 6 // third col
return CLR_HCYAN
endcase
case rowindex > 6 // third row
do case
case colindex <= 3 // first col
return CLR_YELLOW
case colindex > 3 .and. colindex <= 6 // second col
return CLR_HCYAN
case colindex > 6 // third col
return CLR_HCYAN
endcase
endcase
FOR n := 1 TO LEN(oSquare:aCols)
WITH OBJECT oSquare:aCols[ n ]
:nEditType := EDIT_GET
:lAllowSizing := .F.
:nDataStrAlign := AL_CENTER
:nHeadStrAlign := AL_CENTER
IF n < 4
oSquare:aCols[n]:bClrstd := {|| { 255, IIF( oSquare:KeyNo() > 3 .and. ;
oSquare:KeyNo() < 7, 16768185, 16772572 ) } }
ELSEIF n > 3 .and. n < 7
oSquare:aCols[n]:bClrstd := {|| { 255, IIF( oSquare:KeyNo() > 3 .and. ;
oSquare:KeyNo() < 7, 16772572, 16768185 ) } }
ELSEIF n > 6
oSquare:aCols[n]:bClrstd := {|| { 255, IIF( oSquare:KeyNo() > 3 .and. ;
oSquare:KeyNo() < 7, 16768185, 16772572 ) } }
ENDIF
END
NEXT
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 52 guests