Removed offset for player position calculation as server does this for now
[clanbomber-xamarin-client.git] / src / communication / ConnectionTest / ConnectionTest / ConnectionTest / MainPage.xaml.cs
index da8535c..2cdf227 100644 (file)
@@ -31,16 +31,9 @@ namespace Bomberman
 
             con = new TcpJsonConnection(ServerPkgReceived);
 
-            //con.Connect(IPAddress.Parse("fe80::6520:ac61:a4a1:827a%20"));
+            //con.Connect(IPAddress.Parse("10.29.17.60"));
             con.Connect(Dns.GetHostEntry(Dns.GetHostName()).AddressList[1]);    //localhost
 
-        }
-
-        private void MainPage_SizeChanged(object sender, EventArgs e)
-        {
-
-
-
 
             Entry ent = new Entry();
             ButtonLayout.Children.Add(ent);
@@ -66,6 +59,7 @@ namespace Bomberman
                         horizontalLayout.Children.Add(dummy);
                         Button up = new Button();
                         up.Pressed += Up_Pressed;
+                        up.Released += Up_Released;
                         up.Text = "^";
                         horizontalLayout.Children.Add(up);
                         horizontalLayout.Children.Add(dummy);
@@ -75,15 +69,18 @@ namespace Bomberman
                         Button left = new Button();
                         left.Text = "<";
                         left.Pressed += Left_Pressed;
+                        left.Released += Left_Released;
                         horizontalLayout.Children.Add(left);
 
                         Button bomb = new Button();
                         bomb.Pressed += Bomb_Pressed;
+                        bomb.Released += Bomb_Released;
                         bomb.Text = "*";
                         horizontalLayout.Children.Add(bomb);
 
                         Button right = new Button();
                         right.Pressed += Right_Pressed;
+                        right.Released += Right_Released;
                         right.Text = ">";
                         horizontalLayout.Children.Add(right);
                         break;
@@ -92,6 +89,7 @@ namespace Bomberman
                         horizontalLayout.Children.Add(dummy);
                         Button down = new Button();
                         down.Pressed += Down_Pressed;
+                        down.Released += Down_Released;
                         down.Text = "V";
                         horizontalLayout.Children.Add(down);
                         horizontalLayout.Children.Add(dummy);
@@ -100,23 +98,48 @@ namespace Bomberman
 
                 }
 
-                CreateInitializePlayground(c_defaultPlaygroundSize);
+            }
+        }
 
+        private void Down_Released(object sender, EventArgs e)
+        {
+            con.SendEvent(TcpJsonConnection.InputState.Idle);
+        }
 
-            }
+        private void Right_Released(object sender, EventArgs e)
+        {
+            con.SendEvent(TcpJsonConnection.InputState.Idle);
+        }
 
+        private void Bomb_Released(object sender, EventArgs e)
+        {
+            con.SendEvent(TcpJsonConnection.InputBomb.Idle);
+        }
 
+        private void Left_Released(object sender, EventArgs e)
+        {
+            con.SendEvent(TcpJsonConnection.InputState.Idle);
+        }
+
+        private void Up_Released(object sender, EventArgs e)
+        {
+            con.SendEvent(TcpJsonConnection.InputState.Idle);
+        }
+
+        private void MainPage_SizeChanged(object sender, EventArgs e)
+        {
+            CreateInitializePlayground(c_defaultPlaygroundSize);
         }
 
         void CreateInitializePlayground(int size)
         {
             fullLayout = new StackLayout();
             playground = new BombermanPlayground.Playground(size);
+            BombermanPlayground.Playground.c_ImageNamespace = "ConnectionTest";
             BombermanPlayground.BombermanBlock.BlockSize = Width / (size + 1);
 
-
-            fullLayout.Children.Add(playground);
             fullLayout.Children.Add(ButtonLayout);
+            fullLayout.Children.Add(playground);
             Content = fullLayout;
 
         }
@@ -125,6 +148,10 @@ namespace Bomberman
         {
             Device.BeginInvokeOnMainThread(() =>
             {
+                if(playground == null)
+                {
+                    return;
+                }
                 if (playground.FieldSize != pkg.Field.Count)
                 {
                     CreateInitializePlayground(pkg.Field.Count);
@@ -165,32 +192,27 @@ namespace Bomberman
         private void Bomb_Pressed(object sender, EventArgs e)
         {
             con.SendEvent(TcpJsonConnection.InputBomb.PlaceBomb);
-            con.SendEvent(TcpJsonConnection.InputBomb.Idle);
         }
 
         private void Right_Pressed(object sender, EventArgs e)
         {
             con.SendEvent(TcpJsonConnection.InputState.Right);
-            con.SendEvent(TcpJsonConnection.InputState.Idle);
         }
 
         private void Left_Pressed(object sender, EventArgs e)
         {
             con.SendEvent(TcpJsonConnection.InputState.Left);
-            con.SendEvent(TcpJsonConnection.InputState.Idle);
         }
 
         private void Down_Pressed(object sender, EventArgs e)
         {
             con.SendEvent(TcpJsonConnection.InputState.Down);
-            con.SendEvent(TcpJsonConnection.InputState.Idle);
         }
 
 
         private void Up_Pressed(object sender, EventArgs e)
         {
             con.SendEvent(TcpJsonConnection.InputState.Up);
-            con.SendEvent(TcpJsonConnection.InputState.Idle);
         }
     }
 }