Guest User

Untitled

a guest
Dec 23rd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Global host = CreateGNetHost()
  2. Global msgobj:TGNetObject
  3. Global remoteobj:TGNetObject
  4. Global clientid
  5. Global objlist:TList
  6.  
  7. Graphics 800,600
  8.  
  9. in$=""
  10.  
  11. While Not (KeyHit (KEY_ENTER))
  12.     If AppTerminate () End
  13.     Delay 10
  14.     If KeyHit (KEY_BACKSPACE) in=Left (in,Len (in)-1)
  15.     ch=GetChar ()
  16.     If (ch>47 And ch<58) Or ch=46 in$=in$+Chr(ch)
  17.     DrawText ("Serverin ip:"+in,1,1)
  18.     Flip
  19.     Cls
  20. Wend
  21.  
  22. address$=in
  23.  
  24. DrawText ("Yhdistetaan",1,1)
  25. Flip
  26.  
  27. cerror=connecthost(address$,21231)
  28.  
  29. Cls
  30.  
  31. ox=0
  32. oy=0
  33.  
  34.  
  35. While Not (KeyHit(KEY_ESCAPE) Or AppTerminate ())
  36.     Delay 10
  37.    
  38.     If cerror=0
  39.         DrawText ("Ei yhteytta",1,1)
  40.     Else
  41.        
  42.         DrawText ("Yhteys",1,1)
  43.        
  44.         GNetSync host
  45.  
  46.         DrawText ("id "+clientid,1,20)
  47.         If KeyDown (KEY_LEFT)
  48.             DrawText ("moving",1,40)
  49.             SetGNetInt (msgobj,2,-1)
  50.         EndIf
  51.        
  52.         If KeyDown (KEY_RIGHT)
  53.             DrawText ("moving",1,40)
  54.             SetGNetInt (msgobj,2,1)
  55.         EndIf
  56.        
  57.         If KeyDown (KEY_DOWN)
  58.             DrawText ("moving",1,40)
  59.             SetGNetInt (msgobj,3,1)
  60.         EndIf
  61.        
  62.         If KeyDown (KEY_UP)
  63.             DrawText ("moving",1,40)
  64.             SetGNetInt (msgobj,3,-1)
  65.         EndIf
  66.        
  67.         objlist = GNetObjects (host, GNET_MODIFIED)
  68.         For remoteobj = EachIn objlist
  69.             ox=GetGNetInt (remoteobj,2)
  70.             oy=GetGNetInt (remoteobj,3)
  71.         Next
  72.        
  73.         DrawText (ox,1,60)
  74.         DrawText (oy,1,80)
  75.     EndIf
  76.    
  77.     Flip
  78.     Cls
  79.    
  80. Wend
  81. CloseGNetHost(host)
  82. End
  83.  
  84. Function connecthost (ip$,port)
  85.     connect = GNetConnect (host,ip,port,5000)
  86.     If Not connect Return 0
  87.    
  88.     msgobj=CreateGNetObject (host)
  89.    
  90.     SeedRnd MilliSecs()
  91.    
  92.     clientid=Rand (1,320000)
  93.    
  94.     objlist:TList= New TList
  95.  
  96.     SetGNetInt (msgobj,0,1)
  97.     SetGNetInt (msgobj,1,clientid)
  98.    
  99.     Return connect
  100. EndFunction
Add Comment
Please, Sign In to add comment