ODD TUNINGS

Battle Code

There was a time when learning JAVA, that I wanted to make an offensive pokemon clone. I wish I hadn’t made it offensive, so then I would share the whole thing, but I’ve combed through and taken the battling part of the code to share here.

Battle.java
package wtfrpg;

import java.util.Scanner;
import static wtfrpg.WtfRpg.entCon;
import static wtfrpg.WtfRpg.nextwait;
import static wtfrpg.WtfRpg.t;

/**
*
* @author William
*/
public class Battle {

public static void Battle(Player playerBatt, Enemy foe){

Scanner uI = new Scanner(System.in);
System.out.println (“Press Enter to continue.”);
try {System.in.read();}
catch (Exception e) {}
System.out.println (“”);
System.out.println(playerBatt.charName+ ” : ” + playerBatt.charHP + “HP ” + foe.type + ” : “+ foe.hP +”HP”);
t(“”);
double rdmCNum = Math.random();
boolean playerFirst = (rdmCNum > .50 );
int turn = 0;
if (playerFirst == true){
turn = 1;
}
do{

/*————————-Players Turn——————————*/
if (turn == 1){
String attChoice;
do{
System.out.println(“It is your turn. Choose Attack…”);
System.out.println(“|Type(Hit Chance)*Damage|”);
System.out.println(“|Heavy(“+50*playerBatt.accMult+”%)*”+playerBatt.charDamage*2+”|—-|Medium(“+70*playerBatt.accMult+”%)*”+playerBatt.charDamage+”|—-|Light(“+90*playerBatt.accMult+”%)*5|—-|Special(100%)*20|”);
attChoice = uI.next();
if (“heavy”.equalsIgnoreCase(attChoice)){
double attchance = Math.random();
if (attchance>.50/playerBatt.accMult){
System.out.println(“Hit. Opponent -” +playerBatt.charDamage*2 +”HP”);
foe.hP = foe.hP-(playerBatt.charDamage*2);
turn = 2;
}
if (attchance<.50/playerBatt.accMult){
System.out.println(foe.type+ ” dodged the attack”);
turn = 2;
}
}
if (“medium”.equalsIgnoreCase(attChoice)){
double attchance = Math.random();
if (attchance >.30/playerBatt.accMult) {
System.out.println (“Hit. Opponent -” +playerBatt.charDamage+”HP”);
foe.hP = foe.hP – (playerBatt.charDamage);
turn = 2;
}
if (attchance < .30/playerBatt.accMult){
System.out.println(foe.type+ ” dodged the attack”);
turn = 2;
}
}
if (“light”.equalsIgnoreCase(attChoice)){
double attchance = Math.random();
if (attchance>.10/playerBatt.accMult) {
System.out.print(“Hit. Opponent -5″+”HP”);
foe.hP = foe.hP-5;
turn = 2;
}
if (attchance < .10/playerBatt.accMult){
System.out.println(foe.type+ ” dodged the attack”);
turn = 2;
}
}
if (“special”.equalsIgnoreCase(attChoice)){
if (playerBatt.hasshotgun = true && playerBatt.shells>0){
System.out.println (playerBatt.charName + ” blasted ” +foe.type+ ” with a shotgun”);
System.out.println(foe.type+ ” -20″);
foe.hP = foe.hP-20;
playerBatt.shells = playerBatt.shells-1;
turn = 2;
}
else {
t(“You have no Special Weapon”);
turn = 1;
}
}
if (“kill”.equalsIgnoreCase(attChoice)){
foe.hP = 0;
}
} while (turn== 1);
turn = 2;
nextwait(2000,2);
}
else{
turn = 2;
}

/*————————–Enemies Turn————————*/
if (turn == 2 && foe.hP>0 && playerBatt.charHP>0) {
double enrdm = Math.random();
System.out.println(“It is the enemy’s turn.”);
System.out.println (“Press Enter to continue.”);
try {System.in.read();}
catch (Exception e) {}
nextwait(3000,0);
if (enrdm < .33) {
System.out.println (foe.type+ ” uses ” + foe.lAttack);
double hitchance = Math.random();
if (hitchance>.20){
System.out.println(“You are hit. -“+ foe.lAttackP+”HP”);
playerBatt.charHP = playerBatt.charHP-foe.lAttackP;
turn = 1;
}
if (hitchance<.20){
System.out.println(foe.type+” missed.”);
turn = 1;
}
}
if (enrdm>.33 && enrdm<.66){
System.out.println(foe.type+ ” uses ” + foe.mAttack);
double attchance = Math.random();
if (attchance> .40){
System.out.println(“You are hit. -” + foe.mAttackP+”HP”);
playerBatt.charHP = playerBatt.charHP – foe.mAttackP;
turn = 1;
}
if (attchance<.40){
System.out.println(foe.type+ ” missed”);
turn = 1;
}
turn = 1;

}

if (enrdm>.66) {
System.out.println(foe.type+” uses “+ foe.hAttack);
double attchance = Math.random();
if (attchance<.40){
System.out.println(“You are hit. “+ playerBatt.charName +” -“+ foe.hAttackP+”HP”);
playerBatt.charHP = playerBatt.charHP – foe.hAttackP;
}
if (attchance>.40) {
System.out.println (foe.type+” missed”);
}

}
turn =1;
nextwait(2000,1);
}
System.out.println(“Player HP:” +playerBatt.charHP);
System.out.println(“Opponent HP:” +foe.hP);
System.out.println (“”);
} while (foe.hP>0 && playerBatt.charHP>0);
/*————————Battle Over——————-*/
if (playerBatt.charHP< foe.hP){
System.out.println(“You have been defeated by a ” + foe.type);
System.out.println (“Game Over”);
System.out.println (“Don’t bother coming back”);
}
if (foe.hP< playerBatt.charHP){
System.out.println(“Good Work! “+ playerBatt.charName+ ” just killed ” + foe.type + ” with a “+ playerBatt.charPrimaryWeapon.weaponName);
System.out.println (“Gained ” +(foe.XPgain+5) +”XP.”);
playerBatt.charXP = playerBatt.charXP+foe.XPgain+5;
playerBatt.killCount = playerBatt.killCount + 1;
System.out.println(“Kill Count +1”);

/*————————-Loot——————–*/
String randomLoot = null;
int lootvalue = 0;
nextwait(500,5);
double randomLootnum = Math.random();
if(randomLootnum < .30){
randomLoot = foe.lValue;
lootvalue = 20;
}
if(randomLootnum >.33 && randomLootnum<.66){
randomLoot = foe.mValue;
lootvalue = 35;
}
if(randomLootnum >.66){
randomLoot = foe.hValue;
lootvalue = 50;
}
t(“Corpse looted. “+ foe.type+” dropped: -“+randomLoot+” + $”+ lootvalue);
playerBatt.charMoney = playerBatt.charMoney + lootvalue;

entCon(playerBatt);
}
}

}