public void Button_Click(object sender, EventArgs e)
        {
            if (gPanel == null)
            {
                foreach (Form form in Application.OpenForms)
                {
                    if (form.GetType() == typeof(GamePanel))
                    {
                        gPanel = (GamePanel)form;
                    }
                }
            }
            Button button = (Button)sender;

            if (panel1.Contains(button) && !fight)
            {
                ///////////////////////////////////////////CARIERY
                if (carriers == 0 && stage1 == 0)
                {
                    stage1++;
                }
                if (stage1 == 0 && carriers > 0)
                {
                    if (currentSize == 0 && button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\carBack.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        previousButton = button;
                        startingButton = button;
                        usedSpacePlayer.Add(button);
                        currentSize++;
                        ///
                        for (int i = 0; i < size; i++)
                        {
                            for (int j = 0; j < size; j++)
                            {
                                if (helpTab[i, j] == button)
                                {
                                    row    = i;
                                    column = j;
                                }
                            }
                        }
                        ///
                    }
                    else
                    {
                        if (help.rowContains(helpTab, row, size, button, previousButton))
                        {
                            if (tab.IndexOf(previousButton) > tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                            }
                            button.BackgroundImage       = Image.FromFile(@"img\carMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            usedSpacePlayer.Add(button);
                            currentSize++;
                            if (currentSize == 5)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\carFront.jpg");
                                if (tab.IndexOf(startingButton) > tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        if (help.columnContains(helpTab, column, size, button, previousButton))
                        {
                            button.BackgroundImage       = Image.FromFile(@"img\carMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;
                            button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                            if (tab.IndexOf(previousButton) < tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            }

                            button.Refresh();
                            previousButton.Refresh();
                            previousButton = button;
                            usedSpacePlayer.Add(button);
                            currentSize++;
                            if (currentSize == 5)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\carFront.jpg");
                                if (tab.IndexOf(startingButton) < tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                else
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        startingButton.Refresh();
                    }

                    if (currentSize == 5)
                    {
                        currentSize = 0;
                        currentAmount1++;
                    }
                    if (currentAmount1 == carriers)
                    {
                        stage1++;
                        currentAmount1 = 0;
                    }
                }
                ///////////////////////////////////////////BATTLESHIPS
                if (battleships == 0 && stage1 == 1)
                {
                    stage1++;
                }
                if (stage1 == 1 && battleships > 0)
                {
                    if (currentSize == 0 && button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\batBack.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        previousButton = button;
                        startingButton = button;
                        usedSpacePlayer.Add(button);
                        currentSize++;
                        ///
                        for (int i = 0; i < size; i++)
                        {
                            for (int j = 0; j < size; j++)
                            {
                                if (helpTab[i, j] == button)
                                {
                                    row    = i;
                                    column = j;
                                }
                            }
                        }
                        ///
                    }
                    else
                    {
                        if (help.rowContains(helpTab, row, size, button, previousButton))
                        {
                            if (tab.IndexOf(previousButton) > tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                            }
                            button.BackgroundImage       = Image.FromFile(@"img\batMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 4)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\batFront.jpg");
                                if (tab.IndexOf(startingButton) > tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        if (help.columnContains(helpTab, column, size, button, previousButton))
                        {
                            button.BackgroundImage       = Image.FromFile(@"img\batMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;
                            button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                            if (tab.IndexOf(previousButton) < tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            }

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 4)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\batFront.jpg");
                                if (tab.IndexOf(startingButton) < tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                else
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        startingButton.Refresh();
                    }
                    if (currentSize == 4)
                    {
                        currentSize = 0;
                        currentAmount1++;
                    }
                    if (currentAmount1 == battleships)
                    {
                        stage1++;
                        currentAmount1 = 0;
                    }
                }
                //////////////////////////////////////////DESTORYERS
                if (destroyers == 0 && stage1 == 2)
                {
                    stage1++;
                }
                if (stage1 == 2 && destroyers > 0)
                {
                    if (currentSize == 0 && button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\desBack.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        previousButton = button;
                        startingButton = button;
                        usedSpacePlayer.Add(button);
                        currentSize++;
                        ///
                        for (int i = 0; i < size; i++)
                        {
                            for (int j = 0; j < size; j++)
                            {
                                if (helpTab[i, j] == button)
                                {
                                    row    = i;
                                    column = j;
                                }
                            }
                        }
                        ///
                    }
                    else
                    {
                        if (help.rowContains(helpTab, row, size, button, previousButton))
                        {
                            if (tab.IndexOf(previousButton) > tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                            }
                            button.BackgroundImage       = Image.FromFile(@"img\desMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 3)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\desFront.jpg");
                                if (tab.IndexOf(startingButton) > tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        if (help.columnContains(helpTab, column, size, button, previousButton))
                        {
                            button.BackgroundImage       = Image.FromFile(@"img\desMid.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;
                            button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                            if (tab.IndexOf(previousButton) < tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            }

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 3)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\desFront.jpg");
                                if (tab.IndexOf(startingButton) < tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                else
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        startingButton.Refresh();
                    }
                    if (currentSize == 3)
                    {
                        currentSize = 0;
                        currentAmount1++;
                    }
                    if (currentAmount1 == destroyers)
                    {
                        stage1++;
                        currentAmount1 = 0;
                    }
                }
                //////////////////////////////////////////SUBMARINES
                if (submarines == 0 && stage1 == 3)
                {
                    stage1++;
                }
                if (stage1 == 3 && submarines > 0)
                {
                    if (currentSize == 0 && button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\subBack.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        previousButton = button;
                        startingButton = button;
                        currentSize++;
                        usedSpacePlayer.Add(button);
                        ///
                        for (int i = 0; i < size; i++)
                        {
                            for (int j = 0; j < size; j++)
                            {
                                if (helpTab[i, j] == button)
                                {
                                    row    = i;
                                    column = j;
                                }
                            }
                        }
                        ///
                    }
                    else
                    {
                        if (help.rowContains(helpTab, row, size, button, previousButton))
                        {
                            if (tab.IndexOf(previousButton) > tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                            }
                            button.BackgroundImage       = Image.FromFile(@"img\subFront.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 2)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\subFront.jpg");
                                if (tab.IndexOf(startingButton) > tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }
                        if (help.columnContains(helpTab, column, size, button, previousButton))
                        {
                            button.BackgroundImage       = Image.FromFile(@"img\subFront.jpg");
                            button.BackgroundImageLayout = ImageLayout.Stretch;
                            button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                            if (tab.IndexOf(previousButton) < tab.IndexOf(button))
                            {
                                previousButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                            }

                            button.Refresh();
                            previousButton.Refresh();

                            previousButton = button;
                            currentSize++;
                            usedSpacePlayer.Add(button);
                            if (currentSize == 2)
                            {
                                button.BackgroundImage = Image.FromFile(@"img\subFront.jpg");
                                if (tab.IndexOf(startingButton) < tab.IndexOf(button))
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate270FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                else
                                {
                                    button.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                    startingButton.BackgroundImage.RotateFlip(RotateFlipType.Rotate90FlipY);
                                }
                                button.BackgroundImageLayout = ImageLayout.Stretch;
                            }
                        }

                        startingButton.Refresh();
                    }
                    if (currentSize == 2)
                    {
                        currentSize = 0;
                        currentAmount1++;
                    }
                    if (currentAmount1 == submarines)
                    {
                        stage1++;
                        currentAmount1 = 0;
                    }
                }
                //////////////////////////////////////////PATROL BOATS
                if (patrol == 0 && stage1 == 4)
                {
                    stage1++;
                }
                if (stage1 == 4 && patrol > 0)
                {
                    if (currentSize == 0 && button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\patrol.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        previousButton = button;
                        startingButton = button;
                        currentSize++;
                        ///
                        for (int i = 0; i < size; i++)
                        {
                            for (int j = 0; j < size; j++)
                            {
                                if (helpTab[i, j] == button)
                                {
                                    row    = i;
                                    column = j;
                                }
                            }
                        }
                        ///
                    }
                    if (currentSize == 1)
                    {
                        currentSize = 0;
                        currentAmount1++;
                        usedSpacePlayer.Add(button);
                    }
                    if (currentAmount1 == patrol)
                    {
                        stage1++;
                        currentAmount1 = 0;
                    }
                }
                ////////////////////////////koniec placementu
                if (stage1 == 5)
                {
                    fight = true;
                }
                ///koniec placementu\
            }
            if (fight && !roundEnded)
            {
                Console.WriteLine(usedSpace.Count.ToString());
                Console.WriteLine(usedSpacePlayer.Count.ToString());
                if (panel2.Contains(button))
                {
                    if (usedSpace.Contains(button))
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\fire.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        playerScore++;
                        playerAttacked = true;
                        usedSpace.Remove(button);
                        gPanel.historyTextBox.AppendText(Environment.NewLine + "PLA-hit!");
                    }
                    if (button.BackgroundImage == null)
                    {
                        button.BackgroundImage       = Image.FromFile(@"img\miss.jpg");
                        button.BackgroundImageLayout = ImageLayout.Stretch;
                        gPanel.historyTextBox.AppendText(Environment.NewLine + "PLA-miss!");
                        playerAttacked = true;
                    }
                    if (!playerAttacked)
                    {
                        return;
                    }
                }
                playerAttacked = false;
                ///////////////////////////////////////////////////////
                if (help.checkWinner(playerScore, maxPoints))
                {
                    roundEnded = true;
                    winner     = "Player";
                }
                ///////////////////////////////////////////////////////
                while (!aiAttacked && !roundEnded)
                {
                    aiAttack         = random.Next(0, size * size);
                    aiAttackedButton = tab.ElementAt(aiAttack);
                    if (usedSpacePlayer.Contains(aiAttackedButton))
                    {
                        aiAttackedButton.BackgroundImage = Image.FromFile(@"img\fire.jpg");
                        aiScore++;
                        aiAttacked = true;
                        usedSpacePlayer.Remove(aiAttackedButton);
                        gPanel.historyTextBox.AppendText(Environment.NewLine + "AI-hit!");
                    }
                    else
                    {
                        if (aiAttackedButton.BackgroundImage == null)
                        {
                            aiAttackedButton.BackgroundImage = Image.FromFile(@"img\miss.jpg");
                            aiAttacked = true;
                            gPanel.historyTextBox.AppendText(Environment.NewLine + "AI-miss!");
                        }
                    }
                    aiAttackedButton.BackgroundImageLayout = ImageLayout.Stretch;
                }
                aiAttacked = false;
                ///////////////////////////////////////////////////////
                if (help.checkWinner(aiScore, maxPoints))
                {
                    roundEnded = true;
                    winner     = "AI";
                }
                ///////////////////////////////////////////////////////
            }
            help.actualizeGamePanel(playerScore, aiScore);
            if (roundEnded)
            {
                help.EndGame(this);
            }
        }