[cf67b8]: Classes / Field / Hand.cs  Maximize  Restore  History

Download this file

62 lines (50 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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>, INotifyPropertyChanged {
public ObservableCollection<ACard> Cards { get; private set; }
public uint Count { get { return (uint)Cards.Count; } }
public Hand() { Cards = new ObservableCollection<ACard>(); }
public Hand( IEnumerable<ICard> list ) : this() {
foreach ( var c in list )
Add( c as ACard );
}
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 );
NotifyPropertyChanged( "Cards" );
}
public ACard Discard( uint pos ) {
if ( pos > Count ) throw new InvalidIndexException();
ACard r = Cards[(int)pos];
Cards.RemoveAt( (int)pos );
return r;
}
public ACard Discard( ACard c ) {
if( c == null ) throw new NotSupportedException();
foreach ( ACard e in Cards.Where( e => e.Equals( c ) ) ) {
Remove(c);
NotifyPropertyChanged( "Cards" );
return e;
}
throw new InvalidCardException();
}
public IEnumerator<ACard> GetEnumerator() { return Cards.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 ) );
}
}
}
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks