コード例 #1
0
        public bool Move(int y, int x)
        {
            FieldsElement elem = this.Field[y, x];

            elem.IsFired = true;
            NewState.Add(elem);
            if (elem.IsShip())
            {
                Score       += 5;
                Enemy.Score -= 1;

                elem.ShipRef.Decks -= 1;//hit ship
                if (elem.ShipRef.IsDead())
                {
                    Explosion(elem.ShipRef);
                }

                return(true);
            }
            else
            {
                Score--;
                return(false);
            }
        }
コード例 #2
0
ファイル: Bot.cs プロジェクト: MeeLucky/SeaBattle
        public bool Move()
        {
            if (Goal == null)
            {
                return(RandomShot());
            }

            int[] pos = Goal.GetNextShotPosition();
            if (pos[0] == -1)
            {
                Goal = null;
                return(RandomShot());
            }

            FieldsElement elem = UserField.Field[pos[0], pos[1]];

            if (elem.IsShip())
            {
                Goal.Elems.Add(elem);
            }

            return(UserField.Move(pos[0], pos[1]));
        }
コード例 #3
0
        private void FullDisplayField(GameLogic Field, object Side, bool IsUser)
        {
            StackPanel panel = (StackPanel)Side;

            for (int i = 0; i < 10; i++)
            {
                StackPanel row = new StackPanel()
                {
                    Orientation = Orientation.Horizontal
                };
                panel.Children.Add(row);
                for (int j = 0; j < 10; j++)
                {
                    FieldsElement elem = Field.Field[i, j];
                    string        tag  = $"{elem.GetY()},{elem.GetX()},{elem.Ship}";

                    Image img = null;
                    if (elem.IsFired)
                    {
                        if (elem.IsShip())
                        {
                            img = new Image {
                                Source = new BitmapImage(new Uri("RedCross.png", UriKind.Relative))
                            }
                        }
                        ;
                        else
                        {
                            img = new Image {
                                Source = new BitmapImage(new Uri("BlueCircle.png", UriKind.Relative))
                            }
                        };
                    }

                    Button btn = new Button()
                    {
                        Width      = BtnSize,
                        Height     = BtnSize,
                        FontWeight = FontWeights.UltraBold,
                        Background = new SolidColorBrush(Colors.White),
                        Tag        = tag,
                        Content    = img
                    };
                    if (!IsUser)
                    {
                        if (elem.IsShip())
                        {
                            btn.BorderBrush     = new SolidColorBrush(Colors.Blue);
                            btn.BorderThickness = new Thickness(2);
                            btn.Background      = (SolidColorBrush)(new BrushConverter().ConvertFrom("#f0f8ff"));
                        }
                    }
                    else
                    {
                        btn.Click += Button_Click;
                    }

                    row.Children.Add(btn);
                }
            }
        }