示例#1
0
        public void ReceiveShot(int row, int col)
        {
            var elements  = Map.Children.Cast <UIElement>().Where(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == col).ToList();
            var shipParts = elements.Where(e => (e as Image).Tag.ToString().Length == 1).ToList();

            if (shipParts.Count == 0)
            {
                gameClient.SendResult("Miss", row, col);
                for (int i = 0; i < elements.Count; i++)
                {
                    Map.Children.Remove(elements[i]);
                }
                var image = new Image
                {
                    Stretch = Stretch.Fill,
                    Source  = Resources["Miss"] as BitmapImage,
                    Tag     = "Miss"
                };
                Panel.SetZIndex(image, 2);
                Map.Children.Add(image);
                Grid.SetRow(image, row);
                Grid.SetColumn(image, col);
            }
            else
            {
                gameClient.SendResult("Hit", row, col);
                for (int i = 0; i < elements.Count; i++)
                {
                    Map.Children.Remove(elements[i]);
                }
                var image = new Image
                {
                    Stretch = Stretch.Fill,
                    Source  = Resources["Hit"] as BitmapImage,
                    Tag     = "Hit"
                };
                Panel.SetZIndex(image, 10);
                Map.Children.Add(image);
                Grid.SetRow(image, row);
                Grid.SetColumn(image, col);
                leftMy--;
                if (leftMy == 0)
                {
                    WriteLog(user + " lost!");
                    MessageBox.Show("You lost.");
                }
            }
            canShot = true;
        }