Uploaded main files

This commit is contained in:
Kristian Knarvik 2017-11-24 16:02:57 +01:00 committed by GitHub
parent 12265045d3
commit 42ff37ce5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1512 additions and 0 deletions

452
Game.java Normal file
View File

@ -0,0 +1,452 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.NumberFormatException;
import java.text.NumberFormat;
import java.util.Locale;
import java.text.ParseException;
/** Simulates the game Pokémon. */
public class Game {
public static void main(String[] args) {
ArrayList<Pokemon> pokemon = readPokemon();
int initialPokemon = pokemon.size();
ArrayList<Pokemon> temporaryPokemonList = readPokemon();
ArrayList<Pokemon> usersPokemon = new ArrayList<Pokemon>();
for (int i = 1; i <= 6; i++) {
usersPokemon.add(pick(temporaryPokemonList));
}
temporaryPokemonList.clear();
ArrayList<Item> usersItems = prepareInventory();
boolean done = false;
Pokemon opponentPokemon = null;
Pokemon trainersPokemon = null;
Item currentItem = null;
boolean fleeSuccess = false;
Pokemon pokemonToHeal = null;
Scanner in = new Scanner(System.in);
opponentPokemon = randomPokemon(pokemon);
System.out.printf("A wild %s appeared.%n", opponentPokemon.getName());
while (!done) {
if (opponentPokemon == null) {
System.out.printf("You have brutally murdered %d pokemon.%n"
+ "The only ones left are the ones in your posession.%n"
+ "There really is nothing more to do here.%n", initialPokemon);
return;
}
if (!consciousPokemon(usersPokemon)) {
System.out.println("All your pokemon have fainted. Your journey ends here.");
return;
}
while (trainersPokemon == null || !trainersPokemon.isConscious()) {
availablePokemon(usersPokemon, "conscious");
trainersPokemon = usersChoice(usersPokemon, true);
}
System.out.printf("Opponent: %s%nWhat will you do?%n", opponentPokemon);
System.out.printf("b: battle"
+ "%nh: heal or revive"
+ "%nt: throw pokeball"
+ "%nc: change pokemon"
+ "%nf: flee"
+ "%nv: view my pokemon"
+ "%ns: save"
+ "%nl: load"
+ "%nq: quit%n>");
char command = in.next().toLowerCase().charAt(0);
switch (command) {
case 'b':
if (opponentPokemon.isConscious() && trainersPokemon.isConscious()) {
trainersPokemon.attack(opponentPokemon);
if (opponentPokemon.isConscious()) {
opponentPokemon.attack(trainersPokemon);
if (!trainersPokemon.isConscious()) {
System.out.println("Your pokemon fainted.");
}
} else {
pokemonFainted(pokemon, opponentPokemon);
System.out.println("The opponent pokemon fainted.");
opponentPokemon = randomPokemon(pokemon);
}
}
break;
case 'h':
if (itemsLeft(usersItems, Item.Target.SELF)) {
availableItems(usersItems, Item.Target.SELF);
currentItem = chosenItem(usersItems, Item.Target.SELF);
if (currentItem == null) {
System.out.println("Invalid item.");
} else {
if (currentItem.needsAlive()) {
availablePokemon(usersPokemon, "conscious");
pokemonToHeal = usersChoice(usersPokemon, true);
} else {
availablePokemon(usersPokemon, "fainted");
pokemonToHeal = usersChoice(usersPokemon, false);
}
if (pokemonToHeal == null) {
System.out.println("That is not a valid pokemon");
} else {
if (currentItem.use(pokemonToHeal)) {
opponentPokemon.attack(trainersPokemon);
}
}
}
} else {
System.out.println("You have used all your healing items.");
}
break;
case 't':
if (itemsLeft(usersItems, Item.Target.OTHER)) {
availableItems(usersItems, Item.Target.OTHER);
currentItem = chosenItem(usersItems, Item.Target.OTHER);
if (currentItem == null) {
System.out.println("Invalid pokeball.");
} else {
if (currentItem.getName().toLowerCase().replace(" ", "").equals("masterball")) {
currentItem.use(opponentPokemon, pokemon, usersPokemon);
opponentPokemon = randomPokemon(pokemon);
System.out.printf("A wild %s appeared.%n", opponentPokemon.getName());
} else {
boolean captured = currentItem.use(opponentPokemon, pokemon, usersPokemon);
if (captured) {
opponentPokemon = randomPokemon(pokemon);
System.out.printf("A wild %s appeared.%n", opponentPokemon.getName());
} else {
opponentPokemon.attack(trainersPokemon);
}
}
}
} else {
System.out.println("You have used all your pokeballs.");
}
break;
case 'c':
availablePokemon(usersPokemon, "conscious");
trainersPokemon = usersChoice(usersPokemon, true);
while (trainersPokemon == null) {
availablePokemon(usersPokemon, "conscious");
trainersPokemon = usersChoice(usersPokemon, true);
}
opponentPokemon.attack(trainersPokemon);
break;
case 's':
savePokemon(pokemon, "pokemon.save");
savePokemon(usersPokemon, "user.save");
saveItems(usersItems, "items.save");
break;
case 'l':
ArrayList<Pokemon> loadedPokemon = loadPokemon("pokemon.save");
ArrayList<Pokemon> loadedUsersPokemon = loadPokemon("user.save");
ArrayList<Item> loadedUsersItems = loadItems("items.save");
if (loadedPokemon == null || loadedUsersPokemon == null || loadedUsersItems == null) {
System.out.println("One or more savefiles seem corrupt. Please delete or fix the affected file(s).");
} else {
pokemon = loadedPokemon;
usersPokemon = loadedUsersPokemon;
usersItems = loadedUsersItems;
if (pokemon.size() > 0 && usersPokemon.size() > 0) {
do {
availablePokemon(usersPokemon, "conscious");
trainersPokemon = usersChoice(usersPokemon, true);
} while (trainersPokemon == null || !trainersPokemon.isConscious());
opponentPokemon = randomPokemon(pokemon);
}
}
break;
case 'f':
fleeSuccess = trainersPokemon.flee(opponentPokemon);
if (fleeSuccess) {
System.out.println("You fled the battle.");
opponentPokemon = randomPokemon(pokemon);
System.out.printf("A wild %s appeared.%n", opponentPokemon.getName());
} else {
System.out.printf("Failed to flee from %s.%n", opponentPokemon.getName());
opponentPokemon.attack(trainersPokemon);
}
break;
case 'v':
availablePokemon(usersPokemon, "all");
System.out.println();
break;
case 'q':
done = true;
break;
default:
System.out.println("[Invalid command]");
}
}
}
/**
* Prevents wild fainted pokemon to ever be encountered again.
* @param pokemonList List of pokemon to search.
* @param target The pokemon to remove.
*/
public static void pokemonFainted(ArrayList<Pokemon> pokemonList, Pokemon target) {
for (int i = 0; i < pokemonList.size(); i++) {
if (pokemonList.get(i).equals(target)) {
pokemonList.remove(i);
}
}
}
/**
* Lists all currently available items for the user.
* @param items List of all of the user's items.
* @param target We are either listing items targeted at an opponent pokemon or at our own pokemon.
*/
public static void availableItems(ArrayList<Item> items, Item.Target target) {
System.out.println("You may choose from these items:");
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getAmount() > 0 && items.get(i).getTarget().equals(target)) {
System.out.printf("%d: %s%n", i + 1, items.get(i));
}
}
System.out.print(">");
}
/**
* Gives a trainer necessary starting items.
* @return A list of items.
*/
public static ArrayList<Item> prepareInventory() {
ArrayList<Item> usersItems = new ArrayList<Item>();
usersItems.add(new Item("Poke Ball", "A device for catching wild Pokémon. It's thrown like a ball at a Pokémon, comfortably encapsulating its target.", 15, Item.Target.OTHER));
usersItems.add(new Item("Great ball", "A good, high-performance Poké Ball that provides a higher Pokémon catch rate than a standard Poké Ball.", 10, Item.Target.OTHER));
usersItems.add(new Item("Ultra ball", "An ultra-high-performance Poké Ball that provides a higher success rate for catching Pokémon than a Great Ball.", 5, Item.Target.OTHER));
usersItems.add(new Item("Master ball", "The best Poké Ball with the ultimate level of performance. With it, you will catch any wild Pokémon without fail.", 1, Item.Target.OTHER));
usersItems.add(new Item("Potion", "Heals a pokemon for 20 HP.", 20, Item.Target.SELF));
usersItems.add(new Item("Super Potion", "Heals a pokemon for 50 HP.", 10, Item.Target.SELF));
usersItems.add(new Item("Hyper Potion", "Heals a pokemon for 200 HP.", 5, Item.Target.SELF));
usersItems.add(new Item("Max Potion", "Fully heals a pokemon.", 1, Item.Target.SELF));
usersItems.add(new Item("Revive", "Revives a fainted pokemon.", 2, Item.Target.SELF, false));
return usersItems;
}
/**
* Checks if the user has any item left of any type.
* @param items List of all of the user's items.
* @return True if any items are left. False otherwise.
*/
public static boolean itemsLeft(ArrayList<Item> items, Item.Target target) {
int count = 0;
for (Item item : items) {
if (item.getAmount() > 0 && item.getTarget().equals(target)) {
count++;
}
}
return count > 0;
}
/**
* Lists all currently available pokemon for the user.
* @param pokemonList List of all the user's pokemon.
* @param type Should we only include a certain type of pokemon.
*/
public static void availablePokemon(ArrayList<Pokemon> pokemonList, String type) {
System.out.println("You may choose from these pokemon:");
for (int i = 0; i < pokemonList.size(); i++) {
switch (type) {
case "conscious":
if (pokemonList.get(i).isConscious()) {
System.out.printf("%d: %s%n", i + 1, pokemonList.get(i));
}
break;
case "fainted":
if (!pokemonList.get(i).isConscious()) {
System.out.printf("%d: %s%n", i + 1, pokemonList.get(i));
}
break;
default:
System.out.printf("%d: %s%n", i + 1, pokemonList.get(i));
}
}
System.out.print(">");
}
/**
* Checks if all of the pokemon in a list have fainted.
* @param pokemonList List of the user's pokemon.
* @return True if the user has at least one pokemon left. False otherwise.
*/
public static boolean consciousPokemon(ArrayList<Pokemon> pokemonList) {
int pokemonLeft = 0;
for (Pokemon pokemon : pokemonList) {
if (pokemon.isConscious()) {
pokemonLeft++;
}
}
return pokemonLeft > 0;
}
/**
* Asks the user for the name of a pokemon and returns it.
* @param pokemonList A list of available pokemon
* @return A pokemon object or null.
*/
public static Pokemon usersChoice(ArrayList<Pokemon> pokemonList, boolean alive) {
Scanner in = new Scanner(System.in);
if (in.hasNextInt()) {
int choice = in.nextInt() - 1;
in.nextLine();
if (choice >= 0 && choice < pokemonList.size() && alive && pokemonList.get(choice).isConscious()) {
return pokemonList.get(choice);
} else if (choice >= 0 && choice < pokemonList.size() && !alive && !pokemonList.get(choice).isConscious()) {
return pokemonList.get(choice);
} else {
System.out.println("Invalid pokemon");
}
}
return null;
}
/**
* Asks the user for an item, and validates it.
* @param itemList Available items.
* @return An Item object or null.
*/
public static Item chosenItem(ArrayList<Item> itemList, Item.Target target) {
Scanner in = new Scanner(System.in);
if (in.hasNextInt()) {
int choice = in.nextInt() - 1;
in.nextLine();
if (choice >= 0 && choice < itemList.size()) {
return itemList.get(choice);
} else {
System.out.println("Invalid item");
}
}
return null;
}
/**
* Chooses a random pokemon from a list.
* @param pokemon The list to choose from.
* @return A Pokemon object, or null if the list is empty.
*/
public static Pokemon randomPokemon(ArrayList<Pokemon> pokemon) {
if (pokemon.size() > 0) {
return pokemon.get((int)(Math.random() * pokemon.size()));
} else {
return null;
}
}
/**
* Reads pokemon from Pokemon.txt to an ArrayList.
* @return An ArrayList of pokemon objects.
*/
public static ArrayList<Pokemon> readPokemon() {
ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
try (Scanner in = new Scanner(new File("Pokemon.txt"))) {
while (in.hasNextLine()) {
pokemon.add(new Pokemon(in.nextLine()));
}
} catch (FileNotFoundException e) {
System.out.println("You seem to be missing one of the necessary files to run this program.");
}
return pokemon;
}
/**
* Picks a random pokemon from a list.
* @param pokemon A list of pokemon objects.
* @return A pokemon object.
*/
public static Pokemon pick(ArrayList<Pokemon> pokemon) {
int index = (int)(Math.random() * (pokemon.size()));
Pokemon randomPokemon = pokemon.get(index);
pokemon.remove(index);
return randomPokemon;
}
/**
* Saves all pokemon in a list with stats to a text file.
* @param pokemonList List of Pokemon objects to save.
* @param savefile The file to write to.
*/
public static void savePokemon(ArrayList<Pokemon> pokemonList, String savefile) {
try (PrintWriter file = new PrintWriter(savefile)) {
for (Pokemon pokemon : pokemonList) {
file.println(pokemon.saveString());
}
System.out.println("Successfully saved pokemon.");
} catch (FileNotFoundException e) {
System.out.println("The savefile could not be written.");
}
}
/**
* Saves all items in a list to a text file.
* @param itemList List of Item objects to save.
* @param savefile The file to write to.
*/
public static void saveItems(ArrayList<Item> itemList, String savefile) {
try (PrintWriter file = new PrintWriter(savefile)) {
for (Item item : itemList) {
file.println(item.saveString());
}
System.out.println("Successfully saved items.");
} catch (FileNotFoundException e) {
System.out.println("The savefile could not be written.");
}
}
/**
* Loads pokemon from a text file.
* @param savefile The file to write to.
* @return A list of pokemon or null on failiure.
*/
public static ArrayList<Pokemon> loadPokemon(String savefile) {
ArrayList<Pokemon> pokemon = new ArrayList<Pokemon>();
try (Scanner in = new Scanner(new File(savefile))) {
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
while (in.hasNextLine()) {
String[] data = in.nextLine().split(";");
try {
pokemon.add(new Pokemon(data[0], Integer.parseInt(data[1]), Integer.parseInt(data[2]), Integer.parseInt(data[3]), format.parse(data[4]).doubleValue(), Integer.parseInt(data[5]), Integer.parseInt(data[6]), Integer.parseInt(data[7])));
} catch (NumberFormatException e) {
System.out.println("Malformed number " + e);
} catch (ParseException e) {
System.out.println("Malformed number " + e);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Invalid savefile: " + savefile);
return null;
}
}
System.out.println("Successfully loaded pokemon.");
} catch (FileNotFoundException e) {
System.out.println("You don't have a valid savefile.");
}
return pokemon;
}
/**
* Loads items from a text file.
* @param savefile The file to write to.
* @return A list of items or null on failiure.
*/
public static ArrayList<Item> loadItems(String savefile) {
ArrayList<Item> items = new ArrayList<Item>();
try (Scanner in = new Scanner(new File(savefile))) {
while (in.hasNextLine()) {
try {
String[] data = in.nextLine().split(";");
items.add(new Item(data[0], data[1], Integer.parseInt(data[2]), Item.Target.valueOf(data[3]), Boolean.parseBoolean(data[4])));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Invalid savefile: " + savefile);
return null;
}
}
System.out.println("Successfully loaded items.");
} catch (FileNotFoundException e) {
System.out.println("You don't have a valid savefile.");
}
return items;
}
}

138
Item.java Normal file
View File

@ -0,0 +1,138 @@
import java.util.ArrayList;
public class Item {
public enum Target { SELF, OTHER }
private String name;
private String description;
private Target target;
private boolean alive;
private int amount;
public Item(String name, String description, int amount, Target target) {
this.name = name;
this.description = description;
this.target = target;
this.alive = true;
this.amount = amount;
}
public Item(String name, String description, int amount, Target target, boolean alive) {
this.name = name;
this.description = description;
this.target = target;
this.alive = alive;
this.amount = amount;
}
public String toString() {
return String.format("(%d) %s: %s", this.amount, this.name, this.description);
}
public String saveString() {
return String.format("%s;%s;%d;%s;%b", this.name, this.description, this.amount, this.target, this.alive);
}
public int getAmount() {
return this.amount;
}
public Target getTarget() {
return this.target;
}
public String getName() {
return this.name;
}
/** Checks if an item should be used on alive or fainted pokemon. */
public boolean needsAlive() {
return alive;
}
/**
* Spends an item and does something based on the type of item.
* @param target Which pokemon should the item be used on.
* @return True if nothing went wrong. False otherwise.
*/
public boolean use(Pokemon target) {
if (this.amount > 0) {
String name = this.name.toLowerCase().replace(" ", "");
switch (name) {
case "potion":
return potion(target, 20);
case "superpotion":
return potion(target, 50);
case "hyperpotion":
return potion(target, 200);
case "maxpotion":
return potion(target, -1);
case "revive":
if (!target.isConscious()) {
this.amount--;
target.revive();
System.out.printf("%s was revived.%n", target.getName());
return true;
} else {
System.out.println("You can't revive a conscious pokemon.");
return false;
}
default:
System.out.printf("Invalid item %s%n", name);
return false;
}
} else {
System.out.println("No cheating!");
return false;
}
}
/**
* Checks if a pokemon is able to, and in need of a potion. If it is, heal it.
* @param target The pokemon to heal.
* @param amount The amount to heal the pokemon.
* @return True if nothing went wrong. False otherwise.
*/
private boolean potion(Pokemon target, int amount) {
if (target.isConscious()) {
if (target.isDamaged()) {
this.amount--;
int healed = target.heal(amount);
System.out.printf("%s was healed for %d HP and now has %d HP.%n", target.getName(), healed, target.getHP());
} else {
System.out.printf("%s has not taken damage, and does not require a potion.%n", target.getName());
return false;
}
} else {
System.out.println("You can't heal a fainted pokemon.");
return false;
}
return true;
}
/**
* Uses a pokeball on an opponent.
* @param target Which pokemon to target.
* @param current Current list the pokemon belongs to.
* @param catcher Where we send the pokemon on a successfull capture.
* @return True if nothing went wrong. False otherwise.
*/
public boolean use(Pokemon target, ArrayList<Pokemon> current, ArrayList<Pokemon> catcher) {
if (this.amount > 0) {
this.amount--;
switch (this.name.toLowerCase().replace(" ", "")) {
case "pokeball":
return target.tryCapture(current, catcher, 255);
case "greatball":
return target.tryCapture(current, catcher, 200);
case "ultraball":
return target.tryCapture(current, catcher, 150);
case "masterball":
return target.tryCapture(current, catcher, 0);
default:
System.out.println("That item does not exist.");
}
} else {
System.out.println("No cheating!");
}
return false;
}
}

203
Pokemon.java Normal file
View File

@ -0,0 +1,203 @@
import java.util.Random;
import java.util.ArrayList;
public class Pokemon {
private String name;
private int healthPoints;
private int maxHealthPoints;
private int strength;
private double criticalChance;
private Random random;
private int catchRate;
private int exp;
private int level;
private int fleeCount;
public Pokemon(String name) {
this.random = new Random();
this.name = name;
this.healthPoints = 30 + random.nextInt(70);
this.maxHealthPoints = this.healthPoints;
this.criticalChance = Math.abs(0.1 * random.nextGaussian());
this.catchRate = (int)(Math.random() * 256);
this.exp = 0;
this.level = (int)(Math.abs(2 * random.nextGaussian()) + 1);
this.strength = random.nextInt(7) + this.level;
this.fleeCount = 0;
}
public Pokemon(String name, int healthPoints, int maxHealthPoints, int strength, double criticalChance, int catchRate, int exp, int level) {
this.random = new Random();
this.name = name;
this.healthPoints = healthPoints;
this.maxHealthPoints = maxHealthPoints;
this.criticalChance = criticalChance;
this.catchRate = catchRate;
this.exp = exp;
this.level = level;
this.strength = strength;
this.fleeCount = 0;
}
public String toString() {
return String.format("Level %d %s HP: (%d/%d) STR: %d CHC: %.0f%%", this.level, this.name, this.healthPoints, this.maxHealthPoints, this.strength, (this.criticalChance*100));
}
/**
* Returns a string containing all the pokemon's data.
*/
public String saveString() {
return String.format("%s;%d;%d;%d;%f;%d;%d;%d", this.name, this.healthPoints, this.maxHealthPoints, this.strength, this.criticalChance, this.catchRate, this.exp, this.level);
}
public String getName() {
return this.name;
}
public int getHP() {
return this.healthPoints;
}
public boolean equals(Pokemon target) {
return target == this;
}
/**
* Heals a pokemon.
* @param amount How many hitpoints to heal.
* @return The exact amount of hitpoints healed.
*/
public int heal(int amount) {
if (amount < 0) {
amount = this.maxHealthPoints - this.healthPoints;
} else {
amount = Math.min(this.maxHealthPoints - this.healthPoints, amount);
}
this.healthPoints += amount;
return amount;
}
/**
* Checks if a pokemon has not taken any damage or is fully healed.
* @param return True if health is full. False otherwise.
*/
public boolean isDamaged() {
return this.healthPoints < this.maxHealthPoints;
}
/**
* Tries to catch a pokemon.
* @param current The list where the pokemon currently belongs.
* @param catcher The list to send the pokemon on successfull capture.
* @return True on successfull capture. False otherwise.
*/
public boolean tryCapture(ArrayList<Pokemon> current, ArrayList<Pokemon> catcher, int range) {
if (range == 0) {
this.capture(current, catcher);
System.out.printf("%s was caught.%n", this.name);
return true;
}
if ((int)(Math.random() * (range + 1)) < Math.max((3 * this.maxHealthPoints - 2 * this.healthPoints) * this.catchRate / (3 * this.maxHealthPoints), 1)) {
this.capture(current, catcher);
System.out.printf("%s was caught.%n", this.name);
return true;
} else {
System.out.printf("%s escaped from the pokeball.%n", this.name);
return false;
}
}
/**
* Captures a wild pokemon.
* @param current The pokemon list the pokemon belongs to.
* @param catcher The pokemon list of the trainer.
*/
private void capture(ArrayList<Pokemon> current, ArrayList<Pokemon> catcher) {
catcher.add(this);
for (int i = 0; i < current.size(); i++) {
if (current.get(i) == this) {
current.remove(i);
}
}
}
/** Restores the health of a fainted pokemon. */
public void revive() {
this.healthPoints = this.maxHealthPoints;
}
/**
* Checks if the pokemon has any HP left.
* @return True if any HP is left. False otherwise.
*/
public boolean isConscious() {
return this.healthPoints > 0;
}
/**
* Damages a pokemon.
* @param How many hitpoints are to be deducted.
*/
public void damage(int damageTaken) {
this.healthPoints = Math.max(this.healthPoints -= damageTaken, 0);
System.out.printf("%s takes %d damage and is left with %d/%d HP%n", this.name, damageTaken, this.healthPoints, this.maxHealthPoints);
}
/**
* Gives a pokemon exp after each successfull battle. Also handles leveling up.
* @target Which pokemon did we beat.
*/
private void giveEXP(Pokemon target) {
int exp = (100 * target.level)/7;
this.exp += exp;
System.out.printf("%s gained %d exp.%n", this.name, exp);
if (this.exp > (4 * Math.pow(this.level, 3)) / 5) {
this.level++;
this.maxHealthPoints += 5;
this.healthPoints = maxHealthPoints;
this.strength += 1;
System.out.printf("%s is now level %d. Health has been increased and restored. Strength has been increased.%n", this.name, this.level);
}
}
/**
* Makes a pokemon attack another pokemon.
* @param target The pokemon to take damage.
*/
public void attack(Pokemon target) {
if (this.healthPoints > 0) {
System.out.printf("%s attacks %s.%n", this.getName(), target.getName());
double critical = 1;
if (Math.random() < this.criticalChance) {
System.out.println("Critical hit!");
critical = (2 * this.level +5) / (this.level + 5);
}
double randomDouble = 0.85 + (1.0 - 0.85) * random.nextDouble();
int moveDamage = (int)(Math.random() * 60 + 40);
int damageInflicted = this.level + (int)((((((2 * this.strength) / 5) + 2) * moveDamage * 1.75) / 50 + 2) * critical * randomDouble);
target.damage(damageInflicted);
if (!target.isConscious()) {
System.out.printf("%s is defeated by %s.%n", target.getName(), this.getName());
this.giveEXP(target);
this.fleeCount = 0;
}
} else {
System.out.println("No cheating!");
}
}
/**
* The trainer may flee if the battle is too hard.
* @param target Who are we trying to flee from
* @return True on successfull escape. False otherwise.
*/
public boolean flee(Pokemon target) {
if (random.nextInt(256) < (this.level * 128 / target.level) + (30 * this.fleeCount % 256)) {
this.fleeCount = 0;
return true;
} else {
this.fleeCount++;
return false;
}
}
}

719
Pokemon.txt Normal file
View File

@ -0,0 +1,719 @@
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Caterpie
Metapod
Butterfree
Weedle
Kakuna
Beedrill
Pidgey
Pidgeotto
Pidgeot
Rattata
Raticate
Spearow
Fearow
Ekans
Arbok
Pikachu
Raichu
Sandshrew
Sandslash
Nidoran♀
Nidorina
Nidoqueen
Nidoran♂
Nidorino
Nidoking
Clefairy
Clefable
Vulpix
Ninetales
Jigglypuff
Wigglytuff
Zubat
Golbat
Oddish
Gloom
Vileplume
Paras
Parasect
Venonat
Venomoth
Diglett
Dugtrio
Meowth
Persian
Psyduck
Golduck
Mankey
Primeape
Growlithe
Arcanine
Poliwag
Poliwhirl
Poliwrath
Abra
Kadabra
Alakazam
Machop
Machoke
Machamp
Bellsprout
Weepinbell
Victreebel
Tentacool
Tentacruel
Geodude
Graveler
Golem
Ponyta
Rapidash
Slowpoke
Slowbro
Magnemite
Magneton
Farfetch'd
Doduo
Dodrio
Seel
Dewgong
Grimer
Muk
Shellder
Cloyster
Gastly
Haunter
Gengar
Onix
Drowzee
Hypno
Krabby
Kingler
Voltorb
Electrode
Exeggcute
Exeggutor
Cubone
Marowak
Hitmonlee
Hitmonchan
Lickitung
Koffing
Weezing
Rhyhorn
Rhydon
Chansey
Tangela
Kangaskhan
Horsea
Seadra
Goldeen
Seaking
Staryu
Starmie
Mr. Mime
Scyther
Jynx
Electabuzz
Magmar
Pinsir
Tauros
Magikarp
Gyarados
Lapras
Ditto
Eevee
Vaporeon
Jolteon
Flareon
Porygon
Omanyte
Omastar
Kabuto
Kabutops
Aerodactyl
Snorlax
Articuno
Zapdos
Moltres
Dratini
Dragonair
Dragonite
Mewtwo
Mew
Chikorita
Bayleef
Meganium
Cyndaquil
Quilava
Typhlosion
Totodile
Croconaw
Feraligatr
Sentret
Furret
Hoothoot
Noctowl
Ledyba
Ledian
Spinarak
Ariados
Crobat
Chinchou
Lanturn
Pichu
Cleffa
Igglybuff
Togepi
Togetic
Natu
Xatu
Mareep
Flaaffy
Ampharos
Bellossom
Marill
Azumarill
Sudowoodo
Politoed
Hoppip
Skiploom
Jumpluff
Aipom
Sunkern
Sunflora
Yanma
Wooper
Quagsire
Espeon
Umbreon
Murkrow
Slowking
Misdreavus
Unown
Wobbuffet
Girafarig
Pineco
Forretress
Dunsparce
Gligar
Steelix
Snubbull
Granbull
Qwilfish
Scizor
Shuckle
Heracross
Sneasel
Teddiursa
Ursaring
Slugma
Magcargo
Swinub
Piloswine
Corsola
Remoraid
Octillery
Delibird
Mantine
Skarmory
Houndour
Houndoom
Kingdra
Phanpy
Donphan
Porygon2
Stantler
Smeargle
Tyrogue
Hitmontop
Smoochum
Elekid
Magby
Miltank
Blissey
Raikou
Entei
Suicune
Larvitar
Pupitar
Tyranitar
Lugia
Ho-Oh
Celebi
Treecko
Grovyle
Sceptile
Torchic
Combusken
Blaziken
Mudkip
Marshtomp
Swampert
Poochyena
Mightyena
Zigzagoon
Linoone
Wurmple
Silcoon
Beautifly
Cascoon
Dustox
Lotad
Lombre
Ludicolo
Seedot
Nuzleaf
Shiftry
Taillow
Swellow
Wingull
Pelipper
Ralts
Kirlia
Gardevoir
Surskit
Masquerain
Shroomish
Breloom
Slakoth
Vigoroth
Slaking
Nincada
Ninjask
Shedinja
Whismur
Loudred
Exploud
Makuhita
Hariyama
Azurill
Nosepass
Skitty
Delcatty
Sableye
Mawile
Aron
Lairon
Aggron
Meditite
Medicham
Electrike
Manectric
Plusle
Minun
Volbeat
Illumise
Roselia
Gulpin
Swalot
Carvanha
Sharpedo
Wailmer
Wailord
Numel
Camerupt
Torkoal
Spoink
Grumpig
Spinda
Trapinch
Vibrava
Flygon
Cacnea
Cacturne
Swablu
Altaria
Zangoose
Seviper
Lunatone
Solrock
Barboach
Whiscash
Corphish
Crawdaunt
Baltoy
Claydol
Lileep
Cradily
Anorith
Armaldo
Feebas
Milotic
Castform
Kecleon
Shuppet
Banette
Duskull
Dusclops
Tropius
Chimecho
Absol
Wynaut
Snorunt
Glalie
Spheal
Sealeo
Walrein
Clamperl
Huntail
Gorebyss
Relicanth
Luvdisc
Bagon
Shelgon
Salamence
Beldum
Metang
Metagross
Regirock
Regice
Registeel
Latias
Latios
Kyogre
Groudon
Rayquaza
Jirachi
Deoxys
Turtwig
Grotle
Torterra
Chimchar
Monferno
Infernape
Piplup
Prinplup
Empoleon
Starly
Staravia
Staraptor
Bidoof
Bibarel
Kricketot
Kricketune
Shinx
Luxio
Luxray
Budew
Roserade
Cranidos
Rampardos
Shieldon
Bastiodon
Burmy
Wormadam
Mothim
Combee
Vespiquen
Pachirisu
Buizel
Floatzel
Cherubi
Cherrim
Shellos
Gastrodon
Ambipom
Drifloon
Drifblim
Buneary
Lopunny
Mismagius
Honchkrow
Glameow
Purugly
Chingling
Stunky
Skuntank
Bronzor
Bronzong
Bonsly
Mime Jr.
Happiny
Chatot
Spiritomb
Gible
Gabite
Garchomp
Munchlax
Riolu
Lucario
Hippopotas
Hippowdon
Skorupi
Drapion
Croagunk
Toxicroak
Carnivine
Finneon
Lumineon
Mantyke
Snover
Abomasnow
Weavile
Magnezone
Lickilicky
Rhyperior
Tangrowth
Electivire
Magmortar
Togekiss
Yanmega
Leafeon
Glaceon
Gliscor
Mamoswine
Porygon-Z
Gallade
Probopass
Dusknoir
Froslass
Rotom
Uxie
Mesprit
Azelf
Dialga
Palkia
Heatran
Regigigas
Giratina
Cresselia
Phione
Manaphy
Darkrai
Shaymin
Arceus
Victini
Snivy
Servine
Serperior
Tepig
Pignite
Emboar
Oshawott
Dewott
Samurott
Patrat
Watchog
Lillipup
Herdier
Stoutland
Purrloin
Liepard
Pansage
Simisage
Pansear
Simisear
Panpour
Simipour
Munna
Musharna
Pidove
Tranquill
Unfezant
Blitzle
Zebstrika
Roggenrola
Boldore
Gigalith
Woobat
Swoobat
Drilbur
Excadrill
Audino
Timburr
Gurdurr
Conkeldurr
Tympole
Palpitoad
Seismitoad
Throh
Sawk
Sewaddle
Swadloon
Leavanny
Venipede
Whirlipede
Scolipede
Cottonee
Whimsicott
Petilil
Lilligant
Basculin
Sandile
Krokorok
Krookodile
Darumaka
Darmanitan
Maractus
Dwebble
Crustle
Scraggy
Scrafty
Sigilyph
Yamask
Cofagrigus
Tirtouga
Carracosta
Archen
Archeops
Trubbish
Garbodor
Zorua
Zoroark
Minccino
Cinccino
Gothita
Gothorita
Gothitelle
Solosis
Duosion
Reuniclus
Ducklett
Swanna
Vanillite
Vanillish
Vanilluxe
Deerling
Sawsbuck
Emolga
Karrablast
Escavalier
Foongus
Amoonguss
Frillish
Jellicent
Alomomola
Joltik
Galvantula
Ferroseed
Ferrothorn
Klink
Klang
Klinklang
Tynamo
Eelektrik
Eelektross
Elgyem
Beheeyem
Litwick
Lampent
Chandelure
Axew
Fraxure
Haxorus
Cubchoo
Beartic
Cryogonal
Shelmet
Accelgor
Stunfisk
Mienfoo
Mienshao
Druddigon
Golett
Golurk
Pawniard
Bisharp
Bouffalant
Rufflet
Braviary
Vullaby
Mandibuzz
Heatmor
Durant
Deino
Zweilous
Hydreigon
Larvesta
Volcarona
Cobalion
Terrakion
Virizion
Tornadus
Thundurus
Reshiram
Zekrom
Landorus
Kyurem
Keldeo
Meloetta
Genesect
Chespin
Quilladin
Chesnaught
Fennekin
Braixen
Delphox
Froakie
Frogadier
Greninja
Bunnelby
Diggersby
Fletchling
Fletchinder
Talonflame
Scatterbug
Spewpa
Vivillon
Litleo
Pyroar
Flabébé
Floette
Florges
Skiddo
Gogoat
Pancham
Pangoro
Furfrou
Espurr
Meowstic
Honedge
Doublade
Aegislash
Spritzee
Aromatisse
Swirlix
Slurpuff
Inkay
Malamar
Binacle
Barbaracle
Skrelp
Dragalge
Clauncher
Clawitzer
Helioptile
Heliolisk
Tyrunt
Tyrantrum
Amaura
Aurorus
Sylveon
Hawlucha
Dedenne
Carbink
Goomy
Sliggoo
Goodra
Klefki
Phantump
Trevenant
Pumpkaboo
Gourgeist
Bergmite
Avalugg
Noibat
Noivern
Xerneas
Yveltal
Zygarde
Diancie