mIRC-tac-toe — File Browser
mIRC-tac-toev2.5 / mIRC-tac-toev2.5 / tic.ini
tic.ini — 10.4 KB — Download this file
[script]
n0=on 1:load: {
n1= %tttver = 2.5
n2= echo 4 -a Now loading mIRC-tac-toe version %tttver by luser
n3= .remote on
n4= .ctcps on
n5= .events on
n6= if ( $script( window.ini ) == $null ) .load -rs window.ini
n7=}
n8=alias tictactoe {
n9= if ( $1 == $null ) {
n10= echo 4 -a You must specify a nickname to challenge
n11= halt
n12= }
n13= if ( $sock(ticlisten).status == listen || $sock(tic) ) {
n14= echo 4 -a You are already playing or waiting for a game to start.
n15= halt
n16= }
n17= :blah
n18= %tport = $r( 500 , 1000 )
n19= if ( $portfree( %tport ) == $false ) goto blah
n20= .ctcp $1 TIC %tttver $longip( $ip ) %tport
n21= echo 4 -a Challenged $1 to mIRC-tac-toe
n22= socklisten ticlisten %tport
n23= %ticnick = $1
n24= .timerTicWait 1 180 .checkTicWaitTimeout
n25= unset %tport
n26=}
n27=alias -l checkTicWaitTimeout {
n28= if ( $sock(ticlisten).status == listening ) {
n29= echo 4 -a mIRC-tac-toe challenge to %ticnick timed out.
n30= sockclose ticlisten
n31= unset %ticnick
n32= }
n33=}
n34=alias -l checkTicYesTimeout {
n35= if ( $sock(tic).sent == 0 || $sock(tic).sent == $null ) {
n36= echo 4 -a %ticnick $+ 's mIRC-tac-toe challenge timed out.
n37= sockclose tic
n38= unset %ticnick
n39= }
n40=}
n41=menu nicklist {
n42= Play mIRC-tac-toe:/tictactoe $1
n43=}
n44=menu query {
n45= Play mIRC-tac-toe:/tictactoe $1
n46=}
n47=ctcp 1:TIC:?:{
n48= if ( $2 != %tttver ) {
n49= echo 4 -a $nick challenged you to mIRC-tac-toe, but has version $2 $+ , not %tttver $+ .
n50= ctcpreply $nick TIC WRONGVERSION %tttver
n51= halt
n52= }
n53= if ( $sock(ticlisten).status == listen || $sock(tic) ) {
n54= ctcpreply $nick TIC BUSY
n55= halt
n56= }
n57= if ( $away == $true ) {
n58= ctcpreply $nick TIC AWAY
n59= halt
n60= }
n61= questionwindow ticyes ticno Yes No $nick has challenged you to mIRC-tac-toe! Will you play?
n62= %ticnick = $nick
n63= %ticip = $longip( $3 )
n64= %ticport = $4
n65=}
n66=on 1:CTCPREPLY:TIC *: {
n67= if ( $2 == YES ) {
n68= echo 4 -a $nick has accepted your challenge!
n69= }
n70= if ( $2 == NO ) {
n71= echo 4 -a $nick has rejected your challenge!
n72= sockclose ticlisten
n73= .timerTicWait off
n74= }
n75= if ( $2 == WRONGVERSION ) {
n76= echo 4 -a $nick has version $3 of mIRC-tac-toe, not verson %ttt
n77= sockclose ticlisten
n78= .timerTicWait off
n79= }
n80= if ( $2 == BUSY ) {
n81= echo 4 -a $nick is already busy in a game of mIRC-tac-toe!
n82= sockclose ticlisten
n83= .timerTicWait off
n84= }
n85= if ( $2 == AWAY ) {
n86= echobs $nick is away, and cannot play mIRC-tac-toe!
n87= sockclose ticlisten
n88= .timerTicWait off
n89= }
n90=}
n91=alias ticyes {
n92= ctcpreply %ticnick TIC YES
n93= echo 4 -a Accepted %ticnick $+ 's challenge.
n94= openticsock
n95= .timerTicYes 1 180 .checkTicYesTimeout
n96=}
n97=alias ticno {
n98= ctcpreply %ticnick TIC NO
n99= echo 4 -a Rejected %ticnick $+ 's challenge.
n100= unset %ticnick %ticip %ticport
n101=}
n102=alias openticsock {
n103= sockopen tic %ticip %ticport
n104=}
n105=on 1:socklisten:ticlisten: {
n106= sockaccept tic
n107= sockclose ticlisten
n108= if ( $r( 1 , 2 ) == 1 ) {
n109= %turn = me }
n110= else {
n111= %turn = him }
n112= openticwindow
n113= sockwrite -n tic 0
n114= sockwrite -n tic 100
n115= if ( %turn == me ) {
n116= tictext Your turn
n117= sockwrite -n tic 2
n118= }
n119= else {
n120= tictext [ %ticnick $+ 's ] turn
n121= sockwrite -n tic 1
n122= }
n123= .timerTicWait off
n124=}
n125=on 1:sockopen:tic: {
n126= openticwindow
n127= sockwrite -n tic 0
n128= .timerTicYes off
n129=}
n130=alias -l ticSendNull sockwrite -n tic 0
n131=alias -l ticCheckTimeout {
n132= if ( %tictimeout < $ctime ) {
n133= closegame
n134= echo 4 -a mIRC-tac-toe game timed out.
n135= }
n136=}
n137=on 1:sockread:tic: {
n138= :next
n139= if ( $sockerr > 0 ) halt
n140= sockread %read
n141= if ( $sockbr == 0 ) goto end
n142=
n143= if ( %lastread == TURN ) {
n144= unset %lastread
n145= if ( %read == 1 ) {
n146= tictext Your turn
n147= %turn = me }
n148= else {
n149= tictext [ %ticnick $+ 's ] turn
n150= %turn = him }
n151= }
n152= if ( %lastread == OPPONENTCLICK ) {
n153= unset %lastread
n154= opponentclicked %read
n155= }
n156= if ( %read == 0 ) {
n157= %tictimeout = $ctime + 60
n158= }
n159= if ( %read == 100 ) {
n160= %lastread = TURN
n161= }
n162= if ( %read == 150 ) {
n163= %lastread = OPPONENTCLICK
n164= }
n165= if ( %read == 200 ) {
n166= echo 4 -a Opponent quit
n167= closegame
n168= halt
n169= }
n170= goto next
n171= :end
n172= unset %read
n173=}
n174=on 1:close:@tic: {
n175= sockwrite -n tic 200
n176= closegame
n177=}
n178=alias -l openticwindow {
n179= %x = $calc( [ $window( -1 ).w ] / 2 - 150 )
n180= %y = $calc( [ $window( -1 ).h ] / 2 - 150 )
n181= window -podf +bnt @tic %x %y 300 300
n182= titlebar @tic tac toe
n183= drawfill @tic 0 0 0 0
n184= drawline @tic 1 2 37 112 264 112
n185= drawline @tic 1 2 37 188 264 188
n186= drawline @tic 1 2 112 37 112 264
n187= drawline @tic 1 2 188 37 188 264
n188= ; set temp file
n189= %ticfile = [ $r( A , Z ) ] $+ [ $r( a , z ) ] $+ [ $r( A , Z ) ] $+ [ $r( a ,z ) ] $+ [ $r( 1000 , 9999 ) ] $+ .tic
n190= settic 9 0
n191= .timerTicCheck 0 30 .ticCheckTimeout
n192= .timerTicSend 0 30 .ticSendNull
n193=}
n194=alias -l closegame {
n195= sockclose tic
n196= window -c @tic
n197= .remove %ticfile
n198= unset %ticfile
n199= .timerTicSend off
n200= .timerTicCheck off
n201=}
n202=menu @tic {
n203= sclick: {
n204= if ( $inrect( $mouse.x , $mouse.y , 37 , 37 , 76 , 76 ) ) ticbox 1
n205= if ( $inrect( $mouse.x , $mouse.y , 112 , 37 , 76 , 76 ) ) ticbox 2
n206= if ( $inrect( $mouse.x , $mouse.y , 188 , 37 , 76 , 76 ) ) ticbox 3
n207= if ( $inrect( $mouse.x , $mouse.y , 37 , 112 , 76 , 76 ) ) ticbox 4
n208= if ( $inrect( $mouse.x , $mouse.y , 112 , 112 , 76 , 76 ) ) ticbox 5
n209= if ( $inrect( $mouse.x , $mouse.y , 188 , 112 , 76 , 76 ) ) ticbox 6
n210= if ( $inrect( $mouse.x , $mouse.y , 37 , 188 , 76 , 76 ) ) ticbox 7
n211= if ( $inrect( $mouse.x , $mouse.y , 112 , 188 , 76 , 76 ) ) ticbox 8
n212= if ( $inrect( $mouse.x , $mouse.y , 188 , 188 , 76 , 76 ) ) ticbox 9
n213= }
n214=}
n215=alias -l ticbox {
n216= if ( %turn == me && $checktic( $1 ) == 0 ) {
n217= settic $1 1
n218= drawmark X $1
n219= sockwrite -n tic 150
n220= sockwrite -n tic $1
n221= if ( $ticWonGame( 1 ) ) {
n222= tictext You won!
n223= %turn = gameOver
n224= halt
n225= }
n226= if ( $ticTied ) halt
n227= %turn = him
n228= tictext [ %ticnick $+ 's ] turn
n229= }
n230=}
n231=alias -l opponentclicked {
n232= if ( %turn == him && $checktic( $1 ) == 0 ) {
n233= settic $1 2
n234= drawmark O $1
n235= if ( $ticWonGame( 2 ) ) {
n236= tictext [ %ticnick ] won!
n237= %turn = gameOver
n238= halt
n239= }
n240= if ( $ticTied ) halt
n241= %turn = me
n242= tictext Your turn
n243= }
n244=}
n245=alias -l drawmark {
n246= %x = $calc( $xcoord( $2 ) + 11 )
n247= %y = $calc( $ycoord( $2 ) + 3 )
n248= drawtext -o @tic 4 Arial 72 %x %y $1
n249=}
n250=alias -l xcoord {
n251= if ( $1 == 1 ) return 37
n252= if ( $1 == 4 ) return 37
n253= if ( $1 == 7 ) return 37
n254= if ( $1 == 2 ) return 113
n255= if ( $1 == 5 ) return 113
n256= if ( $1 == 8 ) return 113
n257= if ( $1 == 3 ) return 189
n258= if ( $1 == 6 ) return 189
n259= if ( $1 == 9 ) return 189
n260= return 0
n261=}
n262=alias -l ycoord {
n263= if ( $1 == 1 ) return 37
n264= if ( $1 == 2 ) return 37
n265= if ( $1 == 3 ) return 37
n266= if ( $1 == 4 ) return 113
n267= if ( $1 == 5 ) return 113
n268= if ( $1 == 6 ) return 113
n269= if ( $1 == 7 ) return 189
n270= if ( $1 == 8 ) return 189
n271= if ( $1 == 9 ) return 189
n272= return 0
n273=}
n274=alias -l tictext {
n275= if ( %lasttext != $null ) {
n276= %w = $calc( 150 - [ $width( %lasttext , Arial , 14 , 0 , 0 ) ] / 2 )
n277= drawtext @tic 0 Arial 14 %w 10 %lasttext
n278= }
n279= %w = $calc( 150 - [ $width( $1- , Arial , 14 , 0 , 0 ) ] / 2 )
n280= drawtext @tic 12 Arial 14 %w 10 $1-
n281= %lasttext = $1-
n282=}
n283=alias -l settic {
n284= if ( $exists( %ticfile ) == $true ) {
n285= bread %ticfile 0 9 &tic
n286= }
n287= bset &tic $1-
n288= bwrite %ticfile 0 9 &tic
n289=}
n290=alias -l checktic {
n291= bread %ticfile 0 9 &tic
n292= return $bvar( &tic , $1 )
n293=}
n294=alias -l ticWonGame {
n295= %t1 = $checktic( 1 )
n296= %t2 = $checktic( 2 )
n297= %t3 = $checktic( 3 )
n298= %t4 = $checktic( 4 )
n299= %t5 = $checktic( 5 )
n300= %t6 = $checktic( 6 )
n301= %t7 = $checktic( 7 )
n302= %t8 = $checktic( 8 )
n303= %t9 = $checktic( 9 )
n304= if ( %t1 == $1 ) {
n305= if ( %t1 == %t2 && %t2 == %t3 ) {
n306= winLine 1 3
n307= return $true
n308= }
n309= if ( %t1 == %t5 && %t5 == %t9 ) {
n310= winLine 1 9
n311= return $true
n312= }
n313= if ( %t1 == %t4 && %t4 == %t7 ) {
n314= winLine 1 7
n315= return $true
n316= }
n317= }
n318= if ( %t5 == $1 ) {
n319= if ( %t4 == %t5 && %t5 == %t6 ) {
n320= winLine 4 6
n321= return $true
n322= }
n323= if ( %t2 == %t5 && %t5 == %t8 ) {
n324= winLine 2 8
n325= return $true
n326= }
n327= if ( %t7 == %t5 && %t5 == %t3 ) {
n328= winLine 7 3
n329= return $true
n330= }
n331= }
n332= if ( %t9 == $1 ) {
n333= if ( %t7 == %t8 && %t8 == %t9 ) {
n334= winLine 7 9
n335= return $true
n336= }
n337= if ( %t3 == %t6 && %t6 == %t9 ) {
n338= winLine 3 9
n339= return $true
n340= }
n341= }
n342= unset %t1 %t2 %t3 %t4 %t5 %t6 %t7 %t8 %t9
n343= return $false
n344=}
n345=alias -l winLine {
n346= drawline @tic 12 8 $xcenter( $1 ) $ycenter( $1 ) $xcenter( $2 ) $ycenter( $2 )
n347=}
n348=alias -l xcenter return $calc( $xcoord( $1 ) + 38 )
n349=alias -l ycenter return $calc( $ycoord( $1 ) + 38 )
n350=alias -l ticTied {
n351= %tici = 0
n352= :next
n353= inc %tici
n354= if ( $checktic( %tici ) == 0 ) return $false
n355= if ( %tici < 9 ) goto next
n356= ticText Game Tied!
n357= %turn = gameOver
n358= return $true
n359=}