Ejemplo n.º 1
0
        // check if the coords provided is in the ships location, do not take away health, this is used for checking collisions when placing ships by the AI
        public bool CheckCollision(Coords placed)
        {
            foreach (Coords space in location)
            {
                if (placed.Equals(space))
                {
                    return(true);
                }
            }

            // if no match is found return false
            return(false);
        }
Ejemplo n.º 2
0
        // check if the shot hits and subtract health if it did
        public bool CheckHit(Coords shot)
        {
            foreach (Coords space in location)
            {
                if (shot.Equals(space))
                {
                    health--;
                    return(true);
                }
            }

            // if no match is found return false
            return(false);
        }
Ejemplo n.º 3
0
        // go through each of the past guesses to make sure we aren't guessing a previous guess
        private bool ValidateGuess(Coords guess)
        {
            // if out of bounds it is false
            if (guess.x < 0 || guess.x > 9 || guess.y < 0 || guess.y > 9)
            {
                return(false);
            }

            // if it is a past guess it is false
            foreach (Coords space in pastGuesses)
            {
                if (guess.Equals(space))
                {
                    return(false);
                }
            }

            return(true);
        }