// 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); }
// 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); }
// 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); }