Skip to content

Instantly share code, notes, and snippets.

@macroxela
Created April 24, 2014 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macroxela/11273113 to your computer and use it in GitHub Desktop.
Save macroxela/11273113 to your computer and use it in GitHub Desktop.
A simple turn based game with a Pokemon theme. The user selects which type to start off with and battles their way through. The player's Pokemon can level up, evolve and learn new moves.
import java.util.*;
public class Combatant {
double hp, attack, defense, speed;
String name, type, attribute;
Random ran = new Random();
Combatant()
{
name = "None";
type = "Generic";
hp = 35;
attack = 12;
defense = 10;
speed = 10;
}
double check_types(String h_type, String e_type)
{
if(h_type.equalsIgnoreCase(e_type))
{
System.out.println("Not very effective");
return 0.5;
}
if(h_type.equalsIgnoreCase("Water") && e_type.equalsIgnoreCase("Fire"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Fire") && e_type.equalsIgnoreCase("Water"))
{
System.out.println("Not very effective");
return 0.5;
}
else if(h_type.equalsIgnoreCase("Grass") && e_type.equalsIgnoreCase("Water"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Water") && e_type.equalsIgnoreCase("Grass"))
{
System.out.println("Not very effective");
return 0.5;
}
else if(h_type.equalsIgnoreCase("Fire") && e_type.equalsIgnoreCase("Grass"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Grass") && e_type.equalsIgnoreCase("Fire"))
{
System.out.println("Not very effective");
return 0.5;
}
else if(h_type.equalsIgnoreCase("Ice") && e_type.equalsIgnoreCase("Grass"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Electric") && e_type.equalsIgnoreCase("Water"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Electric") && e_type.equalsIgnoreCase("Grass"))
{
System.out.println("Not very effective");
return 0.5;
}
else if(h_type.equalsIgnoreCase("Dragon") || h_type.equalsIgnoreCase("Ghost") || h_type.equalsIgnoreCase("Psychic") || h_type.equalsIgnoreCase("Dark"))
{
return 1.3;
}
else if(h_type.equalsIgnoreCase("Fire") && e_type.equalsIgnoreCase("Ice"))
{
System.out.println("Super Effective");
return 2;
}
else if(h_type.equalsIgnoreCase("Ice") && e_type.equalsIgnoreCase("Water"))
{
System.out.println("Not very effective");
return 0.5;
}
else if(h_type.equalsIgnoreCase("Flying") && e_type.equalsIgnoreCase("Grass"))
{
System.out.println("Super Effective");
return 2;
}
else if(e_type.equalsIgnoreCase("Dragon"))
{
return 0.7;
}
return 1;
}
}
import static java.lang.System.out;
import java.awt.*;
import javax.swing.*;
public class Enemy extends Combatant{
int value, x, y, level;
ImageIcon pice;
Attacks att;
Enemy()
{
int ran_num = ran.nextInt(3) + 1;
int shiny_num = ran.nextInt(99) + 1;
if(ran_num == 1)
{
name = "Snivy";
type = "Grass";
hp = 30;
attack = 6;
defense = 4;
value = 20;
speed = 15;
attribute = "Enemy";
if(shiny_num == 75)
pice = new ImageIcon("img/Snivy_NB_variocolor.gif");
else
pice = new ImageIcon("img/th_snivy.gif");
att = new Attacks();
att.set_attacks("Tackle", "Normal", "Razor Leaf", "Grass", "Bite", "Normal", null, null);
}
else if(ran_num == 2)
{
name = "Tepig";
type = "Fire";
hp = 30;
attack = 7;
defense = 4;
value = 18;
speed = 7;
attribute = "Enemy";
if(shiny_num == 75)
pice = new ImageIcon("img/Tepig_NB_variocolor.gif");
else
pice = new ImageIcon("img/th_tepig.gif");
att = new Attacks();
att.set_attacks("Tackle", "Normal", "Ember", "Fire", "Bite", "Normal", null, null);
}
else if(ran_num == 3)
{
name = "Totodile";
type = "Water";
hp = 30;
attack = 9;
defense = 4;
value = 21;
speed = 11;
attribute = "Enemy";
if(shiny_num == 75)
pice = new ImageIcon("img/Totodile_NB_variocolor.gif");
else
pice = new ImageIcon("img/Totodile_NB.gif");
att = new Attacks();
att.set_attacks("Tackle", "Normal", "Water Gun", "Water", "Bite", "Normal", null, null);
}
x=200;
y=1;
}
Enemy(String s)
{
int shiny_num = ran.nextInt(99) + 1;
name = s;
if(s.equalsIgnoreCase("Reshiram"))
{
type = "Dragon";
hp = 40;
attack = 40;
defense = 30;
value = 50;
speed = 35;
attribute = "Boss";
pice = new ImageIcon("img/Reshiram_NB.gif");
att = new Attacks();
att.set_attacks("Dragon Pulse", "Dragon", "Fusion Flare", "Fire", "Solar Beam", "Grass", "Blue Flame", "Fire");
}
else if(s.equalsIgnoreCase("Zekrom"))
{
type = "Dragon";
hp = 40;
attack = 40;
defense = 30;
value = 50;
speed = 35;
attribute = "Boss";
pice = new ImageIcon("img/zani1.gif");
att = new Attacks();
att.set_attacks("Dragon Pulse", "Dragon", "Fusion Bolt", "Electric", "Lightning Strike", "Electric", "Flamethrower", "Fire");
}
else if(s.equalsIgnoreCase("Kyurem"))
{
type = "Dragon";
hp = 40;
attack = 40;
defense = 30;
value = 50;
speed = 35;
attribute = "Boss";
pice = new ImageIcon("img/Kyurem_NB.gif");
att = new Attacks();
att.set_attacks("Dragon Pulse", "Dragon", "Blizzard", "Ice", "Hydro Pump", "Water", "Crunch", "Normal");
}
else if(s.equalsIgnoreCase("Moltres"))
{
type = "Fire";
hp = 40;
attack = 25;
defense = 14;
value = 50;
speed = 23;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Moltres_NB_variocolor.gif");
else
pice = new ImageIcon("img/Moltres_NB.gif");
att = new Attacks();
att.set_attacks("Sky Attack", "Flying", "Fire Blast", "Fire", "Solar Beam", "Grass", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Articuno"))
{
type = "Water";
hp = 40;
attack = 25;
defense = 14;
value = 50;
speed = 22;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Articuno_NB_variocolor.gif");
else
pice = new ImageIcon("img/Articuno_NB.gif");
att = new Attacks();
att.set_attacks("Sky Attack", "Flying", "Ice Beam", "Ice", "Water Pulse", "Water", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Zapdos"))
{
type = "Electric";
hp = 40;
attack = 25;
defense = 14;
value = 50;
speed = 27;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Zapdos_NB_variocolor.gif");
else
pice = new ImageIcon("img/Zapdos_NB.gif");
att = new Attacks();
att.set_attacks("Sky Attack", "Flying", "Thunderbolt", "Electric", "Water Pulse", "Water", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Raikou"))
{
type = "Electric";
hp = 40;
attack = 27;
defense = 14;
value = 150;
speed = 25;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Raikou_NB_variocolor.gif");
else
pice = new ImageIcon("img/Raikou_NB.gif");
att = new Attacks();
att.set_attacks("Crunch", "Normal", "Thunderbolt", "Electric", "Volt Tackle", "Electric", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Suicune"))
{
type = "Water";
hp = 40;
attack = 27;
defense = 20;
value = 150;
speed = 25;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Suicune_NB_variocolor.gif");
else
pice = new ImageIcon("img/Suicune_NB.gif");
att = new Attacks();
att.set_attacks("Ice beam", "Ice", "Thunderbolt", "Electric", "Hydro Pump", "Water", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Entei"))
{
type = "Fire";
hp = 40;
attack = 27;
defense = 20;
value = 150;
speed = 25;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Entei_NB_variocolor.gif");
else
pice = new ImageIcon("img/Entei_NB.gif");
att = new Attacks();
att.set_attacks("Crunch", "Normal", "Fire Blast", "Fire", "Solar Beam", "Grass", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Darkrai"))
{
type = "Dark";
hp = 40;
attack = 30;
defense = 20;
value = 150;
speed = 40;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Darkrai_NB_variocolor.gif");
else
pice = new ImageIcon("img/Darkrai_NB.gif");
att = new Attacks();
att.set_attacks("Ice Beam", "Ice", "Fire Blast", "Fire", "Solar Beam", "Grass", "Dark Pulse", "Dark");
}
else if(s.equalsIgnoreCase("Mew"))
{
type = "Psychic";
hp = 40;
attack = 28;
defense = 20;
value = 250;
speed = 35;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Mew_NB_variocolor.gif");
else
pice = new ImageIcon("img/Mew_NB.gif");
att = new Attacks();
att.set_attacks("Ice Beam", "Ice", "Fire Blast", "Fire", "Solar Beam", "Grass", "Psychic", "Psychic");
}
else if(s.equalsIgnoreCase("Mewtwo"))
{
type = "Psychic";
hp = 50;
attack = 30;
defense = 27;
value = 250;
speed = 40;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Mewtwo_NB_variocolor.gif");
else
pice = new ImageIcon("img/Mewtwo_NB.gif");
att = new Attacks();
att.set_attacks("Thunderbolt", "Electric", "Fire Blast", "Fire", "Solar Beam", "Grass", "Psychic", "Psychic");
}
else if(s.equalsIgnoreCase("Dialga"))
{
type = "Dragon";
hp = 60;
attack = 30;
defense = 30;
value = 300;
speed = 27;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Dialga_NB_variocolor.gif");
else
pice = new ImageIcon("img/Dialga_NB.gif");
att = new Attacks();
att.set_attacks("Roar of Time", "Dragon", "Fire Blast", "Fire", "Thunderbolt", "Electric", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Palkia"))
{
type = "Dragon";
hp = 60;
attack = 30;
defense = 25;
value = 300;
speed = 27;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Palkia_NB_variocolor.gif");
else
pice = new ImageIcon("img/Palkia_NB.gif");
att = new Attacks();
att.set_attacks("Spacial Rend", "Dragon", "Water Pulse", "Water", "Thunderbolt", "Electric", "Take Down", "Normal");
}
else if(s.equalsIgnoreCase("Giratina"))
{
type = "Dragon";
hp = 65;
attack = 40;
defense = 40;
value = 300;
speed = 35;
attribute = "Boss";
if(shiny_num == 75)
pice = new ImageIcon("img/Giratina_NB_variocolor.gif");
else
pice = new ImageIcon("img/Giratina_NB.gif");
att = new Attacks();
att.set_attacks("Dragon Pulse", "Dragon", "Shadow Force", "Ghost", "Thunderbolt", "Electric", "Flamethrower", "Fire");
}
x=200;
y=1;
}
void print_stats()
{
System.out.println("Name: " + name + "\nAttack: " + attack);
System.out.println("Defense: " + defense + "\nSpeed: " + speed);
System.out.println("HP: " + hp + "\n");
}
void attack(Hero he)
{
int ran_att = 0;
if(att.a4 != null)
{
ran_att = ran.nextInt(4) + 1;
}
else
{
ran_att = ran.nextInt(3) + 1;
}
String a_type = "blank";
if(ran_att == 1)
{
out.println(name + " used " + att.a1);
a_type = att.a1_type;
}
else if(ran_att == 2)
{
out.println(name + " used " + att.a2);
a_type = att.a2_type;
}
else if(ran_att == 3)
{
out.println(name + " used " + att.a3);
a_type = att.a3_type;
}
else if(ran_att == 4)
{
out.println(name + " used " + att.a4);
a_type = att.a4_type;
}
double stab = 1;
double damage;
double weakness_resistance;
double critical_hit;
int ran_num;
ran_num = ran.nextInt(10) + 1;
if(name.equalsIgnoreCase("Giratina") && hp <= 32)
{
attack += 2;
defense += 2;
}
if(ran_num == 7)
{
critical_hit = 2;
System.out.println("Critical Hit");
}
else
critical_hit = 1;
if(a_type.equalsIgnoreCase(type))
stab = 1.75;
weakness_resistance = super.check_types(a_type, he.type);
//Damage = ((((2 * Level / 5 + 2) * AttackStat * AttackPower / DefenseStat) / 50) + 2) * STAB
//* Weakness/Resistance * RandomNumber / 100
damage = ((attack)/he.defense)*stab*weakness_resistance*critical_hit;
System.out.println("Damage: " + damage);
he.hp -= damage;
if(he.hp <= 0)
he.hp = 0;
/*he.hp -= attack/he.defense;
if(he.hp <= 0)
he.hp = 0;*/
}
boolean check_alive(Hero a)
{
if(a.hp > 0)
return true;
return false;
}
public void draw(Graphics g, Component c)
{
g.drawImage(pice.getImage(), x, y, c);
}
}
import java.util.*;
import static java.lang.System.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class Game {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
Random tst = new Random();
int h, power_up;
int num_defeated = 0;
int boss_battle = 5;
String att_name;
Random rand = new Random();
out.println("What is your name?");
String name = scan.next();
out.println("Hello " + name + " you are about to embark on an epic journey.");
String t;
out.println("What type do you want to be?\nWater\nFire\nGrass\nElectric");
t = scan.next();
Hero user1 = new Hero(name, t);
out.println("\nYour stats are: ");
user1.print_stats();
Enemy a = new Enemy();
out.println("\nYou are against: "+ a.name + "\nHP: " + a.hp);
//Step 1 create frame
JFrame frame = new JFrame("Battlefield");
//Step 2 Create a panel
GamePanel panel = new GamePanel(user1, a);
//Step 3 Put the panel in the frame
frame.getContentPane().add(panel);
//step 4 Set size of frame, make it visible
frame.setSize(400,600);
frame.setVisible(true);
panel.removeAll();
panel.updateUI();
out.println("\nAttack? ");
String ans = scan.next();
String natt;
power_up = 5;
while(ans.equalsIgnoreCase("Yes") && a.hp > 0 && user1.hp > 0)
{
out.println("\nWhich attack?");
if(user1.att.a1 != null)
out.println("(1)" + user1.att.a1);
if(user1.att.a2 != null)
out.println("(2)" + user1.att.a2);
if(user1.att.a3 != null)
out.println("(3)" + user1.att.a3);
if(user1.att.a4 != null)
out.println("(4)" + user1.att.a4);
int o = scan.nextInt();
////////////////////////////////////////////////////////////////////////////////////
//Determine attacking order
if(a.speed > user1.speed)
{
a.attack(user1);
out.println(user1.name + " took damage, \nHP: " + user1.hp + "\n");
if(a.check_alive(user1))
{
user1.attack(a, o);
out.println("Enemy "+ a.name + " took damage, \nHP: " + a.hp);
}
}
//////////////////////////////////////////////////////////////////////////////////
else if(a.speed < user1.speed)
{
user1.attack(a, o);
out.println("Enemy "+ a.name + " took damage, \nHP: " + a.hp + "\n");
if(user1.check_alive(a))
{
a.attack(user1);
out.println(user1.name + " took damage, \nHP: " + user1.hp + "\n");
}
}
///////////////////////////////////////////////////////////////////////////////////
else
{
h = tst.nextInt(2);
if( h == 1)
{
user1.attack(a, o);
out.println("Enemy "+ a.name + " took damage, \nHP: " + a.hp + "\n");
if(user1.check_alive(a))
{
a.attack(user1);
out.println(user1.name + " took damage, \nHP: " + user1.hp + "\n");
}
}
else
{
a.attack(user1);
out.println(user1.name + " took damage, \nHP: " + user1.hp + "\n");
if(a.check_alive(user1))
{
user1.attack(a, o);
out.println("Enemy "+ a.name + " took damage, \nHP: " + a.hp + "\n");
}
}
}
//////////////////////////////////////////////////////////////////////////////////////
// Check to see if user lost
if(user1.hp <= 0)
{
out.println("You lost the game . . .");
panel.update_info(user1, a);
break;
}
//check to see if enemy lost
if(a.hp <= 0)
{
out.println("You defeated " + a.name);
user1.level_up(a);
out.println("You gained " + (user1.exp - user1.old_exp) + " experience points.");
panel.update_info(user1, a);
num_defeated++;
if(num_defeated > 17)
{
out.println("You beat the game!!!");
break;
}
// Increase user's level
if(user1.old_level < user1.level)
{
out.println("You leveled up!! \nLevel: " + user1.level);
out.println("Attack:" + user1.attack + "\nDefense:" + user1.defense + "\nSpeed:" + user1.speed + "\nHP:" + user1.max_hp);
if(user1.level >= user1.lvl_evolve1 || user1.level >= user1.lvl_evolve2)
{
out.println(user1.name + " evolved!!");
user1.attack += 5;
user1.defense += 5;
user1.speed += 5;
user1.hp += 5;
if(user1.type.equalsIgnoreCase("Grass"))
{
user1.att.a4 = "Solar Burst";
user1.att.a4_type = "Fire";
out.println(user1.name + " learned " + user1.att.a4);
}
if(user1.type.equalsIgnoreCase("Fire"))
{
user1.att.a4 = "Solar Beam";
user1.att.a4_type = "Grass";
out.println(user1.name + " learned " + user1.att.a4);
}
if(user1.type.equalsIgnoreCase("Water"))
{
user1.att.a4 = "Ice Beam";
user1.att.a4_type = "Ice";
out.println(user1.name + " learned " + user1.att.a4);
}
if(user1.type.equalsIgnoreCase("Electric"))
{
user1.att.a4 = "Energy Ball";
user1.att.a4_type = "Grass";
out.println(user1.name + " learned " + user1.att.a4);
}
}
}
out.println("Fight another enemy?");
String ans2 = scan.next();
if(!ans2.equalsIgnoreCase("Yes"))
{
out.println("Decided to stop");
break;
}
/////////////////////////////////////////////////////////////////////////////////
if(ans2.equalsIgnoreCase("Yes"))
{
//Bosses
if(num_defeated == boss_battle)
{
int ran_num = rand.nextInt(3) + 1;
power_up += 1;
user1.hp = user1.max_hp;
if(num_defeated == 5)
{
boss_battle = 7;
if(ran_num == 1)
a = new Enemy("Moltres");
else if(ran_num == 2)
a = new Enemy("Zapdos");
else if(ran_num == 3)
a = new Enemy("Articuno");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 7)
{
boss_battle = 10;
if(ran_num == 1)
a = new Enemy("Raikou");
else if(ran_num == 2)
a = new Enemy("Entei");
else if(ran_num == 3)
a = new Enemy("Suicune");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 10)
{
boss_battle = 12;
a = new Enemy("Darkrai");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 12)
{
boss_battle = 14;
a = new Enemy("Mew");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 14)
{
boss_battle = 15;
a = new Enemy("Mewtwo");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 15)
{
boss_battle = 16;
if(ran_num == 1)
a = new Enemy("Reshiram");
else if(ran_num == 2)
a = new Enemy("Zekrom");
else if(ran_num == 3)
a = new Enemy("Kyurem");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 16)
{
int u = tst.nextInt(2) + 1;
boss_battle = 17;
if(u ==1)
a = new Enemy("Palkia");
else
a = new Enemy("Dialga");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
if(num_defeated == 17)
{
a = new Enemy("Giratina");
a.attack += power_up;
a.defense += power_up;
a.speed += power_up;
a.hp += power_up;
a.print_stats();
}
}
else
{
a = new Enemy();
a.attack += power_up;
a.defense += power_up;
a.hp += power_up;
a.speed += power_up;
a.value += power_up;
a.print_stats();
user1.hp = user1.max_hp;
}
panel.update_info(user1, a);
}
else
break;
}
else if(user1.hp > 0)
{
panel.update_info(user1, a);
out.println("Attack? ");
ans = scan.next();
if(!ans.equalsIgnoreCase("Yes"))
{
out.println("You ran away . . .");
break;
}
}
}
}
}
import javax.swing.*;
import java.awt.*;
public class GamePanel extends JPanel{
ImageIcon picture;
Enemy ene;
Hero he;
int counter;
GamePanel()
{
ene = new Enemy();
he = new Hero();
}
GamePanel(Hero us, Enemy n)
{
ene = n;
he = us;
counter = 0;
}
void update_info(Hero us, Enemy n)
{
ene = n;
he = us;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
ene.draw(g, this);
he.draw(g, this);
if(ene.hp <= 0)
{
g.setColor(Color.red);
g.drawLine(ene.x,ene.y, 320, 130);
g.drawLine(ene.x + 120,ene.y, ene.x, 130);
g.setFont( new Font( "stupid font", Font.BOLD, 30 ) );
g.drawString("You beat " + ene.name + "!!!", 30, 300);
}
if(he.hp <= 0)
{
g.setFont( new Font( "stupid font", Font.BOLD, 50 ) );
g.drawString("GAME OVER!!!!", 30, 300);
}
if(he.level >= he.lvl_evolve1)
{
if(he.type.equalsIgnoreCase("Grass"))
he.pich = new ImageIcon("img/Ivysaur_espalda_G5.gif");
else if(he.type.equalsIgnoreCase("Fire"))
he.pich = new ImageIcon("img/Charmeleon_espalda_G5.gif");
else if(he.type.equalsIgnoreCase("Water"))
he.pich = new ImageIcon("img/Wartortle_espalda_G5.gif");
he.draw(g, this);
}
if(he.level >= he.lvl_evolve2)
{
if(he.type.equalsIgnoreCase("Grass"))
he.pich = new ImageIcon("img/Venusaur_espalda_G5_hembra.gif");
else if(he.type.equalsIgnoreCase("Fire"))
he.pich = new ImageIcon("img/Charizard_espalda_G5.gif");
else if(he.type.equalsIgnoreCase("Water"))
he.pich = new ImageIcon("img/Blastoise_espalda_G5.gif");
he.draw(g, this);
}
if(ene.name.equalsIgnoreCase("Giratina") && ene.hp <= 32)
{
ene.pice = new ImageIcon("img/Giratina_forma_origen_NB.gif");
ene.draw(g, this);
}
}
}
import static java.lang.System.out;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.ImageIcon;
public class Hero extends Combatant{
int exp, nxt_level, level, g, old_exp, old_level, max_hp, lvl_evolve1, lvl_evolve2;
int value, x, y;
ImageIcon pich;
Attacks att;
Hero()
{
nxt_level = 10;
level = 1;
exp = 0;
hp = 30;
attack = 10;
defense = 10;
speed = 10;
attribute = "Hero";
x = 10;
y = 400;
int r = ran.nextInt(3);
g = 2;
if(r == 0)
{
type = "Fire";
pich = new ImageIcon("img/Charmander_espalda_G5.gif");
att.set_attacks("Tackle","Normal","Ember","Fire","Bite", "Normal", null, null);
}
else if(r == 1)
{
type = "Water";
pich = new ImageIcon("img/Squirtle_espalda_G5.gif");
att.set_attacks("Tackle","Normal","Water Gun","Water","Bite", "Normal", null, null);
}
else if(r == 2)
{
type = "Grass";
pich = new ImageIcon("img/Bulbasaur_espalda_G5.gif");
att.set_attacks("Tackle","Normal","Vine Whip","Grass","Bite", "Normal", null, null);
}
}
Hero(String s, String t)
{
name = s;
nxt_level = 10;
level = 1;
exp = 0;
speed = 10;
hp = 25;
g = 2;
x = 10;
y = 400;
max_hp = 25;
lvl_evolve1 = 5;
lvl_evolve2 = 10;
//attack = 200; //* Use to go through entire game quickly, check to see if bosses appear
int ran_num = ran.nextInt(99) + 1;
if(t.equalsIgnoreCase("Fire"))
{
type = "Fire";
if(ran_num == 75)
pich = new ImageIcon("img/Charmander_espalda_G5_variocolor.gif");
else
pich = new ImageIcon("img/Charmander_espalda_G5.gif");
att = new Attacks();
att.set_attacks("Tackle","Normal","Ember","Fire","Bite", "Normal", null, null);
}
else if(t.equalsIgnoreCase("Water"))
{
type = "Water";
if(ran_num == 75)
pich = new ImageIcon("img/Squirtle_espalda_G5_variocolor.gif");
else
pich = new ImageIcon("img/Squirtle_espalda_G5.gif");
att = new Attacks();
att.set_attacks("Tackle","Normal","Water Gun","Water","Bite", "Normal", null, null);
}
else if(t.equalsIgnoreCase("Grass"))
{
type = "Grass";
if(ran_num == 75)
pich = new ImageIcon("img/Bulbasaur_espalda_G5_variocolor.gif");
else
pich = new ImageIcon("img/Bulbasaur_espalda_G5.gif");
att = new Attacks();
att.set_attacks("Tackle","Normal","Vine Whip","Grass","Bite", "Normal", null, null);
}
else if(t.equalsIgnoreCase("Electric"))
{
type = "Electric";
if(ran_num == 75)
pich = new ImageIcon("img/Pikachu_espalda_G5_variocolor.gif");
else
pich = new ImageIcon("img/Pikachu_espalda_G5.gif");
att = new Attacks();
att.set_attacks("Tackle","Normal","Thundershock","Electric","Scratch", "Normal", null, null);
}
}
void print_stats()
{
System.out.println("Level: " + level + "\nAttack: " + attack);
System.out.println("Defense: " + defense + "\nSpeed: " + speed);
System.out.println("HP: " + max_hp);
}
void level_up(Enemy en)
{
old_exp = exp;
exp += level*en.value;
old_level = level;
while(exp >= nxt_level)
{
level++;
nxt_level = g*nxt_level;
attack++;
defense++;
g++;
speed++;
max_hp++;
hp = max_hp;
}
//print_stats();
}
void attack(Enemy en)
{
en.hp -= attack/en.defense;
if(en.hp <= 0)
en.hp = 0;
}
void attack(Enemy en, int n)
{
String a_type = "blank";
double stab = 1;
double damage;
double weakness_resistance;
double critical_hit;
int ran_num;
ran_num = ran.nextInt(10) + 1;
if(ran_num == 7)
{
critical_hit = 2;
System.out.println("Critical Hit");
}
else
critical_hit = 1;
if(n == 1)
{
a_type = att.a1_type;
System.out.println(name + " used " + att.a1);
}
else if(n == 2)
{
a_type = att.a2_type;
System.out.println(name + " used " + att.a2);
}
else if(n == 3)
{
a_type = att.a3_type;
System.out.println(name + " used " + att.a3);
}
else if(n == 4)
{
a_type = att.a4_type;
System.out.println(name + " used " + att.a4);
}
if(a_type.equalsIgnoreCase(type))
stab = 1.75;
weakness_resistance = super.check_types(a_type, en.type);
//Damage = ((((2 * Level / 5 + 2) * AttackStat * AttackPower / DefenseStat) / 50) + 2) * STAB
//* Weakness/Resistance * RandomNumber / 100
damage = ((attack*level)/en.defense)*stab*weakness_resistance*critical_hit;
System.out.println("Damage: " + damage);
en.hp -= damage;
if(en.hp <= 0)
en.hp = 0;
}
boolean check_alive(Enemy ene)
{
if(ene.hp > 0)
return true;
return false;
}
public void draw(Graphics g, Component c)
{
g.drawImage(pich.getImage(), x, y, c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment