private void initializeBoardComponent() { int posY = k_DistanceButton; for (int i = 0; i < r_Height; i++) { int posX = k_DistanceButton; for (int j = 0; j < r_Width; j++) { string currentLocation = string.Format("{0}{1}", ((char)(j + k_FirstAsciChar)).ToString(), i + 1); r_ButtonMap.Add(currentLocation, new GameButton(currentLocation)); GameButton currentButton = r_ButtonMap[currentLocation]; currentButton.Size = new Size(k_ButtonSize, k_ButtonSize); currentButton.Left = posX; currentButton.Top = posY; posX += k_ButtonSize + k_DistanceButton; currentButton.Click += currentButton_Click; this.Controls.Add(currentButton); } posY += k_ButtonSize + k_DistanceButton; } r_CurrentPlayerLabel.Left = k_DistanceButton; r_CurrentPlayerLabel.Top = posY; r_CurrentPlayerLabel.AutoSize = true; setCurrentPlayerLabel(m_CurrentGame.CurrentPlayer); r_CurrentPlayerLabel.BackColor = r_PlayerColor[m_CurrentGame.CurrentPlayer]; Controls.Add(r_CurrentPlayerLabel); posY += r_CurrentPlayerLabel.PreferredHeight + k_DistanceButton; r_PlayerLabel[0].Left = k_DistanceButton; r_PlayerLabel[0].Top = posY; setFormattedPlayerLabel(0); r_PlayerLabel[0].BackColor = r_PlayerColor[0]; r_PlayerLabel[0].AutoSize = true; Controls.Add(r_PlayerLabel[0]); posY += r_PlayerLabel[0].PreferredHeight + k_DistanceButton; r_PlayerLabel[1].Left = k_DistanceButton; r_PlayerLabel[1].Top = posY; setFormattedPlayerLabel(1); r_PlayerLabel[1].BackColor = r_PlayerColor[1]; r_PlayerLabel[1].AutoSize = true; Controls.Add(r_PlayerLabel[1]); MaximizeBox = false; StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; Padding = new Padding(0, 0, k_DistanceButton, k_DistanceButton); }
private void currentButton_Click(object sender, EventArgs e) { GameButton button = sender as GameButton; button.BackColor = r_PlayerColor[m_CurrentGame.CurrentPlayer]; button.BackgroundImage = r_PicturesMap.GetPathByKey(m_CurrentGame.GetKey(button.Location)); button.BackgroundImageLayout = ImageLayout.Stretch; button.Enabled = false; if (!m_FirstChosen.Equals(string.Empty)) { if (m_CurrentGame.RunTurnPlayer(m_FirstChosen, button.Location)) { return; } m_SecondChosen = button.Location; setCurrentPlayerLabel(m_CurrentGame.CurrentPlayer); } else { m_FirstChosen = button.Location; } }