예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            InfoArr info = new InfoArr();

            foreach (ListViewItem item in lsvBlockSet.Items)
            {
                info.Add(item.SubItems[0].Text, item.SubItems[1].Text);
            }

            config.BlockInfo = info;
            config.UpKey     = (Keys)tbToUp.Tag;
            config.DownKey   = (Keys)tbToDown.Tag;
            config.LeftKey   = (Keys)tbToleft.Tag;
            config.RightKey  = (Keys)tbToRight.Tag;
            config.DeasilKey = (Keys)tbDeasil.Tag;
            config.ContraKey = (Keys)tbContra.Tag;

            config.BlockNumX  = int.Parse(tbBlockNumX.Text);
            config.BlockNumY  = int.Parse(tbBlockNumY.Text);
            config.BlockCol   = int.Parse(tbBlockColNum.Text);
            config.BlockColor = lbBlockBlackColor.BackColor;
            config.SaveToXmlFile();
        }
예제 #2
0
        public void LoadFromXmlFile()
        {
            XmlTextReader reader;

            if (File.Exists("BlockSet.xml"))
            {
                reader = new XmlTextReader("BlockSet.xml");
            }
            else
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                Stream   sm  = asm.GetManifestResourceStream("tetris.BlockSet.xml");
                reader = new XmlTextReader(sm);
            }

            string key = "";

            try
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "ID")
                        {
                            key = reader.ReadElementString().Trim();
                            _blockInfo.Add(key, "");
                        }
                        else if (reader.Name == "Color")
                        {
                            _blockInfo[key] = reader.ReadElementString().Trim();
                        }
                        else if (reader.Name == "UpKey")
                        {
                            _upKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "DownKey")
                        {
                            _downKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "LeftKey")
                        {
                            _leftKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "RightKey")
                        {
                            _rightKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "DeasilKey")
                        {
                            _deasilKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "ContraKey")
                        {
                            _contraKey = (Keys)Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "BlockNumX")
                        {
                            _blockNumX = Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "BlockNumY")
                        {
                            _blockNumY = Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "BlockColnum")
                        {
                            _blockColnum = Convert.ToInt32(reader.ReadElementString().Trim());
                        }
                        else if (reader.Name == "BlockColor")
                        {
                            _blockColor = Color.FromArgb(Convert.ToInt32(reader.ReadElementString().Trim()));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }