KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

KixMoku 0.9.7 - the full fun, no more draw buggies...

 
Post new topic   Reply to topic    KiXforms Forum Index -> Fun & Games
View previous topic :: View next topic  
Author Message
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sun Aug 22, 2004 2:37 pm    Post subject: KixMoku 0.9.7 - the full fun, no more draw buggies... Reply with quote

changed the logic to not obey picturebox (as it clearly had a bug) but now using that weird stuff, multidimensional array.
you find some oddities, let me know.
some improvements added and other stuff just cleared up.
well, see for yourself.

Code:
$system = createobject("kixtart.system")
$rc=setoption("novarsinstrings","on")
$gui = $system.form
$gui.fontsize=8
;$gui.location=0,0
$gui.clientsize=700,595
$gui.text="KiXmoku 0.9.7"
$gui.minimumsize=$gui.width,$gui.height
drawGameArea
createmarks
$serverDisconnectB=$gui.button("Disconnect Game",$GameTable.right+5,$GameTable.bottom-22,$gui.clientwidth-$GameTable.right-15,22)
$serverJoinB=$gui.button("Connect to Game Server",$GameTable.right+5,$serverDisconnectB.top-27,$serverDisconnectB.width,22)
$serverStartB=$gui.button("Start Game Server",$GameTable.right+5,$serverJoinB.top-27,$serverDisconnectB.width,22)
$gameStartB=$gui.button("Start Game",$GameTable.right+5,10,$serverDisconnectB.width,22)
$gameStartB.onclick="$status.text='' $socket.send('IwannaPlay') drawgameArea $gameStartB.enabled=0 $status.text=iif($mark,'Opponents','Your')+' Turn' if $mark=0 $GameTable.OnClick = 'click' endif"
$serverStartB.onclick="$won=0 $lost=0 $gameStat.text='' $status.text='' startServer $serverStartB.enabled=0 $serverJoinB.enabled=0 $serverDisconnectB.enabled=1"
$serverJoinB.onclick="$won=0 $lost=0 $gameStat.text='' $status.text='' joinServer"
$serverDisconnectB.onclick="$status.text='' $socket.disconnect() $serverStartB.enabled=1 $serverJoinB.enabled=1 $serverDisconnectB.enabled=0 $gameStartB.enabled=0 writeSome('<font color="+chr(34)+"blue"+chr(34)+">Disconnected</font>')"
$serverDisconnectB.enabled=0
$gameStartB.enabled=0
$gameStat=$gui.label("",$GameTable.right+5,$gameStartB.bottom+10,$gameStartB.width,20)
$status=$gui.label('',$gameStat.left,$gameStat.bottom+2,$gameStat.width,20)
$nickHelper=$gui.label('Nick:',$status.left,$status.bottom+5,40,20)
$nick=$gui.textbox(@userid,$nickHelper.right+2,$status.bottom+5,$gameStat.width-42,20)
$statusTalk=$gui.richtextbox(,5,$gametable.bottom+2,$gameStartB.right-5,50)
$statusTalk.multiline=1
$statusTalk.readonly=1
$statusTalk.html="<font size=1>"
$meTalk=$gui.textbox(,$statusTalk.left,$statusTalk.bottom+4,$statusTalk.width-60,22)
$meTalkB=$gui.Button("Send",$meTalk.right+5,$meTalk.top,50,22)
$meTalkB.onclick="if len($meTalk.text) $socket.send('talk:'+$nick.text+': '+$meTalk.text) writeSome($nick.text+': '+$meTalk.text) $meTalk.text='' endif"
$meTalkB.default=1
$gui.show
while $gui.visible
 $=execute($gui.doevents)
loop

;function startGame()
;drawgamearea
;$GameTable.OnClick = "drawMark($GameTable.mouseX/11*11,$GameTable.mouseY/11*11,$mark)"
;endfunction

function writeSome($)
 $statusTalk.html=$statusTalk.html+$+"<br>"
 $statusTalk.selectionStart=len($statusTalk.text)-4
 $statusTalk.setfocus
 $statusTalk.scrolltocaret
 $meTalk.setfocus
endfunction

function drawGameArea()
dim $c,$matrix[45,45]
 $c = $gui.RGB(170,170,170)
 $GameTable = $gui.PictureBox("",5,5)
 $GameTable.clientsize=495,495
 $GameTable.BackColor = "white"
 $GameTable.DrawWidth = 1
 for $=11 to 495 step 11
  $GameTable.line($,0,$,$GameTable.clientHeight,$c)
 next
 for $=11 to 495 step 11
  $GameTable.line(0,$,$GameTable.clientWidth,$,$c)
 next
 $GameTable.onmouseover="$gameTable.setfocus"
 $GameTable.tag=$matrix
endfunction

function drawMark($x,$y,$m)
dim $c,$matrix
 $c = $gui.RGB(255*$m,0,255*($m=0))
 $x=1+$x $y=1+$y
 $matrix=$GameTable.tag
 if $matrix[$x/11,$y/11] exit 0 endif
  for $=0 to 9
   $GameTable.line($x+$markpaint[$m][$][0],$y+$,$x+$markpaint[$m][$][1],$y+$,$c)
   $GameTable.line($x+$markpaint[$m][$][2],$y+$,$x+$markpaint[$m][$][3],$y+$,$c)
  next
 $matrix[$x/11,$y/11] = 1+$m
 checkwin($x,$y,1+$m,$matrix)
 $GameTable.tag=$matrix
endfunction

function checkWin($x,$y,$m,$matrix)
dim $c,$,$a,$pX,$pY
 $pX=$x/11
 $pY=$y/11

 for $=$pX-4 to $pX+4
  if $m=$matrix[$,$pY] $a=$a+"1" if 5=len($a) markwin($*11-40,$pY*11+4,$*11+7,$pY*11+4,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=$pY-4 to $pY+4
  if $m=$matrix[$pX,$] $a=$a+"1" if 5=len($a) markwin($pX*11+4,$*11-40,$pX*11+4,$*11+7,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=-4 to 4
  if $m=$matrix[$pX+$,$pY+$] $a=$a+"1" if 5=len($a) markwin(($pX+$)*11-40,($pY+$)*11-40,($pX+$)*11+7,($pY+$)*11+7,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=-4 to 4
  if $m=$matrix[$pX+$,$pY-1*$] $a=$a+"1" if 5=len($a) markwin(($pX+$)*11-41,($pY-1*$)*11+49,($pX+$)*11+7,($pY-1*$)*11+2,$m) exit 0 endif else $a="" endif
 next
endfunction

function markWin($x,$y,$z,$w,$m)
 $GameTable.drawWidth=2
 $GameTable.line($x,$y,$z,$w,0)
 $GameTable.drawWidth=1
 $GameTable.onclick=""
 $gameStartB.enabled=1
 if $m-1=$mark
  writeSome("<font color='red'>You Won!</font>")
  $won=1+$won
  $mark=0
 else
  writeSome("<font color='red'>You Lost!</font>")
  $mark=1
  $lost=1+$lost
 endif
 $gameStat.text="Games Won: "+$won+"/"+($won+$lost)
 $status.text=""
endfunction

function createmarks()
global $markPaint[1]
dim $x[9]
 $x[0]=0,2,7,9 $x[1]=0,3,6,9 $x[2]=1,3,5,8 $x[3]=2,7,2,7 $x[4]=3,6,3,6
 $x[5]=3,6,3,6 $x[6]=2,7,2,7 $x[7]=1,3,5,8 $x[8]=0,3,6,9 $x[9]=0,2,7,9
 $markpaint[0]=$x
 $x[0]=3,8,0,0 $x[1]=2,9,6,9 $x[2]=1,3,7,9 $x[3]=0,3,8,9 $x[4]=0,2,8,9
 $x[5]=0,2,8,9 $x[6]=0,2,7,9 $x[7]=0,3,6,8 $x[8]=1,7,0,0 $x[9]=3,6,0,0
 $markpaint[1]=$x
endfunction

function startServer()
 $Server = $system.socket()
 $Server.blocking = 0
 $Server.onaccept = "$socket=$server.accept() $socket.blocking = 0 writeSome('<font color="+chr(34)+"blue"+chr(34)+">client '+$socket.remoteaddress+' Connected.</font>') networkInit"
 $Server.localport = 777
 $Server.localaddress = join(split(@ipaddress0),'')
 $Server.bind
 $Server.listen
 $mark=0
 writeSome("<font color='blue'>waiting for client-connections...</font>")
endfunction

function networkInit()
 $socket.onreceive='receive()'
 $socket.ondisconnect="writeSome('<font color="+chr(34)+"blue"+chr(34)+">Opponent Disconnected</font>') $serverStartB.enabled=1 $serverJoinB.enabled=1 $serverDisconnectB.enabled=0 $gameStartB.enabled=0 $holder.enabled=0"
 $gameStartB.enabled=1
 $holder=$system.timer(10000)
 $holder.tag=2
 $holder.ontick="if $holder.tag $socket.send('PingPong') $holder.tag=-1+$holder.tag else writeSome('<font color="+chr(34)+"blue"+chr(34)+">Connection Lost</font>') $serverStartB.enabled=1 $serverJoinB.enabled=1 $serverDisconnectB.enabled=0 endif"
 $holder.enabled=1
endfunction

function joinServer()
 dim $query,$queryText,$queryHelpText,$queryOkB,$queryCancelB,$serverIP,$SAamount,$,$is
 $query=$system.form($gui)
 $query.clientsize=340,40
 $query.top=$gui.top+70
 $query.left=$gui.left+20
 $query.formborderstyle=0
 $queryHelpText=$query.label("Give The IPaddress of the Server you wanna join to:",5,5,330,20)
 $queryText=$query.combobox("",5,30,120,20)
 $SAamount=readvalue("HKCU\software\jooel\KixMoku\serverCache","amount")
 for $=0 to $SAamount
  $queryText.additem(readvalue("HKCU\software\jooel\KixMoku\serverCache",$))
 next
 $queryOkB=$query.button("Ok",130,30,60,20)
 $queryCancelB=$query.button("Cancel",200,30,60,20)
 $queryOkB.onclick="$serverIP=$queryText.text $query.hide"
 $queryOkB.default=1
 $queryCancelB.onclick="$query.hide"
 $query.show
 while $query.visible
  $nul=execute($query.doevents)
 loop
 if $serverIP
  writeSome("<font color='blue'>connecting to server ("+$serverIP+")...</font>")
  $socket = $system.socket()
  $socket.remoteaddress=$serverIP
  $socket.remoteport=777
  $socket.connect() ;($serverIP,777)
  $socket.blocking = 0
  if $system.error
  writeSome("<font color='blue'><b>("+$system.error+") "+$system.serror+"</b></font>")
   $serverStartB.enabled=1 $serverJoinB.enabled=1 $serverDisconnectB.enabled=0
  else
  writeSome("<font color='blue'>Connected to Game Server at "+$socket.remoteaddress+"</font>")
   $serverStartB.enabled=0 $serverJoinB.enabled=0 $serverDisconnectB.enabled=1
   networkInit
   for $=0 to $SAamount
    if $serverIP=readvalue("HKCU\software\jooel\KixMoku\serverCache",$)
     $is=1
    endif
   next
   if not $is
    $=writevalue("HKCU\software\jooel\KixMoku\serverCache","amount",1+$SAamount,"REG_SZ")
    $=writevalue("HKCU\software\jooel\KixMoku\serverCache",1+$SAamount,$serverIP,"REG_SZ")
   endif
  endif
  $mark=1
 else
  $serverStartB.enabled=1 $serverJoinB.enabled=1 $serverDisconnectB.enabled=0
 endif
endfunction

function click()
dim $x,$y
 $y=$GameTable.mouseY/11*11
 $x=$GameTable.mouseX/11*11
 $GameTable.OnClick = ""
 $socket.send('coords:'+$x+','+$y)
 $status.text="Opponents Turn"
 drawMark($x,$y,$mark)
endfunction

function receive()
 dim $t,$c
 $t=$socket.receive
 select
  case left($t,7)="coords:"
   $c=split(substr($t,8),",")
   $GameTable.OnClick = "click"
   $status.text="Your Turn"
sleep 1
   drawmark($c[0],$c[1],iif($mark,0,1))
  case $t="iwannaplay"
    $gameStartB.enabled=0
   drawgamearea
   if $mark=0
    $GameTable.OnClick = "click"
    $status.text="Your Turn"
   else
    $status.text="Opponents Turn"
   endif
  case $t="PingPong"
   $holder.tag=2
  case left($t,5)="talk:"
   writeSome(substr($t,6))
 endselect
endfunction

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Thu Aug 26, 2004 2:24 am    Post subject: Reply with quote

critical security notice:
after playing 10 games I got array ref out of bounds on line 93...

the nature of the bug is so weird that I haven't been able to trace it this far yet no...

_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Fun & Games All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group