--- a/wBattle.xaml.cs
+++ b/wBattle.xaml.cs
@@ -1,14 +1,15 @@
 ďťżusing System;
 using System.ComponentModel;
+using System.Diagnostics;
 using System.Text;
 using System.Windows;
 using System.Net.Sockets;
 using System.Windows.Threading;
 
 namespace YuGiOh_Ultra {
+    public enum GameAction { Draw = 0, Summon, Place, Set, HandDiscard, HandBanish, HandToDeck, FieldToGrave, FiledBanish, MonsterChangePos, Lose, Surrendered };
+
     public partial class wBattle : Window {
-        private enum GameAction { Draw, Summon, Place, Set, HandDiscard, HandBanish, HandToDeck, FieldToGrave, FiledBanish, MonsterChangePos };
-
         private bool iscon = false;
 
         private readonly DispatcherTimer Datatmr = new DispatcherTimer(), Connectioncontroltmr = new DispatcherTimer();
@@ -18,6 +19,9 @@
         private NetworkStream NetStr;
 
         public string enemyip = "127.0.0.1";
+
+        public ICard MagicFieldCard;
+        public readonly Enemy enemy = new Enemy();
 
         public wBattle() {
             InitializeComponent();
@@ -30,8 +34,6 @@
             lbhand.ItemsSource = Com.me.Hand.Cards;
             lbfieldmonsters.ItemsSource = Com.me.MonsterField.Cards;
             lbfieldcards.ItemsSource = Com.me.StField.Cards;
-
-            Com.debug.Show();
         }
 
         private void TcpListenData( object sender = null, object e = null ) {
@@ -39,9 +41,30 @@
 
             var Bytes = new byte[Client.ReceiveBufferSize];
             int len = NetStr.Read( Bytes, 0, Bytes.Length );
-            var y = Encoding.ASCII.GetString( Bytes, 0, len ).Trim();
-
-            Com.debug.Write( "wrote: " + y );
+            var msg = Encoding.ASCII.GetString( Bytes, 0, len ).Trim();
+
+            Debug.WriteLine( "wrote: " + msg );
+
+            if ( msg == "disconnected" ) {
+                Datatmr.Stop();
+                Connectioncontroltmr.Stop();
+                Listener.Stop();
+                Client.Close();
+
+                btnclientcon.IsEnabled = btnservercon.IsEnabled = true;
+                btnclientcon.Content = "Client Connect";
+                btnservercon.Content = "Server Connect";
+                return;
+            }
+
+            if ( !msg.Contains( "|" ) ) return;
+            var a = msg.Split( '|' );
+
+            var action = (GameAction) int.Parse(a[0]);
+
+            switch ( action ) {
+                
+            }
         }
 
         private void ConnectionControl( object sender = null, object e = null ) {
@@ -112,18 +135,19 @@
             SendNetMsg( "test" );
         }
 
-        private void SendNetMsg( string txtmsg ) {
-            if ( Client.Connected && NetStr.CanWrite ) {
-                var Bytes = Encoding.ASCII.GetBytes( txtmsg );
-                NetStr.Write( Bytes, 0, Bytes.Length );
-            }
-            //else MessageBox.Show( "send error!" );
-        }
-
-        private void SendNetAction( GameAction ga, ICard c ) { SendNetMsg( ga.ToString() + "|" + c.Code ); }
+        public void SendNetMsg( string txtmsg ) {
+            if ( !Client.Connected || !NetStr.CanWrite ) return;
+
+            var Bytes = Encoding.ASCII.GetBytes( txtmsg );
+            NetStr.Write( Bytes, 0, Bytes.Length );
+        }
+
+        public void SendNetAction( GameAction ga ) { SendNetMsg( (int) ga + "|" ); } // +"|" because all message with an action must contain this character
+
+        public void SendNetAction( GameAction ga, ICard c ) { SendNetMsg( (int)ga + "|" + c.Code); }
 
         private void btnsummon_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbhand.SelectedItem as Card;
+            ACard c = lbhand.SelectedItem as ACard;
             if ( c == null ) return;
 
             if ( Com.me.MonsterField.Add( c ) ) {
@@ -133,7 +157,7 @@
         }
 
         private void btnviewdeck_Click( object sender, RoutedEventArgs e ) {
-            new wViewBattleCardStack( Com.me.MainDeck ).Show();
+            new wViewBattleCardStack( Com.me.MainDeck.Cards ).Show();
         }
 
         private void btnviewgraveyard_Click( object sender, RoutedEventArgs e ) {
@@ -141,7 +165,7 @@
         }
 
         private void btndiscard_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbhand.SelectedItem as Card;
+            var c = lbhand.SelectedItem as ACard;
             if ( c == null ) return;
             Com.me.Hand.Discard( c );
             Com.me.Graveyard.AddTop( c );
@@ -149,14 +173,15 @@
         }
 
         private void btndraw_Click( object sender, RoutedEventArgs e ) {
-            Card c = Com.me.MainDeck.Draw();
+            var c = Com.me.MainDeck.Draw();
             if ( c == null ) {
                 MessageBox.Show( "Cards finished! You lose!" );
+                SendNetAction( GameAction.Lose );
                 return;
             }
 
-            Com.me.Hand.Add( c );
-            SendNetMsg( GameAction.Draw.ToString() );
+            Com.me.Hand.Add( c as ACard );
+            SendNetAction( GameAction.Draw );
         }
 
         private void Window_Closing( object sender, CancelEventArgs e ) {
@@ -165,23 +190,24 @@
             Connectioncontroltmr.Stop();
             Listener.Stop();
             Client.Close();
+
+            new wMenu().Show();
         }
 
         private void lbhand_ContextMenuOpening( object sender, System.Windows.Controls.ContextMenuEventArgs e ) {
-            Card c = lbhand.SelectedItem as Card;
+            var c = lbhand.SelectedItem as ACard;
 
             if ( c is ASpellTrapCard ) {
                 btnsummon.Visibility = Visibility.Collapsed;
                 btnactivate.Visibility = Visibility.Visible;
-            }
-            else {
+            } else {
                 btnsummon.Visibility = Visibility.Visible;
                 btnactivate.Visibility = Visibility.Collapsed;
             }
         }
 
         private void btnbanish_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbhand.SelectedItem as Card;
+            ACard c = lbhand.SelectedItem as ACard;
             Com.me.Banished.AddTop( c );
             Com.me.Hand.Remove( c );
 
@@ -193,7 +219,7 @@
         }
 
         private void btnplace_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbhand.SelectedItem as Card;
+            ACard c = lbhand.SelectedItem as ACard;
             if ( c == null ) return;
 
             Com.me.Hand.Remove( c );
@@ -205,7 +231,7 @@
         }
 
         private void mftograve_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbfieldmonsters.SelectedItem as Card;
+            ACard c = lbfieldmonsters.SelectedItem as ACard;
             if ( c == null ) return;
 
             Com.me.MonsterField.Remove(c);
@@ -215,7 +241,7 @@
         }
 
         private void mfbanish_Click( object sender, RoutedEventArgs e ) {
-            Card c = lbfieldmonsters.SelectedItem as Card;
+            ACard c = lbfieldmonsters.SelectedItem as ACard;
             if( c == null ) return;
 
             Com.me.MonsterField.Remove( c );