⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blockinfoarr.cs

📁 陈广老师讲课的源代码
💻 CS
字号:
using System;
using System.Windows.Forms;
using System.Text;
using System.Collections;
using System.Drawing;

namespace MyTetris
{
    class BlockInfoArr
    {
        private ArrayList info = new ArrayList();
        private int _length = 0;
        public int Length
        {
            get {
                return _length;
            }
        }
        public BlockInfo this[int index]    //根据下标返回一个BlockInfo
        {
            
            get {
                return (BlockInfo)info[index];
            }
        }

        public string this[string id]   // 根据 一个字符串的id值下标,给相应id的颜色赋值
        {
            set { 
                if(value=="")
                {
                    return; 
                }
                for (int i = 0; i < info.Count;i++ )
                {
                    if(((BlockInfo)info[i]).GetIdStr()==id)
                    {
                        try { 
                            ((BlockInfo)info[i]).Bcolor=Color.FromArgb(Convert.ToInt32(value));
                        }catch(FormatException){
                            MessageBox.Show("获取初始信息出错,请删除Config.xml文件,并重新启动程序!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
         public BitArray StrToBit(string id)    //将字符串信息(方块)转换成BitArray
        { 
            if(id.Length!=25)
            {
                throw new FormatException("方块样式不合法StrToBit!请删除Config.xml文件,并重新启动程序!");
            }
            BitArray ba = new BitArray(25);
            for (int i = 0; i < 25;i++ )
            {
                ba[i] = (id[i] == '0') ? false : true;
            }
            return ba;
        }

        public void AddBlock(BitArray ba,Color bColor)
        {
            if (ba.Length != 25)
            {
                throw new FormatException("方块样式不合法AddBlock!请删除Config.xml文件,并重新启动程序!");
            }
            info.Add(new BlockInfo(ba,bColor));     //为方块数组添加一个新的方块样式
            _length ++;       
        }

        public void AddBlock(string id,string bColor)
        {
            Color temp;
            if (bColor == "")
            {
                temp = Color.Empty;
            }
            else
            {
                temp = Color.FromArgb(Convert.ToInt32(bColor)); //将字符串转换成颜色
            }
            info.Add(new BlockInfo(StrToBit(id), temp));     //将字符串信息(方块)转换成BitArray,然后添加一个新的记块样式
            _length++;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -