示例#1
0
        public void SetShipState(StatedButtonControl sender)
        {
            isVertical = GameWindow.IsVertical;
            int   length = GameWindow.SelectedLength;
            Point point  = (Point)sender.Tag;

            StatedButtonControl[,] playerField = sender.ThisField.PlayerField;
            SetShipState(isVertical, length, point, playerField);
        }
示例#2
0
 public void UnsetShipFromField(Ship ship, StatedButtonControl sender)
 {
     foreach (StatedButton btn in ship.Position)
     {
         btn.ButtonState = StatedButton.State.Unselected;
         btn.LinkedShip  = null;
     }
     shipToSet.ReturnShip(ship);
     ChangeNearState(ship, sender.ThisField.PlayerField, true);
     SetShipState(sender);
 }
 public StatedButtonControl[,] CreateEmptyField()
 {
     StatedButtonControl[,] buttons = new StatedButtonControl[10, 10];
     for (int i = 0; i < 10; i++)
     {
         for (int j = 0; j < 10; j++)
         {
             buttons[i, j]     = new StatedButtonControl(this);
             buttons[i, j].Tag = new Point(i, j);
         }
     }
     return(buttons);
 }
示例#4
0
        public void CheckShot(Point point, bool isComputer)
        {
            StatedButtonControl button = isComputer ? player[(int)point.X, (int)point.Y] : computer[(int)point.X, (int)point.Y];

            if (button.button.ButtonState == StatedButton.State.Ship ||
                button.button.ButtonState == StatedButton.State.HidenShip)
            {
                button.button.ButtonState = StatedButton.State.Killed;
                button.button.LinkedShip.Decrement();
                if (button.button.LinkedShip.Left == 0)
                {
                    //Убит
                }
                else
                {
                    //Ранен
                }
                if (isComputer)
                {
                    playerLeft--;
                }
                else
                {
                    computerLeft--;
                }
                if (computerLeft == 0)
                {
                    MessageBox.Show("Вы победили!");
                    gameWindow.Close();
                }
                if (playerLeft == 0)
                {
                    MessageBox.Show("Победил компьютер");
                    gameWindow.Close();
                }
            }
            else if (button.button.ButtonState == StatedButton.State.Unselected || button.button.ButtonState == StatedButton.State.Locked)
            {
                button.button.ButtonState = StatedButton.State.Missed;
                //Промазал
            }

            if (isComputer)
            {
                if (button.button.ButtonState == StatedButton.State.Missed)
                {
                    if (points.Count > 2)
                    {
                        switch (direction)
                        {
                        case Direction.Down:
                            direction = Direction.Up;
                            break;

                        case Direction.Up:
                            direction = Direction.Down;
                            break;

                        case Direction.Left:
                            direction = Direction.Right;
                            break;

                        case Direction.Right:
                            direction = Direction.Left;
                            break;
                        }
                        points.RemoveRange(1, points.Count - 1);
                    }
                    else if (points.Count == 2)
                    {
                        points.RemoveAt(1);
                        direction++;
                    }
                    else
                    {
                        points.Clear();
                    }
                }
                if (button.button.ButtonState == StatedButton.State.Killed)
                {
                    if (button.button.LinkedShip.Left == 0)
                    {
                        points.Clear();
                        direction = 0;
                    }
                }
            }

            if (!isComputer)
            {
                CheckShot(GetRandomPoint(), true);
            }
        }