private void ClickSettingShipButton(object sender, EventArgs e) { ButtonMap currentButton = (ButtonMap)sender; _tableDirection.Text = (currentButton.Coord.OY + 1).ToString() + ((Letters)currentButton.Coord.OX).ToString(); Application.DoEvents(); System.Threading.Thread.Sleep(1000); _tableDirection.Text = "INPUT DIRECTION:"; Application.DoEvents(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { _buttonsPlayer[i, j].Click -= ClickSettingShipButton; } } _currentGame.StartShipPosition = ((ButtonMap)sender).Coord; _tableDirection.Visible = false; ShowDirectionButtons(); }
private void ClickButtonCellEnemy(object sender, EventArgs e) { ButtonMap cellButton = (ButtonMap)sender; _currentGame.EnemyMap.TargetCoordX = cellButton.Coord.OX; _currentGame.EnemyMap.TargetCoordY = cellButton.Coord.OY; bool wasShot = _currentGame.EnemyMap.WasShot(); if (wasShot) { MessageBox.Show("You alredy have shoot this position!"); } else { IsPlayerTurn(); } }
private void AddButtonsCell(int startCoordY, int startCoordX, int maxWidth, ButtonMap[,] buttonsCell, Sea map, bool isEnemyClickButton) { int oY = 0; int oX = 0; for (int Y = startCoordY; Y < MAX_PIXEL_HEIGTH; Y += CELL_SIZE) { for (int X = startCoordX; X < maxWidth; X += CELL_SIZE) { ButtonMap buttonCell = new ButtonMap(oX, oY); buttonCell.Location = new Point(X, Y); buttonCell.Size = new Size(CELL_SIZE, CELL_SIZE); buttonCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.75F, System.Drawing.FontStyle.Bold); buttonCell.FlatStyle = FlatStyle.Flat; buttonCell.FlatAppearance.BorderSize = 2; buttonCell.FlatAppearance.BorderColor = Color.Orange; buttonCell.CellCondition = map[oY, oX]; buttonsCell[oY, oX] = buttonCell; Controls.Add(buttonCell); if (isEnemyClickButton) { buttonCell.Click += new EventHandler(ClickButtonCellEnemy); } else { buttonCell.Click += new EventHandler(ClickSettingShipButton); } oX++; } oX = 0; oY++; } }