📄 main.cs
字号:
this.Controls.Add(this.Joinbutton);
this.Controls.Add(this.st);
this.Controls.Add(this.Configbutton);
this.Controls.Add(this.buildGamebutton);
this.Controls.Add(this.pictureBox5);
this.Controls.Add(this.pictureBox4);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.MaximizeBox = false;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "深蓝网络五子棋";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load += new System.EventHandler(this.MainForm_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
usingbmp=oldbmp=new Bitmap(this.pictureBox1.Image);
}
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(onebodyin)
try
{
five.pointx=e.X-21;
five.pointy=e.Y-24;
five.cheesemove(this.pictureBox1,this.Myturn);
}
catch
{
}
}
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.Myturn)
{
if(five.CanDown())
{
try
{
string sendinfor=five.cellx.ToString()+"."+five.celly.ToString()+"."+(five.myturn);
network.Send(sendinfor);
string t1,t2;
this.pictureBox1.Image=five.DownthePoint(out t1,out t2);
this.label1.Text=t1;
this.label2.Text=t2;
// try
// {for(int i=0;i<1;i++)
Myturn=false;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
try
{
if(iswin.Win(five.cellx,five.celly)==5)
{
MessageBox.Show("游戏结束,白方胜利");
this.pictureBox1.Enabled=false;
this.st.Text="游戏结束,白方胜利";
this.timer1.Stop();
this.network.StopListen();
}
if(iswin.Win(five.cellx,five.celly)==-5)
{
MessageBox.Show("游戏结束,黑方胜利");
this.pictureBox1.Enabled=false;
this.timer1.Stop();
this.network.StopListen();
}
}
catch
{
this.st.Text="游戏还没有开始,无法下棋";
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try{network.StopListen();}
catch{}
Application.Exit();
}
private void Configbutton_Click(object sender, System.EventArgs e)
{
config.Show();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.st.Text=this.network.sta;
string nowinfor;
infor=this.network.infor;
if(oldinfor!=infor)//有新消息
{
this.netinforlable.Text=infor;
try
{
int dot=infor.IndexOf(".");
five.cellx=Convert.ToInt32(infor.Substring(0,dot));
nowinfor=infor.Substring(dot+1);
dot=nowinfor.IndexOf(".");
five.celly=Convert.ToInt32(nowinfor.Substring(0,dot));
nowinfor=nowinfor.Substring(dot+1);
five.myturn=Convert.ToBoolean(nowinfor);
string t1,t2;
this.pictureBox1.Image=five.DownthePoint(out t1,out t2); //对方下棋
this.label1.Text=t1;
this.label2.Text=t2;
if(iswin.Win(five.cellx,five.celly)==5)
{
this.st.Text="游戏结束,白方胜利";
this.timer1.Stop();
this.network.StopListen();
this.pictureBox1.Enabled=false;
}
if(iswin.Win(five.cellx,five.celly)==-5)
{
this.st.Text="游戏结束,黑方胜利";
this.timer1.Stop();
this.network.StopListen();
this.pictureBox1.Enabled=false;
}
this.Myturn=true;
}
catch
{
this.st.Text=infor;
try
{
if(infor.IndexOf("加")>0) onebodyin=true;
string joinedip=infor.Substring(0,infor.IndexOf("加"));
IPtextBox.Text=network.IP=joinedip;
}
catch
{
}
}
}
oldinfor=infor;
}
private void NewGamebutton_Click(object sender, System.EventArgs e)
{
five=new gobang();
five.AddBmp(usingbmp,new Bitmap(this.pictureBox4.Image),new Bitmap(this.pictureBox5.Image));
iswin=new IsWin(five.down);
this.pictureBox1.Enabled=true;
this.pictureBox1.Image=oldbmp;
this.pictureBox1.Refresh();
network.Listen();
this.timer1.Start();
this.Myturn=true;
this.onebodyin=false;
this.buildGamebutton.Enabled=false;
this.Joinbutton.Enabled=false;
}
private void Joinbutton_Click(object sender, System.EventArgs e)
{
if(this.IPtextBox.Text=="")
{
MessageBox.Show("对方IP还没有配置,请点击配置");
return;
}
network.IP=IPtextBox.Text;
string sta="";
network.Send(ref sta,NetWork.getmyIP()+"加入游戏!");
if(sta=="")
{
NewGamebutton_Click(null,null);
this.st.Text="加入成功!";
this.onebodyin=true;
this.Joinbutton.Enabled=false;
this.buildGamebutton.Enabled=false;
}
else
{
this.st.Text=sta;
}
this.Myturn=false;
}
private void Rebuildbutton_Click(object sender, System.EventArgs e)
{
MainForm mf=new MainForm();
mf.Show();
mf.IPtextBox.Text=this.IPtextBox.Text;
mf.Joinbutton_Click(null,null);
if(mf.st.Text.IndexOf("拒绝")>0)//加入不成功
{
mf.NewGamebutton_Click(null,null);
}
try
{
this.network.StopListen();
this.timer1.Stop();
}
catch
{
}
this.Hide();
}
private void StopNetbutton_Click(object sender, System.EventArgs e)
{
this.network.StopListen();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -