Exemplo n.º 1
0
        private void PCShoot(ref int[,] fieldArray, ref int[,] shoots1, ref int[,] shoots2, ref int[,] shoots3)
        {
            int x, y;

            int [,] count;
            int lines;
            int rand;

            Battleships.Direction direction1 = new Battleships.Direction();
            Battleships.Direction direction2 = new Battleships.Direction();
            if (Battleships.SearchDamaged(fieldArray1, out count) == true)
            {
                lines = Battleships.CountArrayLines(count);
                if (lines > 1)
                {
                    rand = r.Next(lines);
                    Battleships.FindDamagedDirection(count[0, rand], count[1, rand], fieldArray1, ref direction1, ref direction2);
                    while (ShootRandomDirection(count[0, rand], count[1, rand], direction1, direction2) == false)
                    {
                        rand = r.Next(lines);
                    }
                    ;
                }
                else
                {
                    while (ShootRandomDirection(count[0, 0], count[1, 0], Battleships.Direction.Null, Battleships.Direction.Null) == false)
                    {
                        ;
                    }
                }
            }
            else
            {
                if (Battleships.CountArrayLines(shoots1) == 0)
                {
                    if (Battleships.CountArrayLines(shoots2) == 0)
                    {
                        if (Battleships.CountArrayLines(shoots3) == 0)
                        {
                        }
                        else
                        {
                            Battleships.ChooseRandomCoordinates(ref shoots3, out x, out y);
                            while (fieldArray1[x + 1, y + 1] != (int)Battleships.State.Alive && fieldArray1[x + 1, y + 1] != (int)Battleships.State.Empty)
                            {
                                if (Battleships.CountArrayLines(shoots3) == 0)
                                {
                                    break;
                                }
                                Battleships.ChooseRandomCoordinates(ref shoots3, out x, out y);
                            }
                            Shoot(x, y, ref fieldArray1, ref Field1);
                        }
                    }
                    else
                    {
                        Battleships.ChooseRandomCoordinates(ref shoots2, out x, out y);
                        while (fieldArray1[x + 1, y + 1] != (int)Battleships.State.Alive && fieldArray1[x + 1, y + 1] != (int)Battleships.State.Empty)
                        {
                            if (Battleships.CountArrayLines(shoots2) == 0)
                            {
                                break;
                            }
                            Battleships.ChooseRandomCoordinates(ref shoots2, out x, out y);
                        }
                        Shoot(x, y, ref fieldArray1, ref Field1);
                    }
                }
                else
                {
                    Battleships.ChooseRandomCoordinates(ref shoots1, out x, out y);
                    while (fieldArray1[x + 1, y + 1] != (int)Battleships.State.Alive && fieldArray1[x + 1, y + 1] != (int)Battleships.State.Empty)
                    {
                        if (Battleships.CountArrayLines(shoots1) == 0)
                        {
                            break;
                        }
                        Battleships.ChooseRandomCoordinates(ref shoots1, out x, out y);
                    }
                    Shoot(x, y, ref fieldArray1, ref Field1);
                }
            }
        }