- import java.util.Random;
- import java.util.Scanner;
- public class BasicPokemon {
- String name;
- int hitpoints;
- // Constructor to make a BasicPokemon object with a name and hitpoints
- public BasicPokemon(String name1, int hitpoints1) {
- name = name1;
- hitpoints = hitpoints1;
- }
- // Get the name of the Pokemon
- public String getName() {
- return name;
- }
- // Set the name of the Pokemon
- public void setName(String name1) {
- name = name1;
- }
- // Gets the current hitpoints of the Pokemon
- public int getHitpoints() {
- return hitpoints;
- }
- // Set the hitpoints of the Pokemon
- public void setHitpoints(int hitpoints1) {
- hitpoints = hitpoints1;
- }
- // Reduce the hitpoints of the Pokemon by a specified amount
- public void takeDamage(int amount) {
- hitpoints -= amount;
- }
- // Attack
- public void attack(BasicPokemon enemy) {
- Random random = new Random();
- int damage = random.nextInt(6);
- if (damage == 0) {
- System.out.println(name + " Attacks and misses!");
- System.out.println("════════════════════════════════════"); //Print damage message and separator
- } else {
- System.out.println(name + " Attacks and deals " + damage + " damage!");
- System.out.println("════════════════════════════════════"); //Print damage message and separator
- }
- enemy.takeDamage(damage);
- }
- // Check if the Pokemon is still alive
- public boolean isAlive() {
- if (hitpoints > 0) {
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- BasicPokemon ally = new BasicPokemon("Pikachu", 40);// Ally Pokemon is named Pikachu with 40 hitpoints
- BasicPokemon enemy = new BasicPokemon("Charmander", 40);// Enemy Pokemon is named Charmander with 40 hitpoints
- //Start game loop
- while (ally.isAlive() && enemy.isAlive()) { //Game continues as long as both Pokemon are alive
- if (ally.isAlive()) { // Ally attacks enemy
- ally.attack(enemy);
- }
- if (enemy.isAlive()) { // Enemy attacks ally
- enemy.attack(ally);
- }
- }
- //Handle game ending here
- if (ally.isAlive()) { // Print ally victory message
- System.out.println(ally.getName() + " Won against "
- + enemy.getName() + " With "
- + ally.getHitpoints() + " Hitpoints remaining!");
- } else if (enemy.isAlive()) { // Print enemy victory message
- System.out.println(enemy.getName() + " Won against "
- + ally.getName() + " With "
- + enemy.getHitpoints() + " Hitpoints remaining!");
- } else {
- System.out.println("Error"); // Error if both pokemons healths are at 0
- }
- }
- }
[text] Pokemon game
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: