I am having an issue with a health counter in my battleship game. What I need is that when the method is called, it will take 1 off of health. So let's say that the health is at 3, the method is called when the players ship takes a hit. Then I need it to go health-1
, and keep that value. Then when the health=0
, the game will end.
Any questions and improvements to this code is welcome, as well as criticism.
UPDATED:
public static void enemyShoot (int row, int col)
{
int shot1;
int shot2;
int health = 3;
Random enemyshot = new Random();
shot1 = enemyshot.nextInt(5)+1;
shot2 = enemyshot.nextInt(5)+1;
if (shot1 == row && shot2 == col)
{
System.out.println("You Have Been Hit");
health = Health(health);
}
}
public static int Health (int health)
{
if (health == 0){
System.out.println("You dead");
System.exit(0);
}
health = health-1;
return health;
}