</pre>这个是兰州交大的CShap(C#)作业题,刚开始自己陷入误区了,第一天做时没耐心了,今天花了2个多小时写了这个L型骨牌的覆盖程序<p></p><p>命令行的骨牌实现可以在我的博客里找到</p><p>下面是图形化界面的L型骨牌实现</p><p>具体实现思路:</p><p>利用矩形数组和二维数组,核心的算法是二维数组也就是命令行的L型骨牌,然后利用数值的不同画出不同颜色的方块</p><p></p><p>核心的算法</p><p></p><pre name="code" class="csharp">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace L骨牌
{
public partial class Form1 : Form
{
Graphics g;
//定义画刷数组
// SolidBrush[] brush = { new SolidBrush(Color.Gold), new SolidBrush(Color.Black), new SolidBrush(Color.Yellow), new SolidBrush(Color.DarkBlue), new SolidBrush(Color.Purple), new SolidBrush(Color.Red), new SolidBrush(Color.Blue) ,new SolidBrush(Color.DarkCyan),new SolidBrush(Color.Crimson),new SolidBrush(Color.Green),new SolidBrush(Color.Honeydew),new SolidBrush(Color.LawnGreen)};
//定义一个数计数brush
// int count = 0;
//二位数组
int[,] board;
//对应的方块
Rectangle[,] rect;
//k
int k;
//x
int x;
//y
int y;
//2^K
int num;
//画线开始的坐标
int x0, y0;
//递归层数
int n = 1;
//每次画出的L型骨牌
int next;
//定时器
System.Timers.Timer t;
//获取一个不同的画刷
public SolidBrush getSolidBrush()
{
long tick = DateTime.Now.Ticks;
Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
SolidBrush sb = new SolidBrush(Color.FromArgb(ran.Next(255),ran.Next(255),ran.Next(255)));
return sb;
}
//构造函数
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
}
public void resetX0Y0()
{
x0 = 10;
y0 = 10;
}
public void initValue()
{
k = Int32.Parse(textBox_K.Text);
x = Int32.Parse(textBox_x.Text);
y = Int32.Parse(textBox_Y.Text);
num = (int)Math.Pow(2, k);
//二维数组
board = new int[num, num];
//对应的方块
rect = new Rectangle[num, num];
//重置x0和y0
resetX0Y0();
//
next = 1;
}
public void drawInitLine()
{
//横向画
C#图形化界面--L型骨牌
最新推荐文章于 2024-08-16 00:21:21 发布
本文介绍如何利用VS2013进行C#图形化界面开发,展示了一个L型骨牌的游戏项目。读者可以点击提供的下载链接获取源代码。
摘要由CSDN通过智能技术生成