// Hande the messages related to the life packs or coins
 public override bool handleMessageImpl(string message)
 {
     message = message.Substring(0, message.Length - 1);
     // if the message is no hadled return false
     if (message[0] == 'C' || message[0] == 'L')
     {
         // if the message is related to coins
         if (message[0] == 'C')
         {
             // These are the data related to the life pack
             string[] sections = message.Split(':');
             int[] location = { Int32.Parse(sections[1].Split(',')[0]), Int32.Parse(sections[1].Split(',')[1]) };
             int timeout = Int32.Parse(sections[2]);
             int value = Int32.Parse(sections[3]);
             // Add the coin to the grid and updateUI
             // To be implemented
             //Console.WriteLine("Coins");
             //Console.WriteLine("Location " + location[0] + "," + location[1]);
             //Console.WriteLine("Timeout " + timeout);
             //Console.WriteLine("Value " + value);
             Coin coin = new Coin();
             coin.Life_time = timeout;
             coin.Location = new Microsoft.Xna.Framework.Vector2(location[0], location[1]);
             coin.Value = value;
             lock (active_grid.Coins)
             { active_grid.addCoin(coin); }
             return true;
         }
         // if the message is related to life packs
         else
         {
             string[] sections = message.Split(':');
             int[] location = { Int32.Parse(sections[1].Split(',')[0]), Int32.Parse(sections[1].Split(',')[1]) };
             int timeout = Int32.Parse(sections[2]);
             // Add the coin to the grid and updateUI
             // To be implemented
             //Console.WriteLine("Life Pack");
             //Console.WriteLine("Location " + location[0] + "," + location[1]);
             //Console.WriteLine("Timeout " + timeout);
             LifePack lp = new LifePack();
             lp.Life_time = timeout;
             lp.Location = new Microsoft.Xna.Framework.Vector2(location[0], location[1]);
             lock (active_grid.Life_packs)
             { active_grid.addLifePack(lp); }
             return true;
         }
     }
     else
     {
         return false;
     }
 }
 // Adding, accessing and removal coins with timeout
 public void addCoin(Coin c)
 {
     Coins.Add(c.Location, c);
 }
Example #3
0
        private void updateTank()
        {
            // update new tanks
            tanks = active_grid.Tanks;
            Stack<Tank> removable = new Stack<Tank>();
            try
            {
                foreach (Tank tk in tanks.Values.ToList<Tank>())
                {
                    if (tk.Health == 0 && tk.Player_name == active_grid.Playername)
                    {
                        Rectangle reclarge = new Rectangle(0, 0, 700, 700);
                        spriteBatch.Draw(gameover, reclarge, Color.White);
                        continue;

                    }
                    else if (tk.Health == 0)
                    {
                        //dropping their coins
                        Coin c = new Coin();
                        c.Location = tk.Location;
                        c.Value = tk.Coins;
                        c.Life_time = 999999999;
                        if (coins.ContainsKey(c.Location))
                        {
                            coins[c.Location].Value += c.Value;
                        }
                        else
                        {
                            coins.Add(tk.Location, c);
                        }
                        removable.Push(tk);
                        continue;
                    }
                    switch (tk.Direction)
                    {
                        case 0://north
                            spriteBatch.Draw(playerLogo[tk.Player_name], new Vector2(tk.Location.X * 70 + 35, tk.Location.Y * 70 + 35), null, Color.White, 0, new Vector2(35, 35), 1, SpriteEffects.None, 1);
                            spriteBatch.DrawString(font, tk.Player_name, new Vector2(tk.Location.X * 70 + 25, tk.Location.Y * 70 + 20), Color.White);

                            break;
                        case 1://east
                            spriteBatch.Draw(playerLogo[tk.Player_name], new Vector2(tk.Location.X * 70 + 35, tk.Location.Y * 70 + 35), null, Color.White, MathHelper.ToRadians(90), new Vector2(35, 35), 1, SpriteEffects.None, 1);
                            spriteBatch.DrawString(font, tk.Player_name, new Vector2(tk.Location.X * 70 + 25, tk.Location.Y * 70 + 20), Color.White);
                            break;
                        case 2://south
                            spriteBatch.Draw(playerLogo[tk.Player_name], new Vector2(tk.Location.X * 70 + 35, tk.Location.Y * 70 + 35), null, Color.White, MathHelper.ToRadians(180), new Vector2(35, 35), 1, SpriteEffects.None, 1);
                            spriteBatch.DrawString(font, tk.Player_name, new Vector2(tk.Location.X * 70 + 25, tk.Location.Y * 70 + 20), Color.White);
                            break;
                        case 3://west
                            spriteBatch.Draw(playerLogo[tk.Player_name], new Vector2(tk.Location.X * 70 + 35, tk.Location.Y * 70 + 35), null, Color.White, MathHelper.ToRadians(270), new Vector2(35, 35), 1, SpriteEffects.None, 1);
                            spriteBatch.DrawString(font, tk.Player_name, new Vector2(tk.Location.X * 70 + 25, tk.Location.Y * 70 + 20), Color.White);
                            break;
                    }
                    if (tk.Player_name == active_grid.Playername)
                    {
                        spriteBatch.DrawString(font, tk.Player_name, playerstat[tk.Player_name], Color.DarkBlue);
                        spriteBatch.DrawString(font, tk.Points + "", new Vector2(playerstat[tk.Player_name].X + 60, playerstat[tk.Player_name].Y), Color.DarkBlue);
                        spriteBatch.DrawString(font, tk.Coins + "", new Vector2(playerstat[tk.Player_name].X + 130, playerstat[tk.Player_name].Y), Color.DarkBlue);
                        spriteBatch.DrawString(font, tk.Health + "%", new Vector2(playerstat[tk.Player_name].X + 200, playerstat[tk.Player_name].Y), Color.DarkBlue);

                    }
                    else
                    {
                        spriteBatch.DrawString(font, tk.Player_name, playerstat[tk.Player_name], Color.Black);
                        spriteBatch.DrawString(font, tk.Points + "", new Vector2(playerstat[tk.Player_name].X + 60, playerstat[tk.Player_name].Y), Color.Black);
                        spriteBatch.DrawString(font, tk.Coins + "", new Vector2(playerstat[tk.Player_name].X + 130, playerstat[tk.Player_name].Y), Color.Black);
                        spriteBatch.DrawString(font, tk.Health + "%", new Vector2(playerstat[tk.Player_name].X + 200, playerstat[tk.Player_name].Y), Color.Black);

                    }

                    // Remove coins if a tank collects them
                    if (coins.ContainsKey(tk.Location))
                    {
                        coins.Remove(tk.Location);
                    }
                    // Remove lifepack if a tank collects them
                    if (life_packs.ContainsKey(tk.Location))
                    {
                        life_packs.Remove(tk.Location);
                    }
                    // If the tank has shot
                    if (tk.Whether_shot)
                    {
                        active_grid.addBullet(new Bullet(tk.Direction, new Vector2(tk.Location.X * 70, tk.Location.Y * 70)));
                        tk.Whether_shot = false;
                    }
                }
            }
            catch (Exception)
            {

                //
            }
            while (removable.Count > 0)
            {
                tanks.Remove(removable.Pop().Player_name);
            }
        }