資源簡(jiǎn)介
基于socket的c#實(shí)現(xiàn)的五子棋,首先打開服務(wù)端,點(diǎn)擊人人聯(lián)機(jī),然后點(diǎn)擊等待接入;然后打開客戶端,輸入ip和端口,可以修改服務(wù)端的ip和端口,然后客戶端再輸入;
支持聊天功能;
局域網(wǎng)測(cè)試完美運(yùn)行!

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Net;
using?System.Net.Sockets;
using?System.Text;
using?System.Threading;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?FIVE
{
????public?partial?class?Form1?:?Form
????{
????????public?static?int?nWidth=15?;
????????private?int?margin?=?15;
????????private?int?interval?=?20;
????????Point?lastP?=?new?Point(00);//最后下的棋子
????????private?int?chessTurn=1;
????????private?int?winFlag=1;
????????Boolean?turnFlag?=?true;
????????Boolean?conFlag?=?false;
????????Boolean?conFlag_chat?=?false;
????????public?int[]?map?=?new?int[nWidth?nWidth?];
????????Thread?t1;
????????/***********************************************************/
????????private?static?int?server_port2?;?
????????private?static?string?server_ip?;
????????private?static?int?buffer_size?=?1024;
????????private?static?string?data?=?null;
????????private?static?byte[]?receiveBytes?=?new?byte[buffer_size];
????????private?static?string?sendStr?=?“ok“;
????????private?static?int?bytesCount;
????????
????????/***********************************************************/
????????private?static?Socket?client_socket?=?null;
????????private?static?Socket?chess_client_socket=null;
????????private?static?string?clientReceiveStr?=?null;
????????private?static?byte[]?clientSendBytes?=?new?byte[buffer_size];
????????private?static?byte[]?clientReceiveBytes?=?new?byte[buffer_size];
????????/***********************************************************/
????????public?Form1()
????????{
????????????InitializeComponent();
????????????
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????chess_client_socket?=?new?Socket(AddressFamily.InterNetwork?SocketType.Stream?ProtocolType.Tcp);
????????????
????????????
????????}
????????private?void?inicialMap()
????????{
????????????//this.Size?=?new?Size(1?1);
????????????//this.Size?=?new?Size(326?326);
????????????int?tempLocX?=?this.Location.X;
????????????int?tempLocY?=?this.Location.Y;
????????????this.Location?=?new?Point(tempLocX?1000);
????????????this.Location?=?new?Point(tempLocX?tempLocY);//通過移動(dòng)來清空屏幕
????????????//初始化map為-1,0表示黑,1表示白,-1表示沒有
????????????for(int?i=0;i ????????????????for?(int?j?=?0;?j?????????????????{
????????????????????map[ij]?=?-1;
????????????????}
????????????//改變邊框使適應(yīng)
????????????int?offSetX?=?this.Width?-?this.ClientSize.Width;
????????????int?offSetY?=?this.Height?-?this.ClientSize.Height;
????????????this.Width?=?offSetX?+?margin?*?2?+?(interval?)?*?(nWidth?-?1);
????????????this.Height?=?offSetY?+?margin?*?2?+?menuStrip1.Height?+?(interval?)?*?(nWidth?-?1);
????????????//畫圖
????????????Graphics?g?=?this.CreateGraphics();????????????
????????????Pen?p?=?new?Pen(Color.Black??2);
????????????Point?s
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-01-25?15:45??FIVE_CLIENT\
?????文件?????????774??2015-12-21?22:55??FIVE_CLIENT\black.bmp
?????目錄???????????0??2016-01-29?22:26??FIVE_CLIENT\FIVE\
?????文件????????2506??2016-01-25?14:14??FIVE_CLIENT\FIVE.sln
?????文件???????74240??2016-01-25?15:44??FIVE_CLIENT\FIVE.v11.suo
?????文件????????1036??2016-01-30?21:31??FIVE_CLIENT\FIVE\App.config
?????目錄???????????0??2016-01-25?15:45??FIVE_CLIENT\FIVE\bin\
?????目錄???????????0??2016-01-25?15:45??FIVE_CLIENT\FIVE\bin\Debug\
?????文件???????22528??2016-02-27?16:52??FIVE_CLIENT\FIVE\bin\Debug\FIVE.exe
?????文件????????1036??2016-01-30?21:31??FIVE_CLIENT\FIVE\bin\Debug\FIVE.exe.config
?????文件???????50688??2016-02-27?16:52??FIVE_CLIENT\FIVE\bin\Debug\FIVE.pdb
?????文件???????22984??2016-03-01?19:55??FIVE_CLIENT\FIVE\bin\Debug\FIVE.vshost.exe
?????文件????????1036??2016-01-30?21:31??FIVE_CLIENT\FIVE\bin\Debug\FIVE.vshost.exe.config
?????文件?????????490??2013-06-18?20:28??FIVE_CLIENT\FIVE\bin\Debug\FIVE.vshost.exe.manifest
?????文件????????4203??2016-01-29?20:43??FIVE_CLIENT\FIVE\FIVE_CLIENT.csproj
?????文件?????????934??2016-01-30?16:57??FIVE_CLIENT\FIVE\FIVE_CLIENT.sln
?????文件???????38912??2016-02-01?12:45??FIVE_CLIENT\FIVE\FIVE_CLIENT.v11.suo
?????文件???????18822??2016-02-27?16:52??FIVE_CLIENT\FIVE\Form1.cs
?????文件????????9870??2016-01-30?20:53??FIVE_CLIENT\FIVE\Form1.Designer.cs
?????文件????????6663??2016-01-30?20:53??FIVE_CLIENT\FIVE\Form1.resx
?????文件????????2092??2016-01-30?21:54??FIVE_CLIENT\FIVE\Form2.cs
?????文件????????4414??2016-01-30?21:54??FIVE_CLIENT\FIVE\Form2.Designer.cs
?????文件????????5817??2016-01-30?21:54??FIVE_CLIENT\FIVE\Form2.resx
?????目錄???????????0??2016-01-25?15:45??FIVE_CLIENT\FIVE\obj\
?????目錄???????????0??2016-02-27?16:52??FIVE_CLIENT\FIVE\obj\Debug\
?????文件????????5266??2016-01-30?21:16??FIVE_CLIENT\FIVE\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????7013??2016-01-30?21:51??FIVE_CLIENT\FIVE\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????1083??2016-01-25?13:46??FIVE_CLIENT\FIVE\obj\Debug\FIVE.csproj.FileListAbsolute.txt
?????文件????????1014??2016-01-25?13:45??FIVE_CLIENT\FIVE\obj\Debug\FIVE.csproj.GenerateResource.Cache
?????文件????????2209??2015-12-20?22:10??FIVE_CLIENT\FIVE\obj\Debug\FIVE.csprojResolveAssemblyReference.cache
?????文件???????22528??2016-02-27?16:52??FIVE_CLIENT\FIVE\obj\Debug\FIVE.exe
............此處省略77個(gè)文件信息
- 上一篇:用C#寫的高斯濾波源代碼
- 下一篇:曲線擬合&&線性回歸C#)
評(píng)論
共有 條評(píng)論