public void RemovePlayer(int id)
 {
     try
     {
         if (selectedPlayer.Equals(players[id]) && selectedPlayer != null) { selectedPlayer = null; player = false; computer = true; }
         playerAmount--;
         gameobjects.Remove(players[id]);
     }
     catch (NullReferenceException)
     {
         String exMessage = String.Format("{0} / {1} / {2}", Constants.FailedShipRemove, players.ToString(), players[id].ToString());
         if (selectedPlayer != null)
         {
             exMessage = String.Format("{0} / {1}", exMessage, selectedPlayer.ToString());
         }
         throw new FailedShipRemove(exMessage);
     }            
 }
 public void SelectShip(int id)
 {
     if (player)
     {
         for (int i = 0; i < players.Length; i++)
         {
             players[i].selected = false;
         }
         players[id].selected = true;
         selectedPlayer = players[id];
     }
     
 }
        private void SetupShips()
        {
            for (int i = 0; i < amount; i++)
            {
                players[i] = new Player(pCoordinates[i][0], pCoordinates[i][1], i);
                enemies[i] = new Computer(eCoordinates[i][0], eCoordinates[i][1], i, 180, 0);
                #region Set Handlers
                (players[i]).hit.spriteButton.Click += (players[i]).Player_Click;
                (players[i]).alive.spriteButton.Click += (players[i]).Player_Click;
                #endregion
                gameobjects.Add(players[i]);
                gameobjects.Add(enemies[i]);

            }
        }
 private void CheckTurn()
 {
     if (playerAmount == 0 || enemyAmount == 0)
     {
         selectedPlayer = null;
         gameobjects.Clear();
         game.WriteScore();
         Init();
         
     }
     if (selectedPlayer != null && selectedPlayer.dx == 0 && selectedPlayer.dy == 0 && !computer && !player)
     {
         computer = true;
     }
     
     
 }
        public override void Init()
        {
             #region Setup Display

            #region Window
            menuScreen = new Canvas();
            menuScreen.Height = Constants.ScreenHeight;
            menuScreen.Width = Constants.ScreenWidth;
            menuScreen.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            menuScreen.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            background = new Background(Constants.MenuBackgroundPath);
            menuScreen.Background = background.GetBrush();
            title = new Title();
            title.Margin = new Thickness(Constants.ScreenWidth / 2 -430, Constants.ScreenHeight / 2 - 320, 0, 0);
            title.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            title.VerticalAlignment = System.Windows.VerticalAlignment.Center;
             #endregion

            #region Panel
            buttons = new MenuPanel(this);
            buttons.Margin = new Thickness(Constants.ScreenWidth / 2 - buttons.width / 2, Constants.ScreenHeight - (buttons.height * 1.5), 0, 0);
            #endregion

             #endregion

            #region Setup Decoration

            #region Random
            r = new Randomizer();
            angle = new Randomizer(r.Next());
            speed = new Randomizer(r.Next() * angle.Next());
            xpos = new Randomizer(r.Next() * speed.Next());
            ypos = new Randomizer(r.Next() * xpos.Next());
            Constants.SelectedEnemy = xpos.Next(0, 1);
            Constants.SelectedShip = ypos.Next(0, 1);
            #endregion

            #region Create decor
            int amount = r.Next(10, 20);
            int pamount = amount / 2;
            int eamount = amount - pamount;
            players = new Player[pamount];
            enemies = new Computer[eamount];
            list = new List<GameObject>();

            for (int i = 0; i < players.Length; i++)
            {
                players[i] = new Player(xpos.Next(128, Constants.ScreenWidth - 128), ypos.Next(64, Constants.ScreenHeight - 64), i);
                players[i].SetAngle(angle.Next(0, 360));
                players[i].SetSpeed(speed.Next(3, 6));
                players[i].UpdateMovement();
                list.Add(players[i]);
               
            }
            for (int i = 0; i < enemies.Length; i++)
            {
                enemies[i] = new Computer(xpos.Next(128, Constants.ScreenWidth - 128), ypos.Next(64, Constants.ScreenHeight - 64), i);
                enemies[i].SetAngle(angle.Next(0, 360));
                enemies[i].SetSpeed(speed.Next(3, 6));
                enemies[i].UpdateMovement();
                list.Add(enemies[i]);
               
            }
            #endregion

            Constants.SelectedEnemy = 0;
            Constants.SelectedShip = 0;
            #endregion

        }