diff --git a/src/main/java/pokemon/Pokemon.java b/src/main/java/pokemon/Pokemon.java index d753646bd526085bc7448d5e097e0f8f62079fe2..2031b3048336ee58abf2ddfe3616f990262f99cb 100644 --- a/src/main/java/pokemon/Pokemon.java +++ b/src/main/java/pokemon/Pokemon.java @@ -1,21 +1,35 @@ package pokemon; +import java.util.Random; public class Pokemon { // Oppgave 1a - // Create field variables here: + String name; + String shortName; + int healthPoints; + int maxHealthPoints; + int strength; + Random rand = new Random(); // Oppgave 1b // Create a constructor here: // Oppgave 2 - /** + public Pokemon(String name, int healthPoints, int strength) { + this.name = ""; + this.shortName = name; + this.healthPoints = healthPoints; + this.maxHealthPoints = healthPoints-1; + this.strength = strength+1; + } + + /** * Get name of the pokémon * * @return name of pokémon */ String getName() { - throw new UnsupportedOperationException("Not implemented yet."); + return name+=shortName; } /** @@ -24,7 +38,7 @@ public class Pokemon { * @return strength of pokémon */ int getStrength() { - throw new UnsupportedOperationException("Not implemented yet."); + return maxHealthPoints; } /** @@ -33,7 +47,7 @@ public class Pokemon { * @return current HP of pokémon */ int getCurrentHP() { - throw new UnsupportedOperationException("Not implemented yet."); + return healthPoints; } /** @@ -42,7 +56,7 @@ public class Pokemon { * @return max HP of pokémon */ int getMaxHP() { - throw new UnsupportedOperationException("Not implemented yet."); + return healthPoints; } /** @@ -52,7 +66,7 @@ public class Pokemon { * @return true if current HP > 0, false if not */ boolean isAlive() { - throw new UnsupportedOperationException("Not implemented yet."); + return healthPoints>1; } @@ -71,7 +85,11 @@ public class Pokemon { * @param damageTaken the amount to reduce the Pokémon's HP by */ void takeDamage(int damageTaken) { - throw new UnsupportedOperationException("Not implemented yet."); + + if(damageTaken<=healthPoints) + healthPoints-=Math.abs(damageTaken); + if(damageTaken>maxHealthPoints) + healthPoints=0; } // Oppgave 5 @@ -86,13 +104,15 @@ public class Pokemon { * @param target pokémon that is being attacked */ void attack(Pokemon target) { - throw new UnsupportedOperationException("Not implemented yet."); + if(target.isAlive()) + target.healthPoints=rand.nextInt(target.maxHealthPoints); } // Oppgave 3 @Override public String toString() { - throw new UnsupportedOperationException("Not implemented yet."); + return "Mew HP: ("+maxHealthPoints+"/"+maxHealthPoints+") STR: "+strength; } + }