1、c#五子棋游戏/ button1开始游戏/ button2重新开始/ panal1游戏界面using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Drawing.Imaging;using System.Drawing.Drawing2D;using System.Thread
2、ing;namespace 图像处理 public partial class Form1 : Form xyz class1=new xyz (); static int, count = new int15, 15; private enum kind white, black ; private kind flag=kind.black ; private Bitmap bm = new Bitmap(900,700); public Form1() InitializeComponent(); private class xyz public int xget;set ; public
3、 int yget;set ; public int z get; set; public int position get; set; public int lose get; set; private bool judgewin() int pro=1; int k = 1; for(int i=0;i15;i+) for(int j=0;j15;j+) if (counti, j != 0) while (true)/往右边遍历 if (i + k = 15 | j = 15) pro = 1; k = 1; break; if (counti + k, j = counti, j) p
4、ro+; k+; else pro = 1; k = 1; break; if (pro = 5) if (counti, j = 1) MessageBox.Show(您赢了!); else MessageBox.Show(您输了!); return true; while (true)/往右下遍历 if (i + k = 15 | i + k = 15 | j + k = 5) if (counti, j = 1) MessageBox.Show(您赢了!); else MessageBox.Show(您输了!); return true; while (true)/往下边遍历 if (i
5、 =15 | j + k = 15|i0|j+k= 5) if (counti, j = 1) MessageBox.Show(您赢了!); else MessageBox.Show(您输了!); return true; while (true)/往左下遍历 if (i - k = 15 | i - k = 15 | j + k = 5) if (counti, j = 1) MessageBox.Show(您赢了!); else MessageBox.Show(您输了!); return true; return false; private void machine()/机器落子 cla
6、ss1 = new xyz(); int pro=1; int k = 1; for (int i = 0; i 15; i+) for (int j = 0; j 15;j+ ) if (counti, j != 0) while (true)/往下边遍历 if (i 15 & j + k = 0 & j + k = 0) /不越界 if (counti, j + k = counti, j) pro+; k+; else if (counti, j + k != 0 & (j - 1) 0) /上面是墙 pro = 1; k = 1; break; if (counti, j + k !=
7、 0 & counti, j - 1 != 0) pro = 1; k = 1; break; if (counti, j + k != 0) pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = pro; class1.position = 3; class1.lose = -1; k = 1; pro = 1; break; if (class1.z pro) class1.x = i; class1.y = j; class1.z = pro; class1.position = 3; k = 1; pro
8、 = 1; break; else/什么都不做 k = 1; pro = 1; break; else/下面越界 if (counti, j -1 != 0) /上面是子 pro = 1; k = 1; break; pro-; if (class1.z = 0 & i + k = 0 & j 15) if (counti + k, j = counti, j) pro+; k+; else if (counti + k, j != 0 & i - 1 0) /左边是墙 pro = 1; k = 1; break; if (counti + k, j != 0 & counti - 1, j
9、!= 0) pro = 1; k = 1; break; if (counti + k, j != 0) pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = pro; class1.position = 1; class1.lose = -1; k = 1; pro = 1; break; if (class1.z pro) class1.x = i; class1.y = j; class1.z = pro; class1.position = 1; k = 1; pro = 1; break; else/什
10、么都不做 k = 1; pro = 1; break; else if (counti-1, j != 0) /左边是子 pro = 1; k = 1; break; pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = pro; class1.position = 1; class1.lose = -1; k = 1; pro = 1; break; else/什么都不做 k = 1; pro = 1; break; while (true)/往右下遍历 if (i + k = 0 & j + k = 0) i
11、f (counti + k, j + k = counti, j) pro+; k+; else if (counti + k, j + k != 0 & (i - 1 0 | j - 1 0) /左上是墙 pro = 1; k = 1; break; if (counti + k, j + k != 0 & counti - 1, j - 1 != 0) pro = 1; k = 1; break; if (counti + k, j + k != 0) pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = p
12、ro; class1.position = 2; class1.lose = -1; k = 1; pro = 1; break; if (class1.z pro) class1.x = i; class1.y = j; class1.z = pro; class1.position = 2; k = 1; pro = 1; break; else/什么都不做 k = 1; pro = 1; break; else if (counti -1, j -1 != 0 ) /左上是墙 pro = 1; k = 1; break; pro-; if (class1.z pro) /记录点 clas
13、s1.x = i; class1.y = j; class1.z = pro; class1.position = 2; class1.lose = -1; k = 1; pro = 1; break; else/什么都不做 k = 1; pro = 1; break; while (true)/往左下遍历 if (i - k = 0 & j + k = 0) if (counti - k, j + k = counti, j) pro+; k+; else if (counti - k, j + k != 0 & (i + 1 15 | j - 1 0) pro = 1; k = 1; br
14、eak; if (counti - k, j + k != 0 & counti + 1, j - 1 != 0) pro = 1; k = 1; break; if (counti - k, j + k != 0) pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = pro; class1.position = 4; class1.lose = -1; k = 1; pro = 1; break; if (class1.z pro) class1.x = i; class1.y = j; class1.z =
15、 pro; class1.position = 4; k = 1; pro = 1; break; else/什么都不做 k = 1; pro = 1; break; else if (counti +1, j -1 != 0) pro = 1; k = 1; break; pro-; if (class1.z pro) /记录点 class1.x = i; class1.y = j; class1.z = pro; class1.position = 4; class1.lose = -1; k = 1; pro = 1; break; else/什么都不做 k = 1; pro = 1;
16、break; if (class1.position = 1) if (class1.lose = -1) class1.x-; else class1.x += class1.z; if(class1.position =2) if (class1.lose = -1) class1.x-; class1.y-; else class1.x += class1.z; class1.y += class1.z; if (class1.position = 3) if (class1.lose = -1) class1.y-; else class1.y += class1.z; if(clas
17、s1 .position=4) if (class1.lose = -1) class1.x+; class1.y-; else class1.x -= class1.z; class1.y += class1.z; this.richTextBox1.AppendText(电脑落子横 + (class1.x + 1) + ,竖 + (class1.y + 1) + n); paintwhite(new Rectangle(class1.x*40-15, class1.y*40-15, 30, 30); countclass1.x, class1.y = 2; if (judgewin() =
18、 true) return; flag = kind.black; private void paintwhite(Rectangle rect) Graphics g = Graphics.FromImage(bm); g.TranslateTransform(20, 20); g.FillEllipse(new LinearGradientBrush (new Point (rect.X,rect .Y),new Point (rect.X +15,rect .Y +15),Color .FromArgb (250,Color .White),Color .FromArgb (255,Co
19、lor.White), rect); private void paintblack(Rectangle rect) Graphics g = Graphics.FromImage(bm); g.TranslateTransform(20, 20); g.FillEllipse(new LinearGradientBrush(new Point(rect.X, rect.Y), new Point(rect.X + 15, rect.Y + 15), Color.FromArgb(250, Color.Black), Color.FromArgb(200, Color.Black ), rec
20、t); private void paintpanel() Graphics g=Graphics .FromImage (bm); g.TranslateTransform(20, 20); g.DrawRectangle(new Pen(Color.Black, 3), 0, 0,560,560); for (int i = 1; i = 14; i+) g.DrawLine(new Pen(Color.Black, 1), new Point(i * 40, 0), new Point(i * 40, 560); g.DrawLine(new Pen(Color.Black, 1), n
21、ew Point(0, i * 40), new Point(560, i * 40); private void button1_Click(object sender, EventArgs e) this.button2.Visible = false; for (int i = 0; i 15; i+) for (int j = 0; j 15; j+) counti, j = 0; paintpanel(); this.pictureBox1.BackgroundImage = null; this.pictureBox1.BackgroundImage = bm; private v
22、oid pictureBox1_MouseClick(object sender, MouseEventArgs e) if (this.pictureBox1.BackgroundImage = null) return; if (flag = kind.white) return; int X,Y; if (Convert .ToInt16(e.X) 20 | Convert .ToInt16(e.Y) 20) return; if (Convert .ToInt16(e.X-20) % 40 20) X = (Convert .ToInt16(e.X-20) / 40) * 40; el
23、se X = (Convert .ToInt16(e.X-20) / 40 + 1) * 40; if (Convert .ToInt16(e.Y-20) % 40 20) Y = (Convert .ToInt16(e.Y-20) / 40) * 40; else Y = (Convert .ToInt16(e.Y-20) / 40 + 1) * 40; /人落子记为1 if (countX / 40, Y / 40 = 1) return; countX / 40, Y / 40 = 1; this.richTextBox1.AppendText(您落子横 + (X / 40 + 1).T
24、oString () + ,竖 + (Y / 40 + 1)+n); paintblack(new Rectangle(X-15, Y-15, 30, 30); this.pictureBox1.BackgroundImage = null; this.pictureBox1.BackgroundImage = bm; flag = kind.white ; if (judgewin() = true) return; machine(); private void pictureBox1_BackgroundImageChanged(object sender, EventArgs e) /*if (flag = kind.white) Thread th = new Thread(new ThreadStart(machine); th.Start(); */ private void button2_Click(object sender, EventArgs e) this.button1.Visible = false; this.button2.Visible = tru
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1