本人刚学.net是个小菜鸟,论坛有些相关的代码帖子我都看不大明白,有段关于五子棋的代码如下:我用GDI的方式画了一下。希望在这个基础上后面加上可以判定输赢的方法...希望哪位专家高手看到了帮我一下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 五子棋
{
public partial class 五子棋 : Form
{
public 五子棋()
{
InitializeComponent();
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Blue);
for (int i = 0; i < 17; i++)
{
g.DrawLine(p, 10, 10 + i * 30, 490, 10 + i * 30);
g.DrawLine(p, 10 + i * 30, 10, 10 + i * 30, 490);
}
Brush b1=new SolidBrush(Color.Black);
Brush b2 = new SolidBrush(Color.White);
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 17; j++)
{
if (ch[i, j] == 1)
g.FillEllipse(b1, i * 30, j * 30, 20, 20);
else if(ch[i, j] == -1)
g.FillEllipse(b2, i * 30, j * 30, 20, 20);
}
}
}
int[,] ch = new int[17, 17];
int player = 1;
private void 五子棋_MouseClick(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Brush br;
if (e.X <= 490 && e.Y <= 490 && ch[e.X / 30, e.Y / 30] == 0)
{
if (player == 1)
br = new SolidBrush(Color.Black);
else
br = new SolidBrush(Color.White);
int x = (e.X) / 30 * 30;
int y = (e.Y) / 30 * 30;
g.FillEllipse(br, x, y, 20, 20);
ch[e.X / 30, e.Y / 30] = player;
player = player == 1 ? -1 : 1;
}
} private void 五子棋_Load(object sender, EventArgs e)
{
//清空
for (int i = 0; i < 17; i++)
for (int j = 0; j < 17; j++)
ch[i, j] = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 五子棋
{
public partial class 五子棋 : Form
{
public 五子棋()
{
InitializeComponent();
} private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Blue);
for (int i = 0; i < 17; i++)
{
g.DrawLine(p, 10, 10 + i * 30, 490, 10 + i * 30);
g.DrawLine(p, 10 + i * 30, 10, 10 + i * 30, 490);
}
Brush b1=new SolidBrush(Color.Black);
Brush b2 = new SolidBrush(Color.White);
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 17; j++)
{
if (ch[i, j] == 1)
g.FillEllipse(b1, i * 30, j * 30, 20, 20);
else if(ch[i, j] == -1)
g.FillEllipse(b2, i * 30, j * 30, 20, 20);
}
}
}
int[,] ch = new int[17, 17];
int player = 1;
private void 五子棋_MouseClick(object sender, MouseEventArgs e)
{
Graphics g = this.CreateGraphics();
Brush br;
if (e.X <= 490 && e.Y <= 490 && ch[e.X / 30, e.Y / 30] == 0)
{
if (player == 1)
br = new SolidBrush(Color.Black);
else
br = new SolidBrush(Color.White);
int x = (e.X) / 30 * 30;
int y = (e.Y) / 30 * 30;
g.FillEllipse(br, x, y, 20, 20);
ch[e.X / 30, e.Y / 30] = player;
player = player == 1 ? -1 : 1;
}
} private void 五子棋_Load(object sender, EventArgs e)
{
//清空
for (int i = 0; i < 17; i++)
for (int j = 0; j < 17; j++)
ch[i, j] = 0;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货