示例#1
0
        /// <summary>
        /// The functionality of this event handler for "Open Strategy File" button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uxOpen_Click(object sender, EventArgs e)
        {
            try
            {
                DecisionTree tree = null;
                if (uxOpenDialog.ShowDialog() == DialogResult.OK)
                {
                    uxList.Items.Clear();
                    uxConfirm.Enabled = false;
                    using (StreamReader sr = new StreamReader(uxOpenDialog.FileName))
                    {
                        XmlReaderSettings settings = new XmlReaderSettings();
                        settings.IgnoreComments   = true;
                        settings.IgnoreWhitespace = true;
                        XmlReader reader = XmlReader.Create(sr, settings);
                        reader.Read();

                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            throw new IOException("Invalid XML node type found");
                        }
                        else if (reader.Name != "node")
                        {
                            throw new IOException("An element has a name other than node");
                        }
                        else
                        {
                            tree = new DecisionTree(reader);
                        }
                    }
                    MessageBox.Show("File successfully read.");
                    _strategy     = tree;
                    uxNew.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// An event handler for the "Confirm Hits" button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uxConfirm_Click(object sender, EventArgs e)
        {
            if (_play < _maxPlays)
            {
                _guess = _guess.GetChild(Convert.ToInt32(uxBlackNumeric.Value), Convert.ToInt32(uxWhiteNumeric.Value));
            }
            else
            {
                _guess = null;
            }
            int RealPlay = _play - 1;// the number of the real play from 0 to 9

            uxList.Items[RealPlay].SubItems.Add(uxBlackNumeric.Value.ToString());
            uxList.Items[RealPlay].SubItems.Add(uxWhiteNumeric.Value.ToString());
            decimal black = uxBlackNumeric.Value;

            if (black != 4 && _guess != null)
            {
                _play++;
                ListViewItem item = uxList.Items.Add((_play).ToString());
                item.SubItems.Add(_guess.Guess);
            }
            else if (black == 4)
            {
                uxList.Items[RealPlay].SubItems.Add(uxBlackNumeric.Value.ToString());
                uxList.Items[RealPlay].SubItems.Add(uxWhiteNumeric.Value.ToString());
                uxConfirm.Enabled = false;
                uxOpen.Enabled    = true;
                uxNew.Enabled     = true;
            }
            else
            {
                uxList.Items[RealPlay].SubItems.Add(uxBlackNumeric.Value.ToString());
                uxList.Items[RealPlay].SubItems.Add(uxWhiteNumeric.Value.ToString());
                uxConfirm.Enabled = false;
                uxOpen.Enabled    = true;
                uxNew.Enabled     = true;
                GiveUp();
            }
        }