Created
January 22, 2019 11:51
-
-
Save owenselles/418881b1ac7d4eebc46b6fe7d929abf9 to your computer and use it in GitHub Desktop.
Pokemon Game Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nl.delphinity.pokemon.model.general; | |
import nl.delphinity.pokemon.model.battle.Attack; | |
import nl.delphinity.pokemon.model.trainer.Trainer; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class Pokemon { | |
private final int maxPP; | |
private Random randomGenerator; | |
private final int currentPP; | |
private final Random r = new Random(); | |
private PokemonData pokedata; | |
private Trainer owner; | |
private int currentHp; | |
private int maxHp; | |
private int level; | |
private int xpToNext; | |
private int currentXp; | |
public Pokemon(PokemonData pokedata) { | |
this.pokedata = pokedata; | |
this.currentHp = pokedata.maxHp; | |
this.maxHp = pokedata.maxHp; | |
this.currentPP = pokedata.maxPp; | |
this.maxPP = pokedata.maxPp; | |
this.level = 5; | |
this.xpToNext = 8; | |
this.currentXp = 0; | |
} | |
public PokemonData getPokedata() { | |
return pokedata; | |
} | |
public int getCurrentHp() { | |
return currentHp; | |
} | |
public void setCurrentHp(int currentHp) { | |
this.currentHp = currentHp; | |
} | |
public void setCurrentXp(int currentXp) { | |
this.currentXp = currentXp; | |
} | |
public int getLevel() { | |
return level; | |
} | |
public void setLevel(int level) { | |
this.level = level; | |
} | |
public Trainer getOwner() { | |
return owner; | |
} | |
public void setOwner(Trainer owner) { | |
this.owner = owner; | |
} | |
public int getMaxHp() { | |
return maxHp; | |
} | |
public void setMaxHp(int maxHp) { | |
this.maxHp = maxHp; | |
} | |
private int getXpToNext() { | |
return xpToNext; | |
} | |
public List<Attack> getAttacks() { | |
List<Attack> attacks = new ArrayList<>(); | |
attacks.addAll(pokedata.specificAttacks); | |
attacks.addAll(pokedata.pokemonType.typeAttacks); | |
return attacks; | |
} | |
//TODO: US-PKM-O-4E | |
private void evolve() { | |
try | |
{ | |
Thread.sleep(3000); | |
} | |
catch(InterruptedException ex) | |
{ | |
Thread.currentThread().interrupt(); | |
} | |
this.pokedata = pokedata.evolvesIn; | |
} | |
//TODO: US-PKM-O-4D | |
public void gainXp(int amount) { | |
if (amount + owner.getActivePokemon().currentXp >= xpToNext) { | |
levelUp(); | |
int remainingXp = (owner.getActivePokemon().currentXp + amount) - xpToNext; | |
gainXp(remainingXp); | |
} else { | |
owner.getActivePokemon().currentXp = owner.getActivePokemon().currentXp + amount; | |
status(); | |
} | |
} | |
//TODO: US-PKM-O-4C | |
private void levelUp() { | |
//US-PKM-O-4C: Pokemon should be able to level up | |
Random ran = new Random(); | |
int hpIncrease = ran.nextInt(maxHp); | |
Pokemon activePokemon = owner.getActivePokemon(); | |
activePokemon.setCurrentHp(maxHp + hpIncrease); | |
xpToNext = xpToNext * 2; | |
currentXp = 0; | |
evolveCheck(); | |
activePokemon.level++; | |
} | |
//TODO: US-PKM-O-4E | |
private boolean evolveCheck() { | |
if (pokedata.evolvesIn != null && level >= pokedata.evolutionLevel) { | |
evolve(); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//TODO: US-PKM-O-4 | |
public void attack(Pokemon otherPokemon, Attack attack) { | |
//As a Pokemon trainer I want my Pokemon to be able to attack | |
attack.getPower(); | |
if (otherPokemon.getCurrentHp() - attack.getPower() < 0) { | |
otherPokemon.setCurrentHp(0); | |
} | |
else { | |
otherPokemon.setCurrentHp(currentHp = otherPokemon.getCurrentHp() - attack.getPower()); | |
} | |
} | |
//TODO: US-PKM-O-4B | |
public Attack getRandomAttack() { | |
List<Attack> attacks = new ArrayList<>(); | |
attacks.addAll(pokedata.specificAttacks); | |
attacks.addAll(pokedata.pokemonType.typeAttacks); | |
int index = randomGenerator.nextInt(attacks.size()); | |
return attacks.get(index); | |
} | |
public double getHpPercentage() { | |
return currentHp / maxHp * 100; | |
} | |
public void status() { | |
System.out.println("----------------"); | |
System.out.println(this.getPokedata().name()); | |
System.out.println("LVL " + this.level); | |
System.out.println("HP " + this.currentHp + "/" + this.maxHp); | |
System.out.println("PP" + this.currentPP + "/" + this.maxPP); | |
System.out.println("XP " + this.currentXp + "/" + this.xpToNext); | |
} | |
//TODO: US-PKM-O-5 | |
public boolean isKnockout() { | |
if (currentHp <= 0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment