Administrators chain Posted February 9, 2010 Administrators Report Share Posted February 9, 2010 This is a version of Connect 4 that me and Kylar coded.. I coded most of the networking and he coded most of the graphics.. It was both of our first collaborated scripts.. To start a game, right click on someone's name in a channel, and click Connect4.. If they have the script, they will get a popup asking if they want to play or not. If they don't have it, the script will automatically halt the connection after 10 seconds.. Enjoy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; Connect 4: By Imk0tter & Kylar ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; menu Nicklist { Connect4:Connect4::SendRequest $1 } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Open Handeling ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ctcp 1:CONNECT4.REQUEST*:*: { .timer 1 0 Connect4::ReceiveRequest $nick $ctime } ctcp 1:CONNECT4.REJECT*:*: { .timer 1 0 Connect4::RequestFailed $nick .timerCONNECT4.REQUEST. $+ $nick off } ctcp 1:CONNECT4.ACCEPT*:*: { if ($timer(CONNECT4.REQUEST. $+ $nick)) { .timerCONNECT4.REQUEST. $+ $nick off var %id $Connect4::UnusedID sockopen %id $2 $3 } } alias Connect4::SendRequest { ctcp $1 CONNECT4.REQUEST .timerCONNECT4.REQUEST. $+ $1 1 10 Connect4::RequestFailed $1 } alias Connect4::RequestFailed { var %x $input($1 denied your Connect4 request,o) } alias Connect4::ReceiveRequest { var %request $input(Would you like to start a Connect4 game with $1?,y) if (%request && $calc($ctime - $2) 5) || (%piece == 2 && $hget(%id,Client) == $hget(%id,Turn)) { return $false } var %pos $calc(%y * 7 + %x + 1) hadd -m %id pieces $left(%pieces,$calc(%pos - 1)) $+ %piece $+ $mid(%pieces,$calc(%pos + 1)) Connect4::DrawPiece -n %id %x %y 20 if (%piece == 2) hadd -m %id Turn $hget(%id,Client) else hadd -m %id Turn $iif($hget(%id,Client) == 1,2,1) Connect4::DrawNames %id if ($Connect4::CheckForWin(%id)) { var %winState $token($v1,1,32) var %winPos $token($v1,2-,32) if (%winState == 1) Connect4::RegisterWin %id %winPos if (%winState == 2) Connect4::RegisterLoss %id %winPos if (%winState == 3) Connect4::RegisterDraw %id } return $true } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; alias Connect4::InitGUI { ;parameters: ;Calculates the default values for the GUI, ;opens the window, then draws it. var %windowPadding 5 var %squareSize 40 hadd $1 squareSize %squareSize var %board.x %windowPadding var %board.y %windowPadding var %board.w $calc(%squareSize * 7) var %board.h $calc(%squareSize * 6) hadd $1 board.x %board.x hadd $1 board.y %board.y hadd $1 board.w %board.w hadd $1 board.h %board.h var %sideBar.x $calc(%board.x + %board.w + %windowPadding) var %sideBar.y %windowPadding var %sideBar.w 200 var %sideBar.h %board.h hadd $1 sideBar.x %sideBar.x hadd $1 sideBar.y %sideBar.y hadd $1 sideBar.w %sideBar.w hadd $1 sideBar.h %sideBar.h var %closeButton.w 80 var %closeButton.h 21 var %closeButton.x $calc(%sideBar.x + (%sideBar.w - %closeButton.w) / 2) var %closeButton.y $calc(%sideBar.y + %sideBar.h - %closeButton.h) hadd $1 closeButton.x %closeButton.x hadd $1 closeButton.y %closeButton.y hadd $1 closeButton.w %closeButton.w hadd $1 closeButton.h %closeButton.h var %window.w $calc(%sidebar.x + %sidebar.w + %windowPadding) var %window.h $calc(%board.y + %board.h + %windowPadding) hadd $1 window.w %window.w hadd $1 window.h %window.h window -aBdfp @ $+ $1 -1 -1 %window.w %window.h Connect4::Draw $1 } alias Connect4::Draw { ;parameters: [-n] ;Draws the whole Connect 4 Window. var %n if ($1 == -n) { var %n 1 tokenize 32 $2- } var %white $rgb(255, 255, 255) ;Clear the background drawrect -nrf @ $+ $1 %white 1 0 0 $hget($1,window.w) $hget($1,window.h) Connect4::DrawBoard -n $1 Connect4::DrawSideBarStatus -n $1 -1 Connecting... Connect4::DrawScore -n $1 Connect4::DrawCloseButton -n $1 if (!%n) { drawdot @ $+ $1 } } alias Connect4::DrawBoard { ;parameters: var %n if ($1 == -n) { var %n 1 tokenize 32 $2- } var %x $hget($1,board.x) var %y $hget($1,board.y) var %w $hget($1,board.w) var %h $hget($1,board.h) ;Draw board drawrect -nrf @ $+ $1 $rgb(240,240,240) 1 %x %y %w %h ;Draw board border drawrect -nr @ $+ $1 $rgb(200,200,200) 1 %x %y %w %h var %column 0 while (%column Link to comment Share on other sites More sharing options...