摘 要
本文详细介?绍了一个网?络对战军棋?游戏的设计?和实现。对于军棋游?戏来说,规则非常简?单,就是按照先?后顺序在棋?盘上走棋吃?子,直到一方最?先将对方的?“军旗”挖掉为胜。
这里使用了?UDP(User Data Proto?col)。UDP是用?户数据文报?协议的简称?,两台计算机?之间的传输?类似于传递?邮件;两台之间没?有明确的连?接,使用UDP?协议建立对?等通信。游戏开始后?,创建一个线?程启动线程后?,通过不断侦?听本机设定?的端口,得到对方发?送来的信息?,根据自己定?义的通信协?议中传送的?是“输赢信息”、“下的棋子位?置信息”、“重新开始”等信息而分?别处理。发送信息较?为简单,主要实现创?建UDP网?络服务,传送信息到?指定计算机?的端口号后?,关闭UDP?服务。
军棋UDP;C#
Abstr?act
This paper? descr?ibes the desig?n and imple?menta?tion of the Versu?s-netwo?rk Jun Qi.Game rules? are very simpl?e:take turns? playi?ng chess? on a chess? board?,and the one who dig the “flag” of the other? side first? will be the winne?r.
The game uses the C # progr?ammin?g to estab?lish commu?nicat?ion in the netwo?rk .UDP is used there?.UDP is the short? for User Data Proto?col.Trans?missi?on betwe?en two compu?ters is simil?ar to deliv?ering? the messa?ge;There? is no clear? conne?ction? betwe?en the two, using? the UDP proto?col to estab?lish peer commu?nicat?ions.After? the start? of the game, creat?e a threa?d.After? start?ing the threa?d ,throu?gh conti?nuous?ly liste?ning to the port we set,we get infor?matio?n from the other? side. Then proce?ss respe?ctive?ly "winni?ng or losin?g ", "the piece?s posit?ion", "start? again?" and other? infor?matio?n accor?ding to our own defin?ition? of commu?nicat?ion proto?col.Sendi?ng infor?matio?n is relat?ively? simpl?e,mainl?y to creat?e UDP netwo?rk servi?ces, trans?mit infor?matio?n to the desig?nated? remot?e port of the other? compu?ter, shut down the UDP servi?ce.
Creat?ing the game, joini?ng the game and other? funct?ions can be achie?ved in the netwo?rk.
Keywo?rds: Jun Qi;UDP;C #
目 录
1 绪 论1
1.1 网络棋牌游?戏的现状1
1.2 网络棋牌游?戏的未来发?展?2
2 军棋游戏功?能分析4
3 开发环境及?关键技术6
3.1Visu?al Studi?o 2010开?发平台6
3.2 C#编程技术7
3.3UDPC?lient?协议9
3.4C#的UdpC?lient?类11
3.5 12
4 软件整体设?计13
4.1界面设计?13
4.2棋盘数据?结构14
4.3通信协议?设计14
4.4走棋规则?设计16
4.5布阵规则?设计18
5软件详细?设计20
5.1初始化棋?盘22
5.2棋子控件?的四个事件?24
5.3走棋规则?32
5.4读写布阵?棋谱文件39
5.5“保存布阵”、“读取布阵”、“开始对战”41
5.6通信过程?42
5.7“主机