For those involved with RC1, here is my old Noughts and Crosses game ported to KiX2k.

This is a fully KiX version with only the scrolling message text coded in VBScript. I will prob remove this later and use @Msecs, but I am waiting (hoping) for @ticks...

This is a new port, please let me know if you find any bugs.


cj

p.s. Be sure to check the user vars at the top, specially $netpath...

code:

break on cls


; HTML Naughts and Crosses
; by cj Version 2.1
; for my lovely Megan


$diff="hard" ; Difficulty level: 'easy' or 'hard'
$netpath="\\server\share" ; UNC path to NETWORK SHARE for inter-program communication
$bDebug=0 ; 1=on, 0=off : shows in command window what subroutines are running
$bVBS=1 ; if, for some reason, the VBScript on the web page doesn't run, set this to 0


;----------------------Do not edit below---------------------------------------------------------------------------------------Do not edit below------------------------------------

setconsole("minimize")

; this is the web page
$html='
<HTML>
<HEAD>
<TITLE>TicTacToe</TITLE>
</HEAD>
<table cellpadding=8><tr><td>
<table border=0 cellspacing=0 cellpadding=0 bgcolor="#ffffdd">
<tr height=0><td width=85> </td><td width=30></td><td width=85> </td><td width=30></td><td width=85> </td></tr>
<tr height=70 align=middle valign=middle>
<td><INPUT id=cmd1 name=1 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd1.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd2 name=2 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd2.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd3 name=3 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd3.name"></td>
</tr>
<tr>
<td colspan=5 bgcolor="#000000" width=200 height=30> </td>
</tr>
<tr height=70 align=middle>
<td><INPUT id=cmd4 name=4 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd4.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd5 name=5 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd5.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd6 name=6 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd6.name"></td>
</tr>
<tr>
<td colspan=5 bgcolor="#000000" width=200 height=30> </td>
</tr>
<tr height=70 align=middle>
<td><INPUT id=cmd7 name=7 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd7.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd8 name=8 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd8.name"></td>
<td bgcolor="#000000"> </td>
<td><INPUT id=cmd9 name=9 type=button value="" style="display=inline; background-color=#ffffdd; border=0; font-size:50; width=70px; height=60px" onClick="status1.value=cmd9.name"></td>
</tr>
</table>
</td></tr></table>
<table border=0>
<tr><td colspan=3 width=100><INPUT readonly id=msg name=msg size=40 style="font-family:monospace; border:none"></td></tr>
<tr>
<td>
<select id=select1 style="width:170px" onChange=status1.value=select1.value>
<option value=a selected>Human Vs CPU</option>
<option value=b>Human Vs Human Local</option>
<option value=c>Join Network Game</option>
<option value=d>Create Network Game</option>
<option value=e>CPU Vs CPU</option>
</select><br>
<INPUT id=Status1 size=1 name=status1 style="display:none" value=a>
HTML <font color=red>Tic</font><font color=green>Tac</font><font color=blue>Toe</font> v2.1 by cj
</td>
<td width=10></td>
<td>
<table border=1 bordercolor="#000000">
<tr>
<td bgcolor="#ffffdd" width=30 align=middle><b>O</b></td>
<td bgcolor="#ffffdd" width=30 align=middle><b>X</b></td>
<td bgcolor="#ffffdd" width=30 align=middle><b>Draw</b></td>
</tr>
<tr>
<td bgcolor="#ffffdd" align=middle><INPUT id=scoreo size=1 readonly style="background-color=#ffffdd; border:none; text-align:center"></td>
<td bgcolor="#ffffdd" align=middle><INPUT id=scorex size=1 readonly style="background-color=#ffffdd; border:none; text-align:center"></td>
<td bgcolor="#ffffdd" align=middle><INPUT id=scored size=1 readonly style="background-color=#ffffdd; border:none; text-align:center"></td>
</tr>
</table>
</td>
</tr>
</table>
</HTML>' ; the web page

if $bVBS $html=$html+'
<script language=vbscript>
dim i, iTimer : iTimer=window.setInterval("Timer()", 100)
sub Timer
msg.value=mid(msg.value, 2)
end sub
</script>
' ; and a tiny bit of VBScript.
endif

; setup vars
dim $score[3] $score[0]=0 $score[1]=0 $score[2]=0 ; starting scores for O, X and Draw
dim $grid[10] ; 9 squares in the grid
dim $check[9]
$check[1]="123" $check[2]="456" $check[3]="789" $check[4]="147" ; 8 possible winning scenarios
$check[5]="258" $check[6]="369" $check[7]="159" $check[8]="357"
$bWin=0 ; this player wins


; more vars that experienced scripters might want to play with
$thinktime=2 ; CPU pretends to take up to this long to "think" - this is a pretty feature and not required.
$balance=10 ; when CPU's score is $balance more than Mans, difficulty level is set to 'easy' and vice versa. Done in Scores
$welcome="@userid's game on @wksta" ; welcome message put into Created games. Has "Welcome to" prepended to it before display
$netfile=$netpath+"\"+@userid+".ttt" ; full filename of file used for created network games
$flash=15 ; number of times to flash the winning line. If you want to run CPU Vs CPU overnight, change this to 1 MINIMUM.


:MAIN ; ..................................................................................................... MAIN PROGRAM
srnd(val(substr(@time, 7, 2))*len(wdayname)+1) ; sort of randomize PRNG

gosub Onames gosub Xnames ; get random names for CPU players
gosub drawgrid ; displays web page and scores

$oldMode=""
$s=$status.value
;$s=olegetproperty($status, "value")
while @error=0
select
case $s="a" $mode="HVC" ; HVC = (starting condition) Human Vs CPU
if $oldMode<>$mode $bReset=0 if $bDebug "Mode changed to Human Vs CPU" ? endif endif
$Oname=@userid ; human
$Xname=$Xpname ; cpu
gosub resetgrid

$game="clear"
gosub NetGame

case $s="b" $mode="HVH" ; HVH = Human Vs Human Local
if $oldMode<>$mode $bReset=0 if $bDebug "Mode changed to Human Vs Human Local" ? endif endif
$Oname=@userid ; human
$Xname=@userid+"'s friend" ; humans friend
gosub resetgrid

$game="clear"
gosub NetGame

case $s="c" $mode="JNG" ; JNG = Join Network Game
if $oldMode<>$mode $bReset=0 if $bDebug "Mode changed to Join Network Game" ? endif endif
$Xname=@userid ; human (you)
gosub resetgrid

case $s="d" $mode="CNG" ; CNG = Create Network Game
if $oldMode<>$mode $bReset=0 if $bDebug "Mode changed to Create Network Game" ? endif endif
$Oname=@userid ; human (you)
gosub resetgrid

case $s="e" $mode="CVC" ; CVC = CPU Vs CPU
if $oldMode<>$mode $bReset=0 if $bDebug "Mode changed to CPU Vs CPU" ? endif endif
$Oname=$Opname ; cpu
$Xname=$Xpname ; cpu
gosub resetgrid

$game="clear"
gosub NetGame

case $s=""

case 1 ; 1..9 = square clicked
$bReset=0
endselect
$oldMode=$mode

; Who plays the turn is based on $who and $mode
select
case $mode="HVC"
if $who="O" gosub man else gosub cpu endif

case $mode="HVH"
gosub man

case $mode="JNG"
$game="join"
gosub NetGame
if $who="X" gosub man else gosub remote endif

case $mode="CNG"
if $who="O" gosub man else gosub remote endif
$game="create"
gosub NetGame

case $mode="CVC"
gosub cpu
endselect
$s=$status.value
;$s=olegetproperty($status, "value")
loop

:bibi
? "Thanks for playing!" ?
quit quit


:man ; ..................................................................................................... MAN +++++++++++
;$s=olegetproperty($status, "value")
$square=val($s) $s=""
if $square<>0
$=execute("$$test=$$cmd$square.value")
;$=execute("$$test=olegetproperty($$cmd$square, 'value')")
if $square>0 and $square<10 and $test=""
if $bDebug "Human chose $square" ? endif

if $mode="CNG" or $mode="JNG" ; Network Game - update file with this move
$game="update"
gosub NetGame
endif

gosub NextPlayer ; Humans turn is done
endif
endif
return


:cpu ; ..................................................................................................... CPU ++++++++++
$text="~$whoname is thinking" gosub WriteMsg
if $thinktime<>0 $t=rnd($thinktime) sleep $t endif ; thinking pause. Set $thinktime=0 to avoid this.
$put=0
select
case $turn<3
gosub EasyRandom ; no strategy, just place a piece
case $turn<4
gosub Block ; try to block then
if $diff="hard" gosub HardRandom endif ; maybe try strategic random placement then
gosub EasyRandom ; no strategy, just place a piece
case 1
gosub Win ; try to win then
gosub Block ; try to block then
if $diff="hard" gosub HardRandom endif ; maybe try strategic random placement then
gosub EasyRandom ; no strategy, just place a piece
endselect
$square=$put
if $bDebug "CPU chose $square" ? endif
gosub NextPlayer ; CPUs turn is done
return


:remote ; ................................................................................................... REMOTE ++++++++++++
$square="0" ; reset square in case of failed return
$game="scan" gosub NetGame ; get turn info from netgame file

if $square<>"0"
if $bDebug "Remote chose $square" ? endif
gosub NextPlayer ; Remote players turn is done
endif
return


:Win ; ................................................................................................... CPU try to win
if $bDebug "Checking for '$who' winning move..." ? endif
$i=1
do
gosub getpattern
select
case $scan="."+$who+$who $put=$p1 if $bDebug "$who wins at $put on pattern $i($p)" ? endif return
case $scan=$who+"."+$who $put=$p2 if $bDebug "$who wins at $put on pattern $i($p)" ? endif return
case $scan=$who+$who+"." $put=$p3 if $bDebug "$who wins at $put on pattern $i($p)" ? endif return
endselect
$i=$i+1
until $i=9
return


:Block ; ................................................................................................... CPU try to block
if $put<>0 return endif
if $bDebug "Trying to block '$you'..." ? endif
$i=1
do
gosub getpattern
select
case $scan="."+$you+$you $put=$p1 if $bDebug "$who blocks $you at $put on pattern $i($p)" ? endif return
case $scan=$you+"."+$you $put=$p2 if $bDebug "$who blocks $you at $put on pattern $i($p)" ? endif return
case $scan=$you+$you+"." $put=$p3 if $bDebug "$who blocks $you at $put on pattern $i($p)" ? endif return
endselect
$i=$i+1
until $i=9
return


:HardRandom ; ................................................................................................ CPU random - hard
if ($diff="easy") or ($put<>0) return endif
if $bDebug "Trying Hard Random..." ? endif
$i=1
do
gosub getpattern
select
case $scan=$you+"."+"." $put=$p2 if $bDebug "Hard random for '$who' at $put on pattern $i($p)" ? endif return
case $scan="."+$you+"." $put=$p3 if $bDebug "Hard random for '$who' at $put on pattern $i($p)" ? endif return
case $scan="."+"."+$you $put=$p2 if $bDebug "Hard random for '$who' at $put on pattern $i($p)" ? endif return
endselect
$i=$i+1
until $i=9
return


:EasyRandom ; .................................................................................................. CPU random
if $put<>0 return endif
do
$put=rnd(8)+1
if $put>9 $put=0 color y+/n "cj RND() bug detected!" ? color w/n endif ; cj RND() bug protection. This is not required in KiX2k.
until $grid[$put]="."
if $bDebug "Easy random for '$who' at $put on pattern $i($p)" ? endif
return


:NextPlayer ;....................................................................................................... Next Player
; Draw char to screen
$=execute('$$cmd$square.value="$who"')
;$=execute("$$=oleputproperty($$cmd$square, 'value', 's', '$who')")

if $who="x"
$=execute('$$cmd$square.style.color=red')
else
$=execute('$$cmd$square.style.color=blue')
endif

$grid[$square]=$who ; store char in grid

gosub Check4Win ; check squares for win condition for this player
if $bWin=0
if $turn=8
gosub gamedraw
else
if $who="O" $who="X" $you="O" $whoname=$Xname else $who="O" $you="X" $whoname=$Oname endif ; next player
$turn=$turn+1
$text="~$whoname's turn" gosub WriteMsg ; next players turn message
; $status.value="" ; reset status
; $=oleputproperty($status, "value", "s", "") ; reset status
endif
endif
$bWin=0
if $bDebug ? "Turn: $turn - '$who'" ? endif
return


:drawgrid ;....................................................................................................... Draw grid
; create HTML file
$=redirectoutput("%temp%\3t.htm", 1) $html $=redirectoutput("")
; open IE
$ie=createobject("internetexplorer.application")
;$ie=olecreateobject("internetexplorer.application")

; Set properties and display form ...
$ie.addressbar="0"
$ie.menubar="0"
$ie.toolbar="0"
$ie.statusbar="0"
$ie.resizable="0"
$ie.height=440
$ie.width=380
$ie.visible="true"
;$=oleputproperty($ie, "addressbar","s","0")
;$=oleputproperty($ie, "menubar", "s", "0")
;$=oleputproperty($ie, "toolbar", "s", "0")
;$=oleputproperty($ie, "statusbar", "s", "0")
;$=oleputproperty($ie, "resizable", "s", "0")
;$=oleputproperty($ie, "height", "s", "440")
;$=oleputproperty($ie, "width", "s", "380")
;$=oleputproperty($ie, "visible", "s", "-1")
; open HTML file

$ie.navigate("%temp%\3t.htm") while $ie.busy<>0 and @error=0 loop
;$=olecallfunc($ie, "navigate", "s", "%temp%\3t.htm") while olegetproperty($ie, "busy") <> "0" and @error = 0 loop
$doc=$ie.document
;$doc=val("&" + olegetproperty($ie, "document"))

; set focus on web page
while setfocus("TicTacToe - Microsoft Internet Explorer")<>0 loop

; get web page element IDs
$i=1
do
$=execute("$$cmd$i=$$doc.GetElementById('cmd$i')")
; $=execute("$$cmd$i=val('&' + olecallfunc($doc, 'GetElementById', 's', 'cmd$i'))")
$i=$i+1
until $i=10
$status=$doc.GetElementById("status1")
;$status=val("&" + olecallfunc($doc, "GetElementById", "s", "status1"))

$message=$doc.GetElementById("msg")
;$message=val("&" + olecallfunc($doc, "GetElementById", "s", "msg"))
$scoreO=$doc.GetElementById("scoreo")
;$scoreO=val("&" + olecallfunc($doc, "GetElementById", "s", "scoreo"))
$scoreX=$doc.GetElementById("scorex")
;$scoreX=val("&" + olecallfunc($doc, "GetElementById", "s", "scorex"))
$scoreD=$doc.GetElementById("scored")
;$scoreD=val("&" + olecallfunc($doc, "GetElementById", "s", "scored"))


:scores ;....................................................................................................... Scores
; update HTML score display
$scoreO.value=$score[0] ; $=oleputproperty($scoreO, "value", "s", "$oScore") ; O's
$scorex.value=$score[1] ; $=oleputproperty($scoreX, "value", "s", "$xScore") ; X's
$scoreD.value=$score[2] ; $=oleputproperty($scoreD, "value", "s", "$dScore") ; Draw

; difficulty level change
if $mode="HVC" or $mode="CVC"
if ($score[0]-$score[1])>$balance $diff="hard" endif
if ($score[1]-$score[0])>$balance $diff="easy" endif
; "Difficulty level set to $diff" ?
endif
return


:resetgrid ;******************************************************************************************************** Reset Grid
if $bReset return endif ; prevents multiple resets
if $bDebug color w+/n "Reset grid." color w/n ? endif

; reset page
$i=1
do
$=execute("$$cmd$i.value=''") ; clear all squares
; $=execute("$$=oleputproperty($$cmd$i, 'value', 's', '')")
$grid[$i]="." ; clear grid
$i=$i+1
until $i=10

; reset vars
$who="O" ; Who starts = O always
$whoname=$Oname ; their name
$you="X" ; the opponent
$turn=0 ; what turn number or how many pieces have been played

; Reset message box
$text="~$whoname's turn" gosub WriteMsg
$bReset=1 $oldMode=""
if $bDebug ? "$who's turn: $turn" ? endif
return


:Xnames ;....................................................................................................... Xnames
$a=rnd(10)
select
case $a=0 $Xpname="Uncanny X-man"
case $a=1 $Xpname="Your pappa"
case $a=2 $Xpname="eXcited"
case $a=3 $Xpname="Mr X"
case $a=4 $Xpname="Miss X"
case $a=5 $Xpname="X family"
case $a=6 $Xpname="cj"
case $a=7 $Xpname="@wksta"
case $a=8 $Xpname="HAL9000"
case $a=9 $Xpname="@userid's computer"
case 1 $Xpname="cj RND(X) bug"
endselect
return


:Onames ;....................................................................................................... Onames
$a=rnd(10)
select
case $a=0 $Opname="The Big O"
case $a=1 $Opname="O' meister"
case $a=2 $Opname="Roundie"
case $a=3 $Opname="The Fatman"
case $a=4 $Opname="Orange"
case $a=5 $Opname="Zero"
case $a=6 $Opname="Oh my gosh"
case $a=7 $Opname="Ballface"
case $a=8 $Opname="Your mamma"
case $a=9 $Opname="Little o"
case 1 $Opname="cj RND(O) bug"
endselect
return


:WriteMsg ;....................................................................................................... write message
select
case substr($text, 1, 1)="~" ; resets message
$message.value="" ; clear message box
; $=oleputproperty($message, "value", "s", "")
$text=substr($text, 2, len($text)-1) ; strip ~

case substr($text, 1, 1)="^" ; message waits until clear before writing, use for looping messages to avoid overloading
if $message.value<>"" return endif ; will not write message if there is text there. try again later
; if olegetproperty($message, "value")<>"" return endif
$text=substr($text, 2, len($text)-1) ; strip ^

case 1
endselect
if $bDebug color w+/n "Message: " color w/n $text ? endif
if $bVBS $currenttext=$message.value $text=$currenttext+" "+$text+"....." endif
;if $bVBS $text=olegetproperty($message, "value")+" "+$text+"....." endif
$message.value=$text
;$=oleputproperty($message, "value", "s", "$text")
return


:Check4Win ;....................................................................................................... Check for win
if $bDebug "Checking for win..." ? endif
$i=1
do
gosub GetPattern
if $scan=$who+$who+$who goto winner endif
$i=$i+1
until $i=9
return

:winner

$text="~$whoname wins!" gosub WriteMsg
if $who="O" $zScore=$score[0] $score[0]=$zScore+1 else $zScore=$score[1] $score[1]=$zScore+1 endif
gosub scores ; update player scores

; flash the winning line
$j=0
do
$i=1
do
$=execute("$$square=substr($$p,$i,1)")
$=execute("$$cmd$square.value=''")
; $=execute("$$=oleputproperty($$cmd$square, 'value', 's', '')")
$=execute('$$cmd$square.value="$who"')
; $=execute("$$=oleputproperty($$cmd$square, 'value', 's', '$who')")
$i=$i+1
until $i=4
$j=$j+1
until $j=$flash
if $mode="CNG" $=writeprofilestring($netfile, "turn", "who", "") endif ; Creator resets game

$bReset=0 ; this will trigger a reset grid
gosub resetgrid

$bWin=1 ; this Check for Win was successful
$status.value="" ; clear status to prevent 'cached clicks'
;$=oleputproperty($status, "value", "s", "")
return


:gamedraw ;....................................................................................................... Draw - no winner
$text="~It's a draw!" gosub WriteMsg
$score[2]=$score[2]+1 gosub scores ; update draw scores
if $thinktime<>0 sleep 4 endif
if $mode="CNG" $=writeprofilestring($netfile, "turn", "who", "") endif ; Creator resets game

$bReset=0 ; this will trigger a reset grid
gosub resetgrid

$status.value="" ; clear status to prevent 'cached clicks'
;$=oleputproperty($status, "value", "s", "") ; clear status to prevent 'cached clicks'
return


:GetPattern ;....................................................................................................... grid search pattern
$p=$check[$i]
$p1=substr($p,1,1)
$p2=substr($p,2,1)
$p3=substr($p,3,1)
$scan=$grid[$p1]+$grid[$p2]+$grid[$p3]
return


:NetGame ;....................................................................................................... Network Game code
if $bDebug
if $oldGame<>$game "NetGame($game)" ? endif
$oldGame=$game
endif
select
case $game="create" ;........................................................................................... Create
if $bGame=0 ; Create game file...
if $bDebug "Creating NetFile..." ? endif
del $netfile
$=writeprofilestring($netfile, "players", "number", "1")
$=writeprofilestring($netfile, "players", "oname", $Oname)
$=writeprofilestring($netfile, "players", "welcome", $welcome)
$text="~Game created, waiting for player to join" gosub WriteMsg
if $bDebug "Created NetFile..." ? endif
$bGame=1 $bJoin=0
else ; Scan game file for player joined...
if $bJoin=0
sleep 1 ; pause so that file is not pummelled
$filethere=getfileattr($netfile)
if @error<>0
if $bDebug color r+/n "NetFile access failed with Error @error :" ? "@serror" ? color w/n endif
$text="~Game file was not found" gosub WriteMsg
$mode="" $oldMode="" ; reset mode so that nothing happens until user clicks list on web page
$status.value="" ; clear status to prevent instant re-create net game
;$=oleputproperty($status, "value", "s", "")
$bGame=0 ; reset game flag
else
if $bDebug "Checking NetFile for players..." ? endif
if readprofilestring($netfile, "players", "number")="2" ; player has joined
$bJoin=1
$Xname="Remote: "+readprofilestring($netfile, "players", "xname")
$text="~$Xname joined your game" gosub WriteMsg
if $bDebug "$Xname has joined your game..." ? endif
$status.value="" ; reset creators' impatient button presses
;$=oleputproperty($status, "value", "s", "")
endif
endif
else ; player present check
if readprofilestring($netfile, "players", "number")="1" ; joined player left your game
$bJoin=0
$bGame=0
$mode="" $oldMode="" ; turn this line OFF to prevent new game re-start
if $mode="" del $netfile endif ; delete aborted game file
$bReset=0
gosub resetgrid
$text="~Player left your game, game aborted" gosub WriteMsg
$square="0"
$status.value="" ; clear status
;$=oleputproperty($status, "value", "s", "")
return
endif
endif
endif

case $game="join" ;........................................................................................... Join
if $bJoin=0 ; not joined yet, look for file
; $dlgnet=0
$dlgNet=createobject("MSComDlg.CommonDialog") ; access MS Common Dialog collection
;$dlgNet=olecreateobject("MSComDlg.CommonDialog")
if $dlgNet=0
color r+/n "You cannot access the MSComDlg.CommonDialog Object!" color w/n
$netfile=""
do
? "Enter the full path to the Network Game File or press ENTER to cancel." ? ">"
gets $netfile
if $netfile<>""
$=getfileattr($netfile)
if @error<>0
? color y+/n "Error @error : @serror" color w/n ?
endif
else
$mode="" $oldMode=""
$status.value="" ; clear status
;$=oleputproperty($status, "value", "s", "") ; clear status
return
endif
until $netfile<>""
else ; use Dialog box
$dlgNet.Filter="HTML TicTacToe Game Files|*.ttt"
;$=oleputproperty($dlgNet, "Filter", "s", "HTML TicTacToe Game Files|*.ttt")
$dlgNet.FilterIndex=3
;$=oleputproperty($dlgNet, "FilterIndex", "s", "3")
$dlgNet.Filename=$netpath+"\*.ttt" ; look for all .ttt files in $netpath
;$=oleputproperty($dlgNet, "Filename", "s", $netpath+"\*.ttt")
$dlgNet.DialogTitle="Connect to Network Game"
;$=oleputproperty($dlgNet, "DialogTitle", "s", "Connect to Network Game")
$dlgNet.MaxFileSize=128
;$=oleputproperty($dlgNet, "MaxFileSize", "s", "128")
$dlgNet.ShowOpen() ; show the FILE OPEN dialog
;$=olecallfunc($dlgNet, "ShowOpen")
$netfile=$dlgNet.filename
;$netfile=olegetproperty($dlgNet, "filename")
endif
if $bDebug "NetPath: $netpath" ? "Net File: '$netfile'" ? endif
if ($netfile=$netpath+"\*.ttt") or ($netfile=$netpath+"\") or ($netfile="\") ; cancelled dialog box
if $bDebug "Cancelled join netgame" ? endif
$status.value="" ; clear status
;$=oleputproperty($status, "value", "s", "") ; clear status
$mode="" $oldMode=""
return
else
$players=readprofilestring($netfile, "players", "number")
select
case $players="2" $text="~This game is full" gosub WriteMsg

case $players="1"
$text="~Welcome to "+readprofilestring($netfile, "players", "welcome") gosub WriteMsg
$Oname="Remote: "+readprofilestring($netfile, "players", "oname") ; read o players name
$=writeprofilestring($netfile, "players", "xname", $Xname) ; write x players name for o player to read
$=writeprofilestring($netfile, "players", "number", "2") ; update net file with my presence
$bJoin=1

case 1 $text="~An unknown error occurred, you cannot join this game" gosub WriteMsg
endselect
endif
else ; in game, check that creator did not quit
$players=readprofilestring($netfile, "players", "number")
if $players="1"
$bJoin=0
$bGame=0
$mode="" $oldMode="" ; turn this line OFF to prevent new game re-start
if $mode="" del $netfile endif ; delete aborted game file
$bReset=0
gosub resetgrid
$text="~Creator has left, game aborted" gosub WriteMsg
$square="0"
$status.value="" ; clear status
;$=oleputproperty($status, "value", "s", "") ; clear status
endif
endif

case $game="scan" ;........................................................................................... Scan
if $bJoin=1
if $bDebug "Scanning file for $who's move" ? endif
sleep 1 ; pause so that file is not pummelled
$filethere=getfileattr($netfile)
if @error<>0
if $bDebug color r+/n "NetFile access failed with Error @error :" ? "@serror" ? color w/n endif
$bJoin=0
$bReset=0
$mode="" $oldMode=""
return
else
if $bGame=1 and readprofilestring($netfile, "players", "number")="1" ; joined player left your game
$bJoin=0
$bGame=0
$mode="" $oldMode="" ; turn this line OFF to prevent new game re-start
if $mode="" del $netfile endif ; delete aborted game file
$bReset=0
gosub resetgrid
$text="~Player left your game, game aborted" gosub WriteMsg
$square="0"
$status.value="" ; clear status
;$=oleputproperty($status, "value", "s", "") ; clear status
return
endif

; get square number if it is $who's turn
if readprofilestring($netfile, "turn", "who")=$who $square=readprofilestring($netfile, "turn", "square") endif
endif
endif

case $game="update" ;........................................................................................... Update
if $bJoin
if $bDebug "Updating file with $who's move" ? endif
sleep 1 ; pause so that file is not pummelled
$filethere=getfileattr($netfile)
if @error<>0
if $bDebug color r+/n "NetFile access failed with Error @error :" ? "@serror" ? color w/n endif
$bJoin=0
$bReset=0
$mode="" $oldMode=""
return
else
$=writeprofilestring($netfile, "turn", "square", "$square")
$=writeprofilestring($netfile, "turn", "who", $who) ; write $who last JIC other player is reading the file now
endif
endif

case $game="clear" ;........................................................................................... Clear
; clear filename
; del $netfile
if $bJoin
$=writeprofilestring($netfile, "players", "number", "1") ; if joined, quit and tell creator that you are gone.
endif

$bGame=0
$bJoin=0


endselect

return