《c#网络五子棋源码范例》由会员分享,可在线阅读,更多相关《c#网络五子棋源码范例(10页珍藏版)》请在金锄头文库上搜索。
1、using System;using System.Windows.Forms;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.IO;using System.Net.Sockets;using System.Threading;using System.Diagnostics;using System.Net;using Microsoft.Win32;namespace WuZi
2、Qi public partial class Form1 : Form public Form1() InitializeComponent(); public Button, buttons;/棋盘数组 public bool gamer1 = false, gamer2 = false,netcanplay=false ;/ 两个玩家是否允下棋,连网状态时是否允许下棋 public bool gamer1click = new bool 225;/玩家一所下的棋 public bool gamer2click = new bool225;/玩家二所下的棋 public static in
3、t port = 3332;/连接端口 public string myipadd = ;/本机IP public Thread li = null;/创建监听进程 public Thread se = null;/创建发送上线信息进程 public Thread sen = null;/创建发送信息进程 public string sendmessage = ;/要发送的信息 public bool canplay = false;/是否可以开始游戏 private void Form1_Load(object sender, EventArgs e) cshqp(); /初始化棋盘 / /
4、 初始化棋盘 / / 初始化是否成功 public bool cshqp() groupBox1.Controls.Clear(); buttons = new Button15,15; int i = 0; for (int x = 0; x / 下棋 / / 要下棋子的索引 / public bool xiaqi(int index) /MessageBox.Show(index.ToString(); foreach (Button b in buttons) if (b.TabIndex = index ) bool check = false; if (gamer1clickb.Ta
5、bIndex = true) check = true; if (gamer2clickb.TabIndex = true) check = true; if (check != true) if (gamer1 = true) gamer1clickb.TabIndex = true; b.Image = global:WuZiQi.Properties.Resources.black; canxiaqi(gamer2); if (netpk.Checked = false | Asservice.Checked = true) if (checkwin(gamer1) label11.Te
6、xt = 赢家:玩家一 + player1.Text; MessageBox.Show(恭喜玩家一: + player1.Text + ,你赢了!, 会飞的鱼提醒, MessageBoxButtons.OK, MessageBoxIcon.Information); canxiaqi(); send(win恭喜玩家一: + player1.Text + ,你赢了!); else if (gamer2 = true) gamer2clickb.TabIndex = true; b.Image = global:WuZiQi.Properties.Resources.write; canxiaqi
7、(gamer1); if (netpk.Checked = false | Asservice.Checked = true) if (checkwin(gamer2) label11.Text = 赢家:玩家二 + player2.Text; MessageBox.Show(恭喜玩家二: + player2.Text + ,你赢了!, 会飞的鱼提醒, MessageBoxButtons.OK, MessageBoxIcon.Information); canxiaqi(); send(win恭喜玩家二: + player2.Text + ,你赢了!); else check = false;
8、 MessageBox.Show(这个位置上不能下棋!, 会飞的鱼提醒, MessageBoxButtons.OK, MessageBoxIcon.Warning); /MessageBox.Show(b.TabIndex.ToString(); return true; return false; /开始游戏 private void start_Click(object sender, EventArgs e) /if (player1.Text = | player2.Text = ) / / MessageBox.Show(请输入你的名字!, 会飞的鱼提醒, MessageBoxButtons.OK, MessageBoxIcon.Warning); / /else / if (canplay = true | netpk.Checked = false) if (radioButton1.Checked = true) canxiaqi(gamer1); else canxiaqi(gamer2)