Hi Inna,
> do any of you guys had experience of making a game like tic
> tac toe in
> lingo?
I did :)
> I am having problem checking the winner in the diagonal form.
> Anybody can
> help me put of this misery? :) I really appreciate it if you do...
I wrote an Array parent script (based on Tab Julius's Array in his "Lingo!"
book - Thanks Tab), and part of the script is parsing the array in a
vertical, horizontal and diagonal spreads. I don't have time to distill it
now, but here's the whole script. The bit you want to look at is the "on
getDiagonal me, dir" handler. "dir" can be #left or #right and represents
the left and right diagonals.
I hope you get what you need from it.
Here's the Parent script:
property plArray, piRows, piCols, piTotalCells
on new me, rows, cols
-- put "I'm an Array Object"
piRows=rows
piCols=cols
pitotalCells= rows*cols
plArray= []
plArray.addAt(piTotalCells, 0)
return me
end
on cell me, row, col
cCellLoc=((row-1) * piCols) + col
return cCellLoc
end
on setCell me, row, col, vCellValue
plArray[me.cell(row, col)]=vCellValue
end
on setCellLoc me, cCellLoc, vCellValue
plArray[cCellLoc]=vCellValue
end
on getCellLoc me, cCellLoc
return plArray[cCellLoc]
end
on getCell me, row, col
vCellValue=plArray[me.cell(row, col)]
return vCellValue
end
on setAll me, vCellValue
repeat with i = 1 to piTotalCells
plArray[i]= vCellValue
end repeat
end
on dump me
repeat with row = 1 to piRows
qThisRow=row && "--"
repeat with col = 1 to piCols
qThisRow=qThisRow&& me.getCell(row, col)
end repeat
put qThisRow
end repeat
end
on getMaxCells me
return piTotalCells
end
on getNumRows me
return piRows
end
on getNumCols me
return piCols
end
--return a list of items in the given row
on getRow me, row
rowlist=[]
repeat with iC = 1 to piCols
rowlist.append (me.getCell(row, iC))
end repeat
return rowlist
end
--return a list of items in the given colum
on getCol me, col
collist = []
repeat with i = 1 to piRows
collist.append (me.getCell(i, col))
end repeat
return collist
end
--return a list of items in the given diagonal (going right or left)
on getDiagonal me, dir
diaglist=[]
diagcells=[]
case dir of
#right:
iR=1
dir=1
#left:
iR=piRows
dir=-1
end case
repeat with iC =1 to piCols
if iC > piRows then
exit repeat
else
diaglist.append(me.getCell(iR, iC))
diagcells.append (me.cell(iR, iC))
iR=iR+dir
end if
end repeat
return [diaglist, diagcells]
end
on getArray me
return plArray.duplicate()
end
on cleanup me
plArray=[]
return 0
end
Karina
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]