Skip to content
Snippets Groups Projects
Commit 48006437 authored by Martin Vatshelle's avatar Martin Vatshelle
Browse files

Code passes all tests

There are still some bugs we need to remove
parent b8cbd928
No related branches found
No related tags found
No related merge requests found
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment