Diff of /Classes/Field/Hand.cs [c5a3d1] .. [cf67b8] Maximize Restore

  Switch to side-by-side view

--- a/Classes/Field/Hand.cs
+++ b/Classes/Field/Hand.cs
@@ -1,10 +1,11 @@
 ďťżusing System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.ComponentModel;
 using System.Linq;
 
 namespace YuGiOh_Ultra {
-    public sealed class Hand : IEnumerable<ACard> {
+    public sealed class Hand : IEnumerable<ACard>, INotifyPropertyChanged {
         public ObservableCollection<ACard> Cards { get; private set; }
         public uint Count { get { return (uint)Cards.Count; } }
 
@@ -17,16 +18,20 @@
 
         public void Add( ACard c ) {
             Cards.Add( c );
+            NotifyPropertyChanged( "Cards" );
         }
 
         internal void Add( IList<ACard> list ) {
             foreach( ACard c in list ) this.Add( c );
         }
 
-        public void Remove( ACard c ) { Cards.Remove( c ); }
+        public void Remove( ACard c ) {
+            Cards.Remove( c );
+            NotifyPropertyChanged( "Cards" );
+        }
 
         public ACard Discard( uint pos ) {
-            if( pos > Count ) return null;
+            if ( pos > Count ) throw new InvalidIndexException();
             ACard r = Cards[(int)pos];
             Cards.RemoveAt( (int)pos );
             return r;
@@ -36,17 +41,21 @@
             if( c == null ) throw new NotSupportedException();
             foreach ( ACard e in Cards.Where( e => e.Equals( c ) ) ) {
                 Remove(c);
+                NotifyPropertyChanged( "Cards" );
                 return e;
             }
-            return null;
+            throw new InvalidCardException();
         }
 
-        public IEnumerator<ACard> GetEnumerator() {
-            return Cards.GetEnumerator();
-        }
+        public IEnumerator<ACard> GetEnumerator() { return Cards.GetEnumerator(); }
 
-        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
-            return this.GetEnumerator();
+        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        private void NotifyPropertyChanged( String info ) {
+            if( PropertyChanged != null ) {
+                PropertyChanged( this, new PropertyChangedEventArgs( info ) );
+            }
         }
     }
 }