C#图形化界面--L型骨牌

</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()
        {
            //横向画
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值