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 - get five in row
Goto page 1, 2  Next
 
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: Wed Aug 11, 2004 10:47 pm    Post subject: KiXmoku - get five in row Reply with quote

new game with network and stuff.
try it out.
it has not all the fancy stuff yet, but it's working.

[€dit]
new version with chat and all shit...
the chat box could be one line higher though...
playing with my friend here and he is kicking my ASS!
[/€dit]
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.3"
$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)
$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('Opponent Says: '+$meTalk.text) writeSome('You said: '+$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)-1
 $statusTalk.setfocus
 $statusTalk.scrolltocaret
 $meTalk.setfocus
endfunction

function drawGameArea()
 $c = $gui.RGB(170,170,170)
; $gameTable=$gui.listview(,5,20,$gui.clientwidth-100,$gui.clientheight)
$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.OnClick = "drawMark($GameTable.mouseX/11*11,$GameTable.mouseY/11*11,$mark)"
endfunction

function drawMark($x,$y,$m)
 $c = $gui.RGB(255*$m,0,255*($m=0))
 $x=1+$x $y=1+$y
 if 16777215<>$GameTable.point($x+7,$y) 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
 checkwin($x,$y,$m)
endfunction

function checkWin($x,$y,$m)
dim $c,$,$a
 $c=$GameTable.point($x+7,$y)
 for $=$x-44 to $x+44 step 11
  if $c=$GameTable.point($+7,$y) $a=$a+"1" if 5=len($a) markwin($-40,$y+4,$+7,$y+4,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=$y-44 to $y+44 step 11
  if $c=$GameTable.point($x+7,$) $a=$a+"1" if 5=len($a) markwin($x+4,$-40,$x+4,$+7,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=-44 to 44 step 11
  if $c=$GameTable.point($x+$+7,$y+$) $a=$a+"1" if 5=len($a) markwin($x+$-40,$y+$-40,$x+$+7,$y+$+7,$m) exit 0 endif else $a="" endif
 next
 $a=""
 for $=-44 to 44 step 11
  if $c=$GameTable.point($x+$+7,$y-1*$) $a=$a+"1" if 5=len($a) markwin($x+$-41,$y-1*$+49,$x+$+7,$y-1*$+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=$mark
  writeSome("<font color='red'>You Won!</font>")
  $won=1+$won
  $mark=0
 else
;  $status.text="You Lost!"
  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
 $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.textbox("",5,30,120,20)
 $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
  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)
;"Send:   " $x " " $y ?
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"
   drawmark($c[0],$c[1],iif($mark,0,1))
;"Receive:   " $c[0] " " $c[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
; "tell Mama " @time ?
  case left($t,14)="Opponent Says:"
   writeSome($t)
 endselect
endfunction

_________________
Hammer


Last edited by Lonkero on Thu Aug 12, 2004 5:03 pm; edited 1 time in total
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: Wed Aug 11, 2004 10:57 pm    Post subject: Reply with quote

btw, you can play it with yourself, but think that's kinda pointless...
haven't got the computer brain in it so anyone interested could code it.

basic help:
you wanna play.
reach to someone and ask him to play too.
he says yes.
fire up the script and press start gameserver button.
tell your buddy to press join to server and tell him your ip addy.

he joins, and of you go with your play.

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


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

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

Got the network game going, but the guy who "connected" to the server can't see othe server-guys X's ??? wtf ??? :0)

-Shawn
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Thu Aug 12, 2004 7:39 am    Post subject: Reply with quote

how old KF he has?
if it's you, I wonder.
worked fine here.

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


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Thu Aug 12, 2004 7:51 am    Post subject: Reply with quote

maybe his one is newer ... Oh babylonic build 45 Rolling Eyes
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
Lonkero
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Thu Aug 12, 2004 8:52 am    Post subject: Reply with quote

k, found shit too.
not sure, but looks like non-blocking socket ain't giving me all the stuff.

game went fine but it was around 5th X when it did not draw it.
after that, it went ok again, but obviously... the winner didn't win in the other screen.

_________________
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 12, 2004 8:56 am    Post subject: Reply with quote

ja, it occurs only from time to time.
_________________
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 12, 2004 9:32 am    Post subject: Reply with quote

well, from time to time the X does not appear in neither.
that's weird.
the data goes via the network but the picturebox don't take it Sad

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


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Aug 12, 2004 12:04 pm    Post subject: Reply with quote

I'm just yanking your chain Jooel - who cares if it drops an X or O now and again - this game is a work-of-art !

-Shawn
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Thu Aug 12, 2004 12:43 pm    Post subject: Reply with quote

well, who cares?
I do.
I now know it is nothing about sockets.
the sockets send the stuff and ping pongs and all just fine.
it seems that there might be some event ruling order thing...

not sure, but I know the marks get transferred and all works, just the picturebox does not draw it.

anyway, thanks for the feedback.
have new build at home which has chat inbuild, just need to tweak the richtextbox code to append and scroll to bottom.
oh, is there ever gonna be append method for textboxes?

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


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Aug 12, 2004 12:57 pm    Post subject: Reply with quote

append method for textboxes - ja - textbox.appendtext(text) :0)
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Thu Aug 12, 2004 2:37 pm    Post subject: Reply with quote

textboxes = textbox, richtextbox and all alike.

$richtextbox.html.append("some blaah<hr>")

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


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Thu Aug 12, 2004 2:44 pm    Post subject: Reply with quote

ok - i know where your heading with this. The html support for RichTextBox is too crude to support appending HTML directly ... the only solution is to keep doing it additively, like this:

$RichTextBox.Html = $RichTextBox.Html + "<h1>My line...</h1>"

or the like ... but the performance will degrade exponentially. What I was meaning to do, and will do, is support the dotnetty method for colorizing and formatting text in rtb.... this will work for appended text and will be fast, will advise.
Back to top
View user's profile Send private message
Lonkero
KiXforms Devotee
KiXforms Devotee


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

PostPosted: Thu Aug 12, 2004 5:04 pm    Post subject: Reply with quote

new version.
added chat and all the shit I could.
recognizes disconnection by the user from the network lagging.
not so good thing but had to do it, as I'm irc-dude.

some other shit happened too, just can't remember.

_________________
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 12, 2004 10:00 pm    Post subject: Reply with quote

just playing with shane...
this one missing mark per game is annoying.
shawn, I want you (or either captain) to look at it.

otherwise, the chat works 100% and everything goes smoothly.
one thing though... it has three lines in window, and it always goes to last line (which is blank)
does <br> in html feed 10+13 to the text or just 10?

_________________
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
Goto page 1, 2  Next
Page 1 of 2

 
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