基本信息
源码名称:C#双人五子棋小游戏源代码 实例下载
源码大小:0.10M
文件格式:.zip
开发语言:C#
更新时间:2013-01-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C#双人五子棋小游戏源代码(完整版) 仅供学习交流使用,请勿用于商业用途
public partial class Form1 : Form { string bzw = "0"; string ks = "0"; string bh = ""; DateTime sj = new DateTime(); wzqDB wzqDB = new wzqDB(); Color col = Color.FromArgb(255,185,0); string jmyi = ""; int ylcs = 0; int gb = 0; int fsjm = 0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Color col1 = Color.FromArgb(255, 165, 0); menuStrip1.BackColor = col1; label5.BackColor = col1; Bitmap bmap;Graphics gph; GraphicsInitial(out gph, out bmap); this.ControlBox = false; ylcs = wzqDB.ReturnCS(); } //鼠标点击事件,在鼠标点击区域绘制五子棋图标 private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { if (groupBox1.Visible == true) { return; } if (ks == "0") { return; } DataTable dttxt = wzqDB.readwzqDB_jsbz(); DataTable dtstrcmd = wzqDB.datatable_select1(dttxt, "bh='" bh "' and jsbz='1'"); if (dtstrcmd.Rows.Count > 0) { MessageBox.Show("该回合已分胜负,不能在继续游戏!", "温馨提示"); return; } DataTable txtsj = wzqDB.readwzqDB_sj(); DataTable dtsj = wzqDB.datatable_select2(txtsj, "sj='" sj "'", "sj desc"); if (dtsj.Rows.Count == 0) wzqDB.writewzqDB_sj(bh "|" sj); Bitmap bmap; Graphics gph; GraphicsInitialPic(out gph, out bmap); DataTable dttxt1 = wzqDB.readwzqDB(); DataTable dt1 = wzqDB.datatable_select1(dttxt1, "bh='" bh "'"); GraphicsInitialDraw(ref gph, ref bmap, dt1); int xzb = 0; int yzb = 0; wzqDB.XYvalue(e.X, e.Y, ref xzb, ref yzb); if (xzb < 50 || xzb > 950 || yzb < 20 || yzb > 620) { return; } DataTable dt2 = wzqDB.datatable_select1(dttxt1, "hzb='" xzb "' and zzb='" yzb "' and bh='" bh "'"); if (dt2.Rows.Count > 0) { pictureBox1.Image = bmap; return; } GraphicsInitialDrawWZQ(ref gph, ref bmap, xzb, yzb); } private void panduan(int xval, int yval) { string yj = wzqDB.panduan(xval, yval, bzw, bh); if (yj == "1") {} else { MessageBox.Show(yj,"温馨提示"); } } //开始或重新开始按钮事件 private void 开始游戏ToolStripMenuItem_Click_1(object sender, EventArgs e) { if (groupBox1.Visible == true) return; menuStrip1.Items[0].Text = "重新开始"; Bitmap bmap; Graphics gph; GraphicsInitialPicTime(out gph, out bmap); } //游戏记录按钮事件 private void 游戏记录ToolStripMenuItem_Click_1(object sender, EventArgs e) { checkedListBox1.BackColor = Color.YellowGreen; groupBox1.BackColor = Color.YellowGreen; checkedListBox1.Items.Clear(); DataTable txtsj = wzqDB.readwzqDB_sj(); DataTable dt1 = wzqDB.datatable_select2(txtsj, "","sj desc"); if (dt1.Rows.Count > 0) { for (int i = 0; i < dt1.Rows.Count; i ) { if (dt1.Rows[i]["sj"].ToString() != "") { checkedListBox1.Items.Add(dt1.Rows[i]["sj"].ToString()); } } groupBox1.Visible = true; } else { MessageBox.Show("目前没有游戏记录", "温馨提示"); } } //游戏记录界面中的继续游戏按钮事件 private void label1_Click(object sender, EventArgs e) { if (checkedListBox1.CheckedItems.Count > 1 || checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("请选择一个游戏开始!", "温馨提示"); return; } groupBox1.Visible = false; string sj1 = checkedListBox1.CheckedItems[0].ToString(); DateTime sj2 = Convert.ToDateTime(checkedListBox1.CheckedItems[0]); sj = sj2; DataTable txtsj = wzqDB.readwzqDB_sj(); DataTable dt1 = wzqDB.datatable_select1(txtsj, "sj='" sj2 "'"); if (dt1.Rows.Count > 0) { int re = 0; int gree = 0; bh = dt1.Rows[0]["bh"].ToString(); DataTable dttxtjsbz = wzqDB.readwzqDB_jsbz(); DataTable dtstrcmd = wzqDB.datatable_select1(dttxtjsbz, "bh='" bh "' and jsbz='1'"); DataTable dttxt = wzqDB.readwzqDB(); DataTable dt2 = wzqDB.datatable_select1(dttxt, "bh='" bh "'"); for (int i = 0; i < dt2.Rows.Count; i ) { if (dt2.Rows[i]["bzw"].ToString() == "0") { re = re 1; } else { gree = gree 1; } } if (dtstrcmd.Rows.Count == 0) { if (re - gree > 0) { bzw = "1"; MessageBox.Show("游戏开始,请黑方先下!", "温馨提示"); } else { bzw = "0"; MessageBox.Show("游戏开始,请红方先下!", "温馨提示"); } } ks = "1"; Bitmap bmap; Graphics gph; GraphicsInitialPic(out gph, out bmap); GraphicsInitialDraw(ref gph, ref bmap, dt2); pictureBox1.Image = bmap; } } //游戏记录界面中的新游戏按钮事件 private void label2_Click(object sender, EventArgs e) { groupBox1.Visible = false; menuStrip1.Items[0].Text = "重新开始"; Bitmap bmap; Graphics gph; GraphicsInitialPicTime(out gph, out bmap); } //游戏记录界面中的返回按钮事件 private void label3_Click(object sender, EventArgs e) { groupBox1.Visible = false; } //游戏记录界面中的清空按钮事件 private void label4_Click(object sender, EventArgs e) { string filePath = AppDomain.CurrentDomain.BaseDirectory; int index = filePath.IndexOf("bin"); filePath = filePath.Substring(0, index); string filePath2 = filePath "wzq.wzq"; File.Delete(filePath2); FileStream fs= File.Create(filePath2); fs.Close(); string filePath1=filePath "wzqjzbz.wzq"; File.Delete(filePath1); FileStream fs1=File.Create(filePath1); fs1.Close(); string filePath3 = filePath "wzqsj.wzq"; File.Delete(filePath3); FileStream fs2=File.Create(filePath3); fs2.Close(); MessageBox.Show("游戏记录清空成功!", "温馨提示"); groupBox1.Visible = false; Graphics gh;Bitmap bm; GraphicsInitial(out gh, out bm); return; } //退出游戏按钮事件 private void 退出游戏ToolStripMenuItem_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } //隐藏游戏按钮事件 private void 隐藏游戏ToolStripMenuItem_Click(object sender, EventArgs e) { gb = 1; if (ylcs == 0 && fsjm ==0) { richTextBox1.Text = ""; label6.Text = "第一次玩该游戏,请写下您的建议吧,谢谢!"; groupBox2.Visible = true; } else this.Close(); } //关闭按钮事件 private void label5_Click(object sender, EventArgs e) { gb = 1; if (ylcs == 0 && fsjm == 0) { richTextBox1.Text = ""; label6.Text = "第一次玩该游戏,请写下您的建议吧,谢谢!"; groupBox2.Visible = true; } else this.Close(); } //意见反馈按钮事件 private void 意见反馈ToolStripMenuItem_Click(object sender, EventArgs e) { fsjm = 1; if (gb == 1) { label6.Text = "第一次玩该游戏,请写下您的建议吧,谢谢!"; } else { label6.Text = "请在这里写下您的建议,非常感谢!"; } groupBox2.Visible = true; richTextBox1.Text = ""; } //发送意见按钮事件 private void label7_Click(object sender, EventArgs e) { if (richTextBox1.Text.Trim() != "") { jmyi = richTextBox1.Text.Trim(); } else { MessageBox.Show("请您填入建议后再发送,谢谢!","温馨提示"); return; } wzqDB.SendJYToEmail(jmyi); groupBox2.Visible = false; if (gb == 1) this.Close(); } //绘制函数 private void GraphicsInitial(out Graphics gph, out Bitmap bmap) { bmap = new Bitmap(1000, 1000);//图片大小 gph = Graphics.FromImage(bmap); gph.SmoothingMode = SmoothingMode.AntiAlias; gph.Clear(col); gph.SmoothingMode = SmoothingMode.AntiAlias; pictureBox1.Image = bmap; } private void GraphicsInitialPic(out Graphics gph, out Bitmap bmap) { bmap = new Bitmap(1000, 1000);//图片大小 gph = Graphics.FromImage(bmap); gph.SmoothingMode = SmoothingMode.AntiAlias; gph.Clear(col); gph.SmoothingMode = SmoothingMode.AntiAlias; for (int i = 0; i <= 20; i ) { gph.DrawLine(Pens.Black, 50, 20 30 * i, 950, 20 30 * i); } for (int j = 0; j <= 30; j ) { gph.DrawLine(Pens.Black, 50 30 * j, 20, 50 30 * j, 620); } } private void GraphicsInitialPicTime(out Graphics gph, out Bitmap bmap) { bmap = new Bitmap(1000, 1000);//图片大小 gph = Graphics.FromImage(bmap); gph.SmoothingMode = SmoothingMode.AntiAlias; gph.Clear(col); gph.SmoothingMode = SmoothingMode.AntiAlias; //画网格线 for (int i = 0; i <= 20; i ) { gph.DrawLine(Pens.Black, 50, 20 30 * i, 950, 20 30 * i); } for (int j = 0; j <= 30; j ) { gph.DrawLine(Pens.Black, 50 30 * j, 20, 50 30 * j, 620); } pictureBox1.Image = bmap; ks = "1"; sj = DateTime.Now; bh = DateTime.Now.Year.ToString() DateTime.Now.Month.ToString() DateTime.Now.Day.ToString() DateTime.Now.Hour.ToString() DateTime.Now.Minute.ToString() DateTime.Now.Second.ToString(); } private void GraphicsInitialDraw(ref Graphics gph, ref Bitmap bmap, DataTable dt1) { if (dt1.Rows.Count > 0) { for (int m = 0; m < dt1.Rows.Count; m ) { if (dt1.Rows[m]["bzw"].ToString() == "0") { gph.DrawEllipse(Pens.Red, Convert.ToInt16(dt1.Rows[m]["hzb"].ToString()) - 7, Convert.ToInt16(dt1.Rows[m]["zzb"].ToString()) - 7, 15, 15); gph.FillEllipse(new SolidBrush(Color.Red), Convert.ToInt16(dt1.Rows[m]["hzb"].ToString()) - 7, Convert.ToInt16(dt1.Rows[m]["zzb"].ToString()) - 7, 15, 15); } else { gph.DrawEllipse(Pens.Black, Convert.ToInt16(dt1.Rows[m]["hzb"].ToString()) - 7, Convert.ToInt16(dt1.Rows[m]["zzb"].ToString()) - 7, 15, 15); gph.FillEllipse(new SolidBrush(Color.Black), Convert.ToInt16(dt1.Rows[m]["hzb"].ToString()) - 7, Convert.ToInt16(dt1.Rows[m]["zzb"].ToString()) - 7, 15, 15); } } } } private void GraphicsInitialDrawWZQ(ref Graphics gph, ref Bitmap bmap,int xzb,int yzb) { Pen penrb; Color colorrb; if (bzw == "0") { penrb = Pens.Red; colorrb = Color.Red; } else { penrb = Pens.Black; colorrb = Color.Black; } gph.DrawEllipse(penrb, xzb - 7, yzb - 7, 15, 15); gph.FillEllipse(new SolidBrush(colorrb), xzb - 7, yzb - 7, 15, 15); pictureBox1.Image = bmap; string txtstring = xzb "|" yzb "|" bzw "|" bh "|" DateTime.Now; wzqDB.writewzqDB(txtstring); panduan(xzb, yzb); if (bzw == "0") { bzw = "1"; } else { bzw = "0"; } } }