求C#的小程序代码

求几个小程序的代码... 求几个小程序的代码 展开
 我来答
hujiansg
推荐于2016-04-08 · TA获得超过232个赞
知道小有建树答主
回答量:302
采纳率:0%
帮助的人:0
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace RIF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public class Arr
{
public int[,] arr = new int[25, 25];
public bool win;
}

Arr a = new Arr();
bool cc = true;

public void PaintLab()
{
Bitmap image = new Bitmap(300,300);
Graphics g = Graphics.FromImage(image);
g.Clear(Color.Tan);
Pen pen = new Pen(Color.Black, 1);
int i, j;
i = j = 0;
while (i <= 300)
{
g.DrawLine(pen, i, 0, i, 300);
i = i + 20;
}
while (j <= 300)
{
g.DrawLine(pen, 0, j, 300, j);
j = j + 20;
}
img.Image = image;

}

private void Form1_Load(object sender, EventArgs e)
{
PaintLab();
}

private void img_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int x = e.X;
int y = e.Y;
Graphics g = Graphics.FromImage(img.Image);
Brush pen;
int myx = x / 20;
int myy = y / 20;
if (a.arr[myx, myy] != 0)
{
MessageBox.Show("这里已经有棋子了!");
return;
}
else
{
if (cc)
{
pen = new SolidBrush(Color.White);
cc = false;
a.arr[myx, myy] = 1;
}
else
{
pen = new SolidBrush(Color.Black);
cc = true;
a.arr[myx, myy] = 2;
}
g.FillEllipse(pen, myx * 20 + 2, myy * 20 + 2, 16, 16);
img.Invalidate();
int z = IsWin(myx, myy, cc);
if (z != 0)
{
if (z == 1)
{
MessageBox.Show("白色获胜!");
}
else
{
MessageBox.Show("黑色获胜!");
}
img.Enabled = false;
}
}
}
else
{
MessageBox.Show("本程序由Cantahu开发","作者信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}

}

private int IsWin(int x, int y,bool cc)
{
int m, n, count, p, q;
int val = 0;
bool win=false;
if (cc)
{
val = 2;
}
else
{
val = 1;
}

#region 横向判断
count = 1;
int f = 0;
m = x-1;
n = x+1;
while (1==1)
{
if (count == 5)
{
win = true;
break;
}
else if (f == 5)
{
win = false;
break;

}
if (m >= 0 && n <= 300)
{
if (a.arr[m, y] == val)
{
count = count + 1;
m = m - 1;
}
if (a.arr[n, y] == val)
{
count = count + 1;
n = n + 1;
}
}
f = f + 1;
}
if (win)
{
return val;
}
#endregion

#region 纵向判断
m = y - 1;
n = y + 1;
f = 0;
count = 1;
while (1 == 1)
{
if (count == 5)
{
win = true;
break;
}
if (f == 5)
{
win = false;
break;
}
if (m >= 0 && n <= 300)
{
if(a.arr[x,m]==val)
{
count = count + 1;
m = m - 1;
}
if(a.arr[x,n]==val)
{
count = count + 1;
n = n + 1;
}
}
f = f + 1;

}
if (win)
{
return val;
}
#endregion

#region 左斜向判断
count = 1;
f = 0;
m = x - 1;
n = y - 1;
p = x + 1;
q = y + 1;
while (1 == 1)
{
if (count == 5)
{
win = true;
break;
}
if (f == 5)
{
win = false;
break;
}
if (m >= 0 && n >= 0 && p <= 300 && q <= 300)
{
if (a.arr[m, n] == val)
{
count = count + 1;
m = m - 1;
n = n - 1;
}
if (a.arr[p, q] == val)
{
count = count + 1;
p = p + 1;
q = q + 1;
}
}
f = f + 1;
}
if (win)
{
return val;
}
#endregion

#region 右斜向
count = 1;
f = 0;
m = x - 1;
n = y + 1;
p = x + 1;
q = y - 1;
while (1 == 1)
{
if (count == 5)
{
win = true;
break;
}
if (f == 5)
{
win = false;
break;
}
if (m >= 0 && n <= 300 && p <= 300 && q >= 0)
{
if (a.arr[m, n] == val)
{
count = count + 1;
m = m - 1;
n = n + 1;
}
if (a.arr[p, q] == val)
{
count = count + 1;
p = p + 1;
q = q - 1;
}
}
f = f + 1;
}
if (win)
{
return val;
}
#endregion

return 0;
}

private void Btnstart_Click(object sender, EventArgs e)
{
img.Enabled = true;

PaintLab();
}

private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}

}
}
这是我自己写的 五子棋代码 希望对你有帮助
上海里艾
2024-10-22 广告
里艾传播,是基于受众洞察,整合多种营销方式,聚焦社交网络及搜索引擎,协助品牌和产品扩大其社会影响力的新形态传播公司。从品牌渠道招商、新品发布造势、电商节日大促等方面为合作品牌搭建一站式内容传播服务,从而满足品牌在不同阶段的营销需求,致力于成... 点击进入详情页
本回答由上海里艾提供
代任岑安安
2020-05-26 · TA获得超过3803个赞
知道大有可为答主
回答量:3171
采纳率:31%
帮助的人:206万
展开全部
锐英源有专业的C#指导,保证掌握工作能力,写上万行软件。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
耿墨析新颖
2020-03-31 · TA获得超过3935个赞
知道大有可为答主
回答量:3081
采纳率:25%
帮助的人:192万
展开全部
那你也得把题发出来啊
。。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
每天吃一头猪
2019-07-06 · TA获得超过1490个赞
知道答主
回答量:535
采纳率:43%
帮助的人:12.7万
展开全部
这个小不到50行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int i,j,k;
string[] xiushi= new string[]
{ "聪明的","善良的","热情的","沉默的","害羞的","勤奋的","固执的","魅惑的",
"调皮的","美貌的","冷静的","坚强的","勇敢的","不朽的","大胆的","乐观的","漂亮的","温柔的"};
string[] name = new string[]
{ "阿米莉娅","塞亚","雪儿","阿黛拉","克里斯汀","尤娜","夏娜","艾格文","蒂娜","安妮","杰西卡","卢西娅","瓦娜斯","布兰切特","雅典娜","伊丽萨","娜莎"};
int[] num = new int[18] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11,12,13,14,15,16,17};
Random ra = new Random();
Console.WriteLine("输入1表示继续生成随机名字,输入2表示退出,请输入数字:");

for (k=1;;k++)
{

string m = Console.ReadLine();
if (m == "1")
{
i = ra.Next(num[0], num[17]);

Console.Write(xiushi[i]);
j = ra.Next(num[0], num[17]);
Console.WriteLine(name[j]);

}
else if (m == "2")
break;
else
Console.WriteLine("输入错误!");
}

}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式