Example #1
0
        public override Board shoot(Player opponent, Board boardOpponent)
        {
            List <SeaElement> elementPlayer = boardOpponent.SeaElementList;

            SeaElement shootable = ButtonBuffer.getPressedSeaElement(); // case ayant été cliquée

            if (shootable == null)
            {
                return(null);
            }
            if (shootable.button.Name[1] != '2')
            {
                return(null);
            }

            if (opponent.id == 2)
            {
                ButtonBuffer.setPressedSeaElement(null);
                shootable.known = true; // on révèle la case
                if (shootable.state == State.Water)
                {
                    shootable.state = State.Plouf; // raté !
                }
                if (shootable.state == State.Boat)
                {
                    for (int nboat = 0; nboat < opponent.boatList.Length; nboat++)
                    {
                        {
                            Boat currentBoat = opponent.boatList[nboat]; // on recherche le bateau à qui appartient la case que l'on a touchée
                            for (int element = 0; element < currentBoat.size; element++)
                            {
                                if ((shootable.posX == currentBoat.position[element].posX) && (shootable.posY == currentBoat.position[element].posY))
                                {
                                    int pv = currentBoat.Life();
                                    if (pv > 1)
                                    {
                                        shootable.state = State.Touched; // touché !
                                    }
                                    else
                                    {
                                        for (int element2 = 0; element2 < currentBoat.size; element2++)
                                        {
                                            currentBoat.position[element2].state = State.Sunk; // si le bateau est coulé, on change tous ses éléments en "Sunk"
                                        }
                                        shootable.state = State.Sunk;                          // coulé!
                                    }
                                }
                            }
                            opponent.boatList[nboat] = currentBoat;
                        }
                    }
                }
            }
            return(boardOpponent);
        }
Example #2
0
        public override Board shoot(Player opponent, Board boardOpponent)
        {
            List <int> targetable = new List <int> {
            };                                        // liste des éléments sur lesquels on n'a pas encore tiré

            for (int index = 0; index < boardOpponent.SeaElementList.Count; index++)
            {
                if (boardOpponent.SeaElementList[index].state != State.Plouf && boardOpponent.SeaElementList[index].state != State.Touched && boardOpponent.SeaElementList[index].state != State.Sunk)
                {
                    targetable.Add(index);
                }
            }
            Random     random      = new Random();
            int        targetIndex = targetable[random.Next(targetable.Count)]; // on tire au hasard sur une case encore inconnue
            SeaElement target      = boardOpponent.SeaElementList[targetIndex];

            if (target.button.Name[1] != '1')
            {
                return(null);
            }

            if (target.state == State.Water)
            {
                target.state = State.Plouf;                              // raté !
            }
            else if (target.state == State.Boat)
            {
                for (int nboat = 0; nboat < opponent.boatList.Length; nboat++)
                {
                    Boat currentBoat = opponent.boatList[nboat]; // on recherche le bateau à qui appartient la case que l'on a touchée
                    for (int element = 0; element < currentBoat.size; element++)
                    {
                        if ((target.posX == currentBoat.position[element].posX) && (target.posY == currentBoat.position[element].posY))
                        {
                            int pv = currentBoat.Life();
                            if (pv > 1)
                            {
                                target.state = State.Touched; // touché !
                            }
                            else
                            {
                                for (int element2 = 0; element2 < currentBoat.size; element2++)
                                {
                                    currentBoat.position[element2].state = State.Sunk; // si le bateau est coulé, on change tous ses éléments en "Sunk"
                                }
                                target.state = State.Sunk;                             // coulé !
                            }
                        }
                    }
                }
                boardOpponent.SeaElementList[targetIndex] = target;
            }
            return(boardOpponent);
        }