Тема: Lan
Показать сообщение отдельно
Старый 05.01.2007, 02:09   #4
Atomikc
Бывалый
 
Регистрация: 14.12.2006
Сообщений: 811
Написано 93 полезных сообщений
(для 257 пользователей)
Re: Lan

Ну допустим танчики на 5 играков. простенькая игра. Там ведь можно всё и проше сделать. Или нет?
Вот нарыл пару примеров

сервер:

Сервер для сетевой программы (обучение как пользоватся Direct play)
Два шарика и возможность переписки
Извените без пояснений....

Graphics 640,480,32,0
fon=LoadFont("Ms sans Serif",10)
SetFont fon
 
Print "WAITING START NETGAME..." :Delay 1000
 
PK=HostNetGame("Lanx")
If PK<>2 Then End
PLY=CreateNetPlayer("Jim")
 
 
NMT=0
NMF=0
.g
 
 
If RecvNetMsg() Then
NMT=NetMsgType()
NMF=NetMsgFrom()
NMTT=NetMsgTo()
NMD$=NetMsgData$()
 
If nmt=100 Then plu=NMF
 
 
If nmt=2 Then x2=Int(NMD$)
If nmt=3 Then y2=Int(NMD$)
 
 
 
If nmt=5 Then
tot6$=tot5$
tot5$=tot4$
tot4$=tot3$
tot3$=tot2$
tot2$=tot$
tot$=NMD$
End If
 
 
End If
 
count=count+1
If Count=25 Then
SendNetMsg 2,x,ply,plu,0
SendNetMsg 3,y,ply,plu,0
Count=0
End If
 
 
If INPU=0 Then
If KeyDown(30) Then x=x-1
If KeyDown(32) Then x=x+1
If KeyDown(17) Then y=y-1
If KeyDown(31) Then y=y+1
End If
 
If KeyDown(15) Then INPU=1
 
 
 
If inpu=1 Then
s=GetKey()
If s<>0 And s<>9 And s<>8 Then t$=t$+Chr(s)
If s=13 Then SendNetMsg 5,t$,ply,plu,0:t$="":inpu=0
If s=8 Then t$=""
End If
 
 
Cls
Color 255,0,0:Oval x,y,10,10
Color 0,255,0:Oval x2,y2,15,15
Color 255,255,255
If inpu=1 Then Color 0,255,0
Text 10,50,">>>>>> "+t$+" <<<<<"
Text 10,90,Tot$
Text 10,100,tot2$
Text 10,110,tot3$
Text 10,120,tot4$
Text 10,130,tot5$
Text 10,140,tot6$
Color 255,255,255
 
 
Text 10,10,"YOU ID "+ply+" you joint with "+NetPlayerName(PLU)
Flip
 
Goto g
Клиент:
Client для Server DirectPlay (semples)

Тут все поясняется как управлять программой
принцип клиента и сервера по внешнему виду
идентичные даже код похож...
Лиш небольшие различия
(Примечание%) Я подключался так
Два модема один настроен как сервер с IP 197.57.0.1
а другой просто к нему подключается
тот кто сервер тот и запускает прогу сервер
Тот кто клиент соответственно
запускает клиента и указывает IP 197.57.0.1
и все.... Версии програм реально действующие
Сам пробывал... Правда ЛАГАЮТ из за не совершенства кода...


Graphics 640,480,32,2
fon=LoadFont("Ms sans Serif",10)
SetFont fon
 
 
 
.NE
Cls
Print ""
Print " Инструкция по применению."
Print ""
Print " Управление"
Print " [A,S,D,W] - управление шариком в четырех направленияях"
Print " [TAB] - вход в текстовый наборный режим (при етом стрелочки должны загорется зеленым)"
Print " [ENTER] - окончание текстового режима и отправка сообщения на сервер"
Print " [DEL] - удоление строки в текстовом режиме для перепичатования занова"
Print ""
Print ""
Print ""
Print ""
Print ""
Print ""
Print ""
Print ""
Print " Нажмите любую клавишу ..."
;WaitKey()
 
 
IPADDR$=Input ("IP ADDRES LIKE [127.0.0.1]: ")
Print "WAITING START NETGAME..." :Delay 1000
 
PK=JoinNetGame("Lanx",IPADDR$)
If PK<>1 Then Cls:Text 100,100,"SERVER CLOSED. TRY RECONNECT":If Input (" [y/n] ")="y" Then StopNetGame():Goto NE:Else End
 
PLY=CreateNetPlayer("Serg")
 
 
.g
 
 
If RecvNetMsg() Then
NMT=NetMsgType()
NMF=NetMsgFrom()
NMTT=NetMsgTo()
NMD$=NetMsgData$()
 
 
If nmt=100 Then plu=NMF
 
 
If nmt=2 Then x2=Int(NMD$)
If nmt=3 Then y2=Int(NMD$)
 
 
If nmt=5 Then
tot6$=tot5$
tot5$=tot4$
tot4$=tot3$
tot3$=tot2$
tot2$=tot$
tot$=NMD$
End If
 
 
 
End If
 
 
count=count+1
If Count=25 Then
SendNetMsg 2,x,ply,plu,0
SendNetMsg 3,y,ply,plu,0
Count=0
End If
 
 
 
If INPU=0 Then
If KeyDown(30) Then x=x-1
If KeyDown(32) Then x=x+1
If KeyDown(17) Then y=y-1
If KeyDown(31) Then y=y+1
 
End If
 
 
If KeyDown(15) Then INPU=1
 
 
If inpu=1 Then
s=GetKey()
If s<>0 And s<>9 And s<>8 Then t$=t$+Chr(s)
If s=13 Then SendNetMsg 5,t$,ply,plu,0:t$="":inpu=0
If s=8 Then t$=""
End If
 
 
 
Cls
Color 255,0,0:Oval x,y,10,10
Color 0,255,0:Oval x2,y2,15,15
Color 255,255,255
If inpu=1 Then Color 0,255,0
Text 10,50,">>>>>> "+t$+" <<<<<"
Text 10,90,Tot$
Text 10,100,tot2$
Text 10,110,tot3$
Text 10,120,tot4$
Text 10,130,tot5$
Text 10,140,tot6$
Color 255,255,255
 
NAMER$=NetPlayerName(PLU)
Text 10,10,"YOU ID "+ply+" you joint with "+NAMER$
If NAMER$="" Then Cls:Text 100,100,"SERVER CLOSED. TRY RECONNECT":If Input (" [y/n] ")="y" Then StopNetGame():Goto NE:Else End
Flip
 
Goto g
(Offline)
 
Ответить с цитированием