private void setPictureBoxLocation( PictureBoxGameTool i_CurrentPictureBox, bool i_NewLine, bool i_IsFirstPictureBox, PictureBox i_LastPictureBoxInMatrix) { Point newLocation; int pictureBoxMatrixMaxLine = r_FormGameSettings.BoardSize - 1; int pictureBoxMatrixMaxCol = r_FormGameSettings.BoardSize - 1; if (i_IsFirstPictureBox) { newLocation = new Point(k_StartingPictureBoxX, k_StartingPictureBoxY); } else { newLocation = i_LastPictureBoxInMatrix.Location; if (!i_NewLine) { newLocation.Offset(i_LastPictureBoxInMatrix.Width, 0); } else { newLocation.X = k_StartingPictureBoxX; newLocation.Offset(0, i_LastPictureBoxInMatrix.Height); } } i_CurrentPictureBox.Location = newLocation; }
private void setPlayersLabelLocation() { PictureBoxGameTool middlePictureBox = pictureBoxMatrix[0, (r_FormGameSettings.BoardSize / 2) - 1]; int gamePictureBoxWidth = middlePictureBox.Width; int gamePictureBoxHeight = middlePictureBox.Height / 2; Point middle = middlePictureBox.Location; Point player1LabelLocation = middle, player2LabelLocation = middle; player1LabelLocation.Offset(-middlePictureBox.Width, -gamePictureBoxHeight); player2LabelLocation.Offset(middlePictureBox.Width, -gamePictureBoxHeight); labelPlayer1.Location = player1LabelLocation; labelPlayer1.AutoSize = true; labelPlayer2.Location = player2LabelLocation; labelPlayer2.AutoSize = true; }
private void pictureBox_Click(object sender, EventArgs e) { PictureBoxGameTool currentGameToolPressed = sender as PictureBoxGameTool; MoveEnterdEventArgs me; if (currentGameToolPressed.IsEnabled) { if (anotherPictureBoxPressed) { if (currentGameToolPressed.Image == null) { me = createMoveEnterdEventArgs(pictureBoxPressed.PlaceOnBoard, currentGameToolPressed.PlaceOnBoard); OnMoveEnterd(me); anotherPictureBoxPressed = false; pictureBoxPressed.BorderStyle = BorderStyle.FixedSingle; pictureBoxPressed.IsEnabled = true; pictureBoxPressed.BackgroundImage = global::UIWindows.Properties.Resources.EnabledBackground; } } else { if (currentGameToolPressed.Image != null) { pictureBoxPressed = currentGameToolPressed; currentGameToolPressed.BorderStyle = BorderStyle.Fixed3D; currentGameToolPressed.IsEnabled = false; anotherPictureBoxPressed = true; pictureBoxPressed.BackgroundImage = global::UIWindows.Properties.Resources.GameToolPressed; } } } else { anotherPictureBoxPressed = false; currentGameToolPressed.BorderStyle = BorderStyle.FixedSingle; currentGameToolPressed.IsEnabled = true; pictureBoxPressed.BackgroundImage = global::UIWindows.Properties.Resources.EnabledBackground; } }
private void createPictureBoxMatrix() { bool newLine = false, isFirstPictureBox = true; PictureBox lastPictureBoxInMatrix = new PictureBox(); for (int i = 0; i < r_FormGameSettings.BoardSize; i++) { for (int j = 0; j < r_FormGameSettings.BoardSize; j++) { PictureBoxGameTool currentPictureBox = new PictureBoxGameTool(i, j); setPictureBoxLocation(currentPictureBox, newLine, isFirstPictureBox, lastPictureBoxInMatrix); intializePictureBox(currentPictureBox); pictureBoxMatrix[i, j] = currentPictureBox; this.Controls.Add(currentPictureBox); newLine = false; isFirstPictureBox = false; lastPictureBoxInMatrix = currentPictureBox; } newLine = true; } }
private void setPictureBoxFigure(PictureBoxGameTool i_CurrentPictureBox) { i_CurrentPictureBox.Height = k_PictureBoxHeight; i_CurrentPictureBox.Width = k_PictureBoxWidth; }
private void intializePictureBox(PictureBoxGameTool i_CurrentPictureBox) { setPictureBoxFigure(i_CurrentPictureBox); i_CurrentPictureBox.Enabled = false; i_CurrentPictureBox.Click += pictureBox_Click; }