Added new Image for (Bomb-)Items.
[clanbomber-xamarin-client.git] / src / visualization / Playground / HelloMovingImage / HelloMovingImage / Playground.cs
index d40ddda..a56649c 100644 (file)
@@ -24,7 +24,8 @@ namespace BombermanPlayground
 
 
         private BombermanBlock[,] playgroungBlocks;
-        private List<PlayerBlock> players = new List<PlayerBlock>();
+        private Dictionary<int,PlayerBlock> players = new Dictionary<int, PlayerBlock>();
+        //private List<PlayerBlock> players = new List<PlayerBlock>();
         private List<BombBlock> bombs = new List<BombBlock>();
         private List<FlameBlock> flames = new List<FlameBlock>();
 
@@ -81,17 +82,23 @@ namespace BombermanPlayground
 
             for (int i = 0; i < pkg.Players.Count; i++)
             {
-                if(i< players.Count)
+                if(players.ContainsKey(i))
                 {
-                    players[i].MoveTo(pkg.Players[i].X, pkg.Players[i].Y);
+                    if (pkg.Players[i].Life != 0)
+                    {
+                        players[i].MoveTo(pkg.Players[i].X, pkg.Players[i].Y);
+                    }
+                    else
+                    {
+                        if(Children.Contains(players[i]))
+                        {
+                            Children.Remove(players[i]);
+                        }
+                    }
                 }
                 else
                 {
-                    players.Add(new PlayerBlock(pkg.Players[i].X, pkg.Players[i].Y, i));
-                    if(i >= players.Count)
-                    {
-                        throw new PlaygroundException("Error: Populating Playground with Players");
-                    }
+                    players[i]=new PlayerBlock(pkg.Players[i].X, pkg.Players[i].Y, i);
                     Children.Add(players[i]);
                 }
             }
@@ -251,6 +258,17 @@ namespace BombermanPlayground
 
     }
 
+    class MoveableBombermanBlock : BombermanBlock
+    {
+        public MoveableBombermanBlock(double posX, double posY) : base(posX - 0.5, posY - 0.5) { }
+
+        public new void MoveTo(double posX, double posY)
+        {
+            base.MoveTo(posX-0.5, posY-0.5);   // Xamarin X is Bomberman Y and vise-versa.
+        }
+    }
+
+
     class WallBlock : BombermanBlock
     {
         public WallBlock(double posX, double posY) : base(posX, posY)
@@ -259,7 +277,7 @@ namespace BombermanPlayground
         }
     }
 
-    class BombBlock : BombermanBlock
+    class BombBlock : MoveableBombermanBlock
     {
         public BombBlock(double posX, double posY) : base(posX, posY)
         {
@@ -275,9 +293,9 @@ namespace BombermanPlayground
         }
     }
 
-    class PlayerBlock : BombermanBlock
+    class PlayerBlock : MoveableBombermanBlock
     {
-        public PlayerBlock(double posX, double posY, int playerId) : base(posX-0.5, posY-0.5)  // Server sets offset itself for now..
+        public PlayerBlock(double posX, double posY, int playerId) : base(posX, posY)  // Server sets offset itself for now..
         {
             const int c_NumOfAvailablePictures = 4;
 
@@ -321,18 +339,13 @@ namespace BombermanPlayground
             }
         }
 
-
-        public void MoveTo(double posX, double posY)
-        {
-            base.MoveTo(posX - 0.5, posY - 0.5); // Server sets offset itself for now..
-        }
     }
 
     class ItemBlock : BombermanBlock
     {
         public ItemBlock(double posX, double posY) : base(posX, posY)
         {
-            //Source = ImageSource.FromResource(Playground.c_ImageNamespace+".Images.Unknwon.png");
+            Source = ImageSource.FromResource(Playground.c_ImageNamespace+".Images.BombCountUp.png");
         }
     }