Пример #1
0
        public void ClickButtonDirection(object sender, EventArgs e)
        {
            _tableDirection.Visible = true;
            _tableDirection.Text    = "PRESS ANY EMPTY CELL FOR SETTING SHIP ";

            Application.DoEvents();

            DirectionButton buttonDirection = (DirectionButton)sender;

            if (_currentGame.HasAllShipsPlayer())
            {
                return;
            }

            _currentGame.SetOneShip(buttonDirection.CurrentDirection);

            for (int OY = 0; OY < 10; OY++)
            {
                for (int OX = 0; OX < 10; OX++)
                {
                    _buttonsPlayer[OY, OX].CellCondition = _currentGame.GetMapManualCondition(OY, OX);
                }
            }

            for (int OY = 0; OY < 10; OY++)
            {
                for (int OX = 0; OX < 10; OX++)
                {
                    _buttonsPlayer[OY, OX].Click += ClickSettingShipButton;
                }
            }

            PrintPlayerMap(_buttonsPlayer, string.Empty);
            HideDirectionButtons();

            if (_currentGame.HasAllShipsPlayer())
            {
                _tableDirection.Visible = false;

                for (int OY = 0; OY < 10; OY++)
                {
                    for (int OX = 0; OX < 10; OX++)
                    {
                        _buttonsPlayer[OY, OX].Click -= ClickSettingShipButton;
                    }
                }

                _currentGame.PlayerMap                = _currentGame.PlayerMapManualInput;
                _currentGame.PlayerMap.InjuredShip   += ChangeMapCellInjuredPlayer;
                _currentGame.PlayerMap.DestroyedShip += ChangeMapCellDestroyedPlayer;
                _currentGame.PlayerMap.MissedCell    += ChangeMapCellPastPlayer;

                SetEnemyGameMap();
            }
        }
Пример #2
0
        private void SetDirectionButtons()
        {
            _fourDirections = new DirectionButton[4];

            for (Direction i = Direction.Up; i <= Direction.Left; i++)
            {
                _fourDirections[(int)(i - 1)] = new DirectionButton(i);

                switch (i)
                {
                case Direction.Up:
                    _fourDirections[(int)(i - 1)].Location = new Point(150, 100);
                    break;

                case Direction.Right:
                    _fourDirections[(int)(i - 1)].Location = new Point(250, 200);
                    break;

                case Direction.Down:
                    _fourDirections[(int)(i - 1)].Location = new Point(150, 300);
                    break;

                case Direction.Left:
                    _fourDirections[(int)(i - 1)].Location = new Point(50, 200);
                    break;

                default:
                    break;
                }

                _fourDirections[(int)(i - 1)].Size = new Size(100, 40);
                _fourDirections[(int)(i - 1)].Font = new System.Drawing.Font("Microsoft Sans Serif",
                                                                             13.75F, System.Drawing.FontStyle.Bold);
                _fourDirections[(int)(i - 1)].ForeColor = Color.Red;
                _fourDirections[(int)(i - 1)].Text      = i.ToString();
                _fourDirections[(int)(i - 1)].Click    += new EventHandler(ClickButtonDirection);
                _fourDirections[(int)(i - 1)].Visible   = false;

                Controls.Add(_fourDirections[(int)(i - 1)]);
            }
        }