Exemple #1
0
        private void PlayerSetupShips()
        {
            int coorX = selectX;
            int coorY = selectY;
            int direc = selectDir;
            int size;

            if (setCarrier < gameOptions.countCarrier)
            {
                size = gameOptions.sizeCarrier;

                if (ValidTile(coorX, coorY, direc, field1Own, size) == true)
                {
                    switch (direc)
                    {
                    case 0:
                        for (int i = coorX; i < coorX + size; i++)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 1:
                        for (int i = coorY; i < coorY + size; i++)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    case 2:
                        for (int i = coorX; i > coorX - size; i--)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 3:
                        for (int i = coorY; i > coorY - size; i--)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    default:
                        break;
                    }
                    setCarrier++;
                }
            }

            else if (setBattleship < gameOptions.countBattleship)
            {
                size = gameOptions.sizeBattleship;

                if (ValidTile(coorX, coorY, direc, field1Own, size) == true)
                {
                    switch (direc)
                    {
                    case 0:
                        for (int i = coorX; i < coorX + size; i++)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 1:
                        for (int i = coorY; i < coorY + size; i++)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    case 2:
                        for (int i = coorX; i > coorX - size; i--)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 3:
                        for (int i = coorY; i > coorY - size; i--)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    default:
                        break;
                    }
                    setBattleship++;
                }
            }

            else if (setCruiser < gameOptions.countCruiser)
            {
                size = gameOptions.sizeCruiser;

                if (ValidTile(coorX, coorY, direc, field1Own, size) == true)
                {
                    switch (direc)
                    {
                    case 0:
                        for (int i = coorX; i < coorX + size; i++)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 1:
                        for (int i = coorY; i < coorY + size; i++)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    case 2:
                        for (int i = coorX; i > coorX - size; i--)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 3:
                        for (int i = coorY; i > coorY - size; i--)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    default:
                        break;
                    }
                    setCruiser++;
                }
            }

            else if (setSubmarine < gameOptions.countSubmarine)
            {
                size = gameOptions.sizeSubmarine;

                if (ValidTile(coorX, coorY, direc, field1Own, size) == true)
                {
                    switch (direc)
                    {
                    case 0:
                        for (int i = coorX; i < coorX + size; i++)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 1:
                        for (int i = coorY; i < coorY + size; i++)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    case 2:
                        for (int i = coorX; i > coorX - size; i--)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 3:
                        for (int i = coorY; i > coorY - size; i--)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    default:
                        break;
                    }
                    setSubmarine++;
                }
            }

            else if (setDestroyer < gameOptions.countDestroyer)
            {
                size = gameOptions.sizeDestroyer;

                if (ValidTile(coorX, coorY, direc, field1Own, size) == true)
                {
                    switch (direc)
                    {
                    case 0:
                        for (int i = coorX; i < coorX + size; i++)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 1:
                        for (int i = coorY; i < coorY + size; i++)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    case 2:
                        for (int i = coorX; i > coorX - size; i--)
                        {
                            field1Own[i, coorY] = 2;
                        }
                        break;

                    case 3:
                        for (int i = coorY; i > coorY - size; i--)
                        {
                            field1Own[coorX, i] = 2;
                        }
                        break;

                    default:
                        break;
                    }
                    setDestroyer++;
                }
            }
            if (setDestroyer == gameOptions.countDestroyer)
            {
                var Game = new GameWindow(gameOptions, field1Own);
                Game.Show();
                this.Close();
            }
            UpdateButtons();
        }