Ejemplo n.º 1
0
 private void btnAdd_Click(object sender, System.EventArgs e)
 {
     Question q = new Question();
     q.Text = this.txtQuestion.Text;
     for (int i = 0; i < this.txtAnswers.Lines.Length; i++) {
         if (this.txtAnswers.Lines[i] != "") {
             string[] line = this.txtAnswers.Lines[i].Split('|');
             Answer a = new Answer(line[0], Int32.Parse(line[1]));
             q.Answers.Add(a);
         }
     }
     this.questions.Add(q);
     this.listQuestions.Items.Add(q.Text);
     this.txtAnswers.Clear();
     this.txtQuestion.Clear();
     this.txtQuestion.Focus();
 }
Ejemplo n.º 2
0
 public override void CopyTo(Answer[] array)
 {
     m_collection.CopyTo(array);
 }
Ejemplo n.º 3
0
 public override bool Contains(Answer x)
 {
     return m_collection.Contains(x);
 }
Ejemplo n.º 4
0
            public override void Insert(int pos, Answer x)
            {
                rwLock.AcquireWriterLock(timeout);

                try {
                    collection.Insert(pos,x);
                }
                finally {
                    rwLock.ReleaseWriterLock();
                }
            }
Ejemplo n.º 5
0
 public abstract void DisplayAnswer(Answer answer);
Ejemplo n.º 6
0
            public override int IndexOf(Answer x)
            {
                int result = 0;
                rwLock.AcquireReaderLock(timeout);

                try {
                    result = collection.IndexOf(x);
                }
                finally {
                    rwLock.ReleaseReaderLock();
                }

                return result;
            }
Ejemplo n.º 7
0
            public override bool Contains(Answer x)
            {
                bool result = false;
                rwLock.AcquireReaderLock(timeout);

                try {
                    result = collection.Contains(x);
                }
                finally {
                    rwLock.ReleaseReaderLock();
                }

                return result;
            }
Ejemplo n.º 8
0
 public override void Remove(Answer x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
Ejemplo n.º 9
0
 /// <summary>
 ///		Returns the zero-based index of the first occurrence of a <see cref="Answer"/>
 ///		in the <c>AnswerCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="Answer"/> to locate in the <c>AnswerCollection</c>.</param>
 /// <returns>
 ///		The zero-based index of the first occurrence of <paramref name="item"/> 
 ///		in the entire <c>AnswerCollection</c>, if found; otherwise, -1.
 ///	</returns>
 public virtual int IndexOf(Answer item)
 {
     for (int i=0; i != m_count; ++i)
         if (m_array[i].Equals(item))
             return i;
     return -1;
 }
Ejemplo n.º 10
0
        /// <summary>
        ///		Copies the entire <c>AnswerCollection</c> to a one-dimensional
        ///		<see cref="Answer"/> array, starting at the specified index of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Answer"/> array to copy to.</param>
        /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param>
        public virtual void CopyTo(Answer[] array, int start)
        {
            if (m_count > array.GetUpperBound(0) + 1 - start)
                throw new System.ArgumentException("Destination array was not long enough.");

            Array.Copy(m_array, 0, array, start, m_count);
        }
Ejemplo n.º 11
0
 /// <summary>
 ///		Copies the entire <c>AnswerCollection</c> to a one-dimensional
 ///		<see cref="Answer"/> array.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="Answer"/> array to copy to.</param>
 public virtual void CopyTo(Answer[] array)
 {
     this.CopyTo(array, 0);
 }
Ejemplo n.º 12
0
 /// <summary>
 ///		Determines whether a given <see cref="Answer"/> is in the <c>AnswerCollection</c>.
 /// </summary>
 /// <param name="item">The <see cref="Answer"/> to check for.</param>
 /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>AnswerCollection</c>; otherwise, <c>false</c>.</returns>
 public virtual bool Contains(Answer item)
 {
     for (int i=0; i != m_count; ++i)
         if (m_array[i].Equals(item))
             return true;
     return false;
 }
Ejemplo n.º 13
0
        /// <summary>
        ///		Adds the elements of a <see cref="Answer"/> array to the current <c>AnswerCollection</c>.
        /// </summary>
        /// <param name="x">The <see cref="Answer"/> array whose elements should be added to the end of the <c>AnswerCollection</c>.</param>
        /// <returns>The new <see cref="AnswerCollection.Count"/> of the <c>AnswerCollection</c>.</returns>
        public virtual int AddRange(Answer[] x)
        {
            if (m_count + x.Length >= m_array.Length)
                EnsureCapacity(m_count + x.Length);

            Array.Copy(x, 0, m_array, m_count, x.Length);
            m_count += x.Length;
            m_version++;

            return m_count;
        }
Ejemplo n.º 14
0
        /// <summary>
        ///		Adds a <see cref="Answer"/> to the end of the <c>AnswerCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="Answer"/> to be added to the end of the <c>AnswerCollection</c>.</param>
        /// <returns>The index at which the value has been added.</returns>
        public virtual int Add(Answer item)
        {
            if (m_count == m_array.Length)
                EnsureCapacity(m_count + 1);

            m_array[m_count] = item;
            m_version++;

            return m_count++;
        }
Ejemplo n.º 15
0
            public override void Remove(Answer x)
            {
                rwLock.AcquireWriterLock(timeout);

                try {
                    collection.Remove(x);
                }
                finally {
                    rwLock.ReleaseWriterLock();
                }
            }
Ejemplo n.º 16
0
 public override void CopyTo(Answer[] array, int start)
 {
     m_collection.CopyTo(array,start);
 }
Ejemplo n.º 17
0
 public override int IndexOf(Answer x)
 {
     return m_collection.IndexOf(x);
 }
Ejemplo n.º 18
0
        /// <summary>
        ///		Inserts an element into the <c>AnswerCollection</c> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param>
        /// <param name="item">The <see cref="Answer"/> to insert.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///		<para><paramref name="index"/> is less than zero</para>
        ///		<para>-or-</para>
        ///		<para><paramref name="index"/> is equal to or greater than <see cref="AnswerCollection.Count"/>.</para>
        /// </exception>
        public virtual void Insert(int index, Answer item)
        {
            ValidateIndex(index, true); // throws

            if (m_count == m_array.Length)
                EnsureCapacity(m_count + 1);

            if (index < m_count) {
                Array.Copy(m_array, index, m_array, index + 1, m_count - index);
            }

            m_array[index] = item;
            m_count++;
            m_version++;
        }
Ejemplo n.º 19
0
            public override int AddRange(Answer[] x)
            {
                int result = 0;
                rwLock.AcquireWriterLock(timeout);

                try {
                    result = collection.AddRange(x);
                }
                finally {
                    rwLock.ReleaseWriterLock();
                }

                return result;
            }
Ejemplo n.º 20
0
        /// <summary>
        ///		Removes the first occurrence of a specific <see cref="Answer"/> from the <c>AnswerCollection</c>.
        /// </summary>
        /// <param name="item">The <see cref="Answer"/> to remove from the <c>AnswerCollection</c>.</param>
        /// <exception cref="ArgumentException">
        ///		The specified <see cref="Answer"/> was not found in the <c>AnswerCollection</c>.
        /// </exception>
        public virtual void Remove(Answer item)
        {
            int i = IndexOf(item);
            if (i < 0)
                throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection.");

            ++m_version;
            RemoveAt(i);
        }
Ejemplo n.º 21
0
            public override void CopyTo(Answer[] array, int start)
            {
                rwLock.AcquireReaderLock(timeout);

                try {
                    collection.CopyTo(array, start);
                }
                finally {
                    rwLock.ReleaseReaderLock();
                }
            }
Ejemplo n.º 22
0
        /// <summary>
        ///		Removes the element at the specified index of the <c>AnswerCollection</c>.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///		<para><paramref name="index"/> is less than zero</para>
        ///		<para>-or-</para>
        ///		<para><paramref name="index"/> is equal to or greater than <see cref="AnswerCollection.Count"/>.</para>
        /// </exception>
        public virtual void RemoveAt(int index)
        {
            ValidateIndex(index); // throws

            m_count--;

            if (index < m_count) {
                Array.Copy(m_array, index + 1, m_array, index, m_count - index);
            }

            // We can't set the deleted entry equal to null, because it might be a value type.
            // Instead, we'll create an empty single-element array of the right type and copy it
            // over the entry we want to erase.
            Answer[] temp = new Answer[1];
            Array.Copy(temp, 0, m_array, m_count, 1);
            m_version++;
        }
Ejemplo n.º 23
0
 public override void DisplayAnswer(Answer answer)
 {
     this.state = GameState.Display;
     this.output = answer.Text + " (" + answer.Votes + ")";
 }
Ejemplo n.º 24
0
 /// <summary>
 ///		Initializes a new instance of the <c>AnswerCollection</c> class
 ///		that contains elements copied from the specified <see cref="Answer"/> array.
 /// </summary>
 /// <param name="a">The <see cref="Answer"/> array whose elements are copied to the new list.</param>
 public AnswerCollection(Answer[] a)
 {
     m_array = new Answer[a.Length];
     AddRange(a);
 }
Ejemplo n.º 25
0
 public override int AddRange(Answer[] x)
 {
     throw new NotSupportedException("This is a Read Only Collection and can not be modified");
 }
Ejemplo n.º 26
0
 public override void DisplayAnswer(Answer answer)
 {
     this.controlForm.AddAnswer(answer.Text);
     this.gameDisplay.AddAnswer(answer.Text, answer.Votes);
 }