联网式中国象棋VB源代码 萨云轩工作室.docx
- 文档编号:30751379
- 上传时间:2023-08-20
- 格式:DOCX
- 页数:29
- 大小:122.93KB
联网式中国象棋VB源代码 萨云轩工作室.docx
《联网式中国象棋VB源代码 萨云轩工作室.docx》由会员分享,可在线阅读,更多相关《联网式中国象棋VB源代码 萨云轩工作室.docx(29页珍藏版)》请在冰豆网上搜索。
联网式中国象棋VB源代码萨云轩工作室
OptionExplicit
PublicbIsNetAsBoolean
ConstFF_EMP=-1
ConstFF_SIDE1=0
ConstFF_SIDE2=1
Dimlocal_sideAsInteger
Dimpos_sideAsInteger
DimChess_OnAsInteger
ConstFF_US_INITALL=0
ConstFF_US_INITNET=1
ConstFF_US_INITLOCAL=2
ConstFF_US_NET_CON=3
ConstFF_US_USE_CON=4
Dimb_ServerAsBoolean
Dimb_isConAsBoolean
Publicm_SetAsString
Dimm_BeSetAsString
'USERSTATE
EnumFF_UA_STATE
FF_UA_INIT
FF_UA_WAITING
FF_UA_USE
FF_UA_INVALID
EndEnum
Dimm_StateAsFF_UA_STATE
PrivateSubTransSide(ByRefsideAsInteger)
Ifside=FF_SIDE1Then
side=FF_SIDE2
Else
side=FF_SIDE1
EndIf
EndSub
PrivateSubTransState(methodAsInteger)
main.WindowState=vbNormal
SelectCasemethod
CaseFF_US_INITALL
InitalBoard
m_State=FF_UA_INVALID
c_MunNew.Visible=False
c_MunLoad.Enabled=True
c_eState.Text=""
c_eMsg.Text=""
c_CmdSay.Enabled=False
c_MunShow.Checked=bIsNet
pos_side=FF_SIDE1
Chess_On=FF_EMP
c_spChessOn.Visible=False
c_sUse.Close
b_isCon=False
CaseFF_US_INITNET
frm_net.Visible=True
main.Width=8835
pic_noclick.Visible=True
pic_click.Visible=False
c_sColor.FillColor=&H8000000F
c_CmdCon.Enabled=True
CaseFF_US_INITLOCAL
frm_net.Visible=False
main.Width=5880
pic_noclick.Visible=False
pic_click.Visible=True
c_sColor.FillColor=vbRed
local_side=FF_SIDE1
CaseFF_US_NET_CON
c_CmdSay.Enabled=True
b_isCon=True
c_CmdCon.Enabled=False
c_eState.Text="网络连接成功"
CaseFF_US_USE_CON
m_State=FF_UA_USE
c_MunLoad.Enabled=False
c_MunNew.Visible=False
c_eState.Text="开始"
EndSelect
EndSub
PrivateSubInitalBoard()
DimiAsInteger
Dimx_step,d_stepAsInteger
x_step=0
d_step=-1
Fori=0To8
c_chess(i).Top=0
c_chess(i).Left=2595+x_step*d_step
c_chess(i+16).Top=5400
c_chess(i+16).Left=c_chess(i).Left
If(i/2=Int(i/2))Thenx_step=x_step+600
d_step=-d_step
Nexti
Fori=0To1
c_chess(i+9).Top=1200
c_chess(i+9).Left=795+i*3600
c_chess(i+25).Top=4200
c_chess(i+25).Left=c_chess(i+9).Left
Nexti
Fori=0To4
c_chess(i+11).Top=1800
c_chess(i+11).Left=195+i*1200
c_chess(i+27).Top=3600
c_chess(i+27).Left=c_chess(i+11).Left
Nexti
Fori=0To31
c_chess(i).Visible=True
Nexti
EndSub
PrivateFunctionDuiJiang()AsBoolean
Dimi,count,tempAsInteger
IfNotc_chess(0).Left=c_chess(16).LeftThen
DuiJiang=False
ExitFunction
EndIf
temp=Sgn(c_chess(16).Top-c_chess(0).Top)
count=0
Fori=c_chess(0).Top/600+tempToc_chess(16).Top/600-tempSteptemp
IfFindChessInPos((c_chess(0).Left-195)/600,i)>-1Thencount=count+1
Nexti
Ifcount=0Then
DuiJiang=True
ExitFunction
EndIf
DuiJiang=False
EndFunction
PrivateSubDie(ByValchess_dieAsInteger)
Ifchess_die=0Then
MsgBox"黑方输了",vbOKOnly,App.LegalTrademarks
Else
MsgBox"红方输了",vbOKOnly,App.LegalTrademarks
EndIf
IfbIsNet=TrueThen
InitalBoard
m_State=FF_UA_INIT
c_MunNew.Visible=True
c_MunLoad.Enabled=True
c_eState.Text=""
c_eMsg.Text=""
c_CmdSay.Enabled=True
c_MunShow.Checked=bIsNet
pos_side=FF_SIDE1
Chess_On=FF_EMP
c_spChessOn.Visible=False
frm_net.Visible=True
pic_noclick.Visible=True
pic_click.Visible=False
c_sColor.FillColor=&H8000000F
Else
TransStateFF_US_INITALL
TransStateFF_US_INITLOCAL
EndIf
EndSub
PrivateFunctionGoChess(ByValchessAsInteger,ByValx_offAsInteger_
ByValy_offAsInteger)AsBoolean
Dimuse_sideAsInteger
Dimx_begin,y_beginAsInteger
DimDistentAsSingle
DimiAsInteger
Ifchess>15Then
use_side=FF_SIDE2
Else
use_side=FF_SIDE1
EndIf
x_begin=(c_chess(chess).Left-195)/600
y_begin=(c_chess(chess).Top)/600
Distent=Sqr((x_off-x_begin)^2+(y_off-y_begin)^2)
SelectCaseInt((chess-use_side*16+1)/2)
Case0'jian
IfDistent>1ThenGoToerrhandle
Ifx_off<3Orx_off>5ThenGoToerrhandle
IfGetSelf(chess,y_off)>2ThenGoToerrhandle
c_chess(chess).Left=x_off*600+195
IfDuiJiang=TrueThen
MsgBox"CanNotthiscol",vbOKOnly,App.LegalTrademarks
c_chess(chess).Left=x_begin*600+195
GoToerrhandle
EndIf
Case1'shi
IfDistent<1.4OrDistent>1.5ThenGoToerrhandle
Ifx_off<3Orx_off>5ThenGoToerrhandle
IfGetSelf(chess,y_off)>2ThenGoToerrhandle
Case2'xiang
IfDistent<2.8OrDistent>2.9ThenGoToerrhandle
IfGetSelf(chess,y_off)>4ThenGoToerrhandle
IfFindChessInPos((x_off+x_begin)/2,(y_begin+y_off)/2)>-1ThenGoToerrhandle
Case3'ma
IfDistent<2.2OrDistent>2.3ThenGoToerrhandle
IfFindChessInPos(x_off-Sgn(x_off-x_begin),y_off-Sgn(y_off-y_begin))>-1ThenGoToerrhandle
Case4'che
If(Notx_begin=x_off)And(Noty_begin=y_off)ThenGoToerrhandle
Ifx_begin=x_offThen
Fori=y_begin+Sgn(y_off-y_begin)Toy_off-Sgn(y_off-y_begin)StepSgn(y_off-y_begin)
IfNotFindChessInPos(x_off,i)=-1ThenGoToerrhandle
Nexti
EndIf
Ify_begin=y_offThen
Fori=x_begin+Sgn(x_off-x_begin)Tox_off-Sgn(x_off-x_begin)StepSgn(x_off-x_begin)
IfNotFindChessInPos(i,y_off)=-1ThenGoToerrhandle
Nexti
EndIf
Case5'pao
If(Notx_begin=x_off)And(Noty_begin=y_off)ThenGoToerrhandle
Ifx_begin=x_offThen
Fori=y_begin+Sgn(y_off-y_begin)Toy_offStepSgn(y_off-y_begin)
IfNotFindChessInPos(x_off,i)=-1ThenGoToerrhandle
Nexti
EndIf
Ify_begin=y_offThen
Fori=x_begin+Sgn(x_off-x_begin)Tox_offStepSgn(x_off-x_begin)
IfNotFindChessInPos(i,y_off)=-1ThenGoToerrhandle
Nexti
EndIf
CaseElse'bing
IfDistent>1ThenGoToerrhandle
IfGetSelf(chess,y_off) IfGetSelf(chess,y_off)<5And(Notx_off=x_begin)ThenGoToerrhandle EndSelect c_chess(chess).Left=x_off*600+195 c_chess(chess).Top=y_off*600 IfbIsNet=FalseThen TransSidelocal_side Ifc_sColor.FillColor=vbRedThen c_sColor.FillColor=vbBlue Else c_sColor.FillColor=vbRed EndIf Else pic_click.Visible=Notpic_click.Visible pic_noclick.Visible=Notpic_click.Visible EndIf TransSidepos_side GoChess=True ExitFunction errhandle: GoChess=False EndFunction PrivateFunctionFindChessInPos(ByValXAsInteger,ByValYAsInteger)AsInteger DimiAsInteger Fori=0To31 Ifc_chess(i).Visible=TrueAndc_chess(i).Top/600=YAnd(c_chess(i).Left-195)/600=XThen FindChessInPos=i ExitFunction EndIf Nexti FindChessInPos=-1 EndFunction PrivateSubTransBoard() Dimi,x_off,y_offAsInteger Fori=0To31 x_off=(c_chess(i).Left-195)/600 x_off=8-x_off y_off=c_chess(i).Top/600 y_off=9-y_off c_chess(i).Left=x_off*600+195 c_chess(i).Top=y_off*600 Nexti EndSub PrivateFunctionGetSelf(ByValchessAsInteger,ByValYAsInteger)AsInteger Dimtemp_sideAsInteger IfbIsNet=TrueThen temp_side=Int(chess/16) IfNotlocal_side=temp_sideThen GetSelf=9-Y Else GetSelf=Y EndIf Else Ifchess>15Then GetSelf=9-Y Else GetSelf=Y EndIf EndIf EndFunction PrivateSubc_chess_Click(IndexAsInteger) If(bIsNet=True)And(Notm_State=FF_UA_USE)ThenExitSub IfNotpos_side=local_sideThenExitSub DimiAsInteger DimcountAsInteger Dimx_off,y_off,x_begin,y_beginAsInteger x_off=(c_chess(Index).Left-195)/600 y_off=(c_chess(Index).Top)/600 IfNotInt(Index/16)=local_sideThen Chess_On=Index c_spChessOn.Left=c_chess(Chess_On).Left-60 c_spChessOn.Top=c_chess(Chess_On).Top-60 c_spChessOn.Visible=True Else IfChess_On=FF_EMPThenExitSub IfGoChess(Chess_On,x_off,y_off)=TrueThen IfbIsNet=TrueAndm_State=FF_UA_USEThenc_sUse.SendData_ "Post"+Chr(Chess_On+65)+Chr(x_off+48)+Chr(y_off+48) c_chess(Index).Visible=False IfIndex=0OrIndex=16Then DieIndex ExitSub EndIf Chess_On=FF_EMP c_spChessOn.Visible=False Else IfChess_On=9OrChess_On=10OrChess_On=25OrChess_On=25OrChess_On=26Then x_begin=(c_chess(Chess_On).Left-195)/600 y_begin=(c_chess(Chess_On).Top)/600 count=0 If(Notx_begin=x_off)And(Noty_begin=y_off)ThenExitSub Ifx_begin=x_offThen Fori=y_begin+Sgn(y_off-y_begin)Toy_off-Sgn(y_off-y_begin)StepSgn(y_off-y_begin) IfNotFindChessInPos(x_off,i)=-1Thencount=count+1 Nexti EndIf Ify_begin=y_offThen Fori=x_begin+Sgn(x_off-x_begin)Tox_off-Sgn(x_off-x_begin)StepSgn(x_off-x_begin) IfNotFindChessInPos(i,y_off)=-1Thencount=count+1 Nexti EndIf EndIf EndIf Ifcount=1Then IfbIsNet=TrueAndm_State=FF_UA_USEThenc_sUse.SendData_ "Post"+Chr(Chess_On+65)+Chr(x_off+48)+Chr(y_off+48) c_chess(Chess_On).Top=c_chess(Index).Top c_chess(Chess_On).Left=c_chess(Index).Left c_chess(Index).Visible=False IfIndex=0OrIndex=16Then DieIndex ExitSub EndIf Chess_On=FF_EMP c_spChessOn.Visible=False IfbIsNet=FalseThen TransSidelocal_side Ifc_sColor.FillColor=vbRedThen c_sColor.FillColor=vbBlue Else c_sColor.FillColor=vbRed EndIf Else pic_click.Visible=Notpic_click.Visible pic_noclick.Visible=Notpic_noclick.Visible EndIf TransSidepos_side EndIf EndIf EndSub PrivateSubc_cmdReset_Click() Loadf_Gnet f_Gnet.ShowvbModal,main TransStateFF_US_INITALL IfbIsNet=TrueThen TransStateFF_US_INITNET Else TransStateFF_US_INITLOCAL EndIf EndSub PrivateSubc_MunExit_Click() UnloadMe EndSub PrivateSubc_MunLoad_Click()
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 联网式中国象棋VB源代码 萨云轩 工作室 联网 中国象棋 VB 源代码