Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OUTDATED! NEW VERSION HERE: http://pastebin.com/F7tfZQqq
- package Main;
- import java.util.Scanner;
- public class Battlesim
- {
- public static int Randint;
- static String P1name;
- static String P2name;
- static float P1Health;
- static float P2Health;
- static float P1Attack;
- static float P2Attack;
- static float P1Defense;
- static float P2Defense;
- static String P1Armor;
- static String P2Armor;
- static float P1Speed;
- static float P2Speed;
- static float Damage;
- static String InputString;
- //Status weapons
- static boolean P1Burner = false;
- static boolean P2Burner = false;
- static boolean P1Jarater = false;
- static boolean P2Jarater = false;
- static boolean P1Poisoner = false;
- static boolean P2Poisoner = false;
- //Status effects
- static boolean P1Burning = false;
- static boolean P2Burning = false;
- static boolean P1Poisoned = false;
- static boolean P2Poisoned = false;
- static boolean P1Stunned = false;
- static boolean P2Stunned = false;
- static boolean P1Bleeding = false;
- static boolean P2Bleeding = false;
- static boolean P1Jarated = false;
- static boolean P2Jarated = false;
- static boolean P1Confused = false;
- static boolean P2Confused = false;
- static boolean P1Rage = false;
- static boolean P2Rage = false;
- /*
- * TODO
- * Add moar status effects (introduced below, already declared)
- * Add moar weapons
- * Ranged? Magic?
- * Incorporate a story mode
- */
- /*
- * STATUS EFFECTS
- * For status effects, add an end possibility to the bottom of a turn.
- * INHERENT: Confused = 30% chance damage self. 1/30 hit (staff = 1/15) 3/5 recover.
- * INHERENT: Bleeding = rand(15,28) damage done. 1/15 hit 4/5 recover.
- * INHERENT: Stunned = 1/2 chance of not being able to attack. 1/15 hit, 1/3 recover
- * INHERENT (1/15 hit chance with battleaxe, 1/50 otherwise): Rage = 57/60 chance of miss, 2/60 chance of a Smash (*27 damage.) 1/60 chance of a final smash (*81 damage) 1/50 (or 1/15) hit, 1/2 recover.
- DONE=
- * Burning = rand(20,60)/(rand(3,6)*defense) Damage done. 1/6 hit 1/10 recover
- * INHERENT: Jarated = all are crits and minicrits. 1/35 hit, 2/5 recover.
- * Poisoned = rand(30,50) damage done. 1/7 hit, 1/4 recover.
- */
- //scanner declaration
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args)
- {
- //Calls inputs method
- Inputs();
- // Main loop. True until battle is completed
- Combat();
- }
- public static void Combat()
- {
- while (P1Health > 0 && P2Health >0)
- {
- //speed test to determine who goes first
- RandInt(0, P1Speed + P2Speed);
- if (Randint < P1Speed)
- {
- //P1's turn
- P1Turn();
- }
- else if (Randint > P1Speed)
- {
- //P2's turn
- P2Turn();
- }
- else
- {
- //If both speeds are 1, I think this will happen. This is to essentially "break the tie"
- RandInt(0, 1);
- if (Randint == 0)
- P1Speed = P1Speed++;
- if (Randint == 1)
- P2Speed = P2Speed++;
- }
- }
- //States winner based on results of battle
- CombatResolver();
- }
- public static void P1Turn()
- {
- RandInt(60, 180);
- Damage = (P1Attack * Randint);
- if (P2Jarated == true)
- {
- RandInt(1,4);
- if (Randint == 4)
- {
- Damage = Damage * 9;
- System.out.print("Critical hit! : ");
- }
- if (Randint != 4)
- {
- Damage = Damage * 3;
- System.out.print("Minicrit! : ");
- }
- }
- if (P2Jarated == false)
- {
- RandInt(1, 60);
- if (Randint == 60)
- {
- Damage = 3 * Damage;
- System.out.print("Critical hit! : ");
- }
- if (Randint >= 57)
- {
- Damage = 3 * Damage;
- if (Randint != 60)
- System.out.print("Minicrit! : ");
- }
- if (Randint <= 7)
- {
- Damage = 0 * Damage;
- System.out.print("Missed! : ");
- }
- }
- RandInt(92, 97);
- Damage = (float) Damage / ((Randint/10) * P2Defense);
- System.out.print(P1name);
- System.out.print(" does ");
- System.out.print((int) (Damage));
- System.out.print(" damage; ");
- P2Health = P2Health - Damage;
- System.out.print(P2name);
- System.out.print(" has ");
- if (P2Health > 0)
- System.out.print((int) P2Health);
- if (P2Health <= 0)
- System.out.print("0");
- System.out.println(" health remaining.");
- P1PostCombatEffects();
- System.out.println("");
- }
- public static void P2Turn()
- {
- RandInt(60, 180);
- Damage = (P2Attack * Randint);
- if (P1Jarated == true)
- {
- RandInt(1,4);
- if (Randint == 4)
- {
- Damage = Damage * 9;
- System.out.print("Critical hit! : ");
- }
- if (Randint != 4)
- {
- Damage = Damage * 3;
- System.out.print("Minicrit! : ");
- }
- }
- if (P1Jarated == false)
- {
- RandInt(1, 60);
- if (Randint == 60)
- {
- Damage = 3 * Damage;
- System.out.print("Critical hit! : ");
- }
- if (Randint >= 57)
- {
- Damage = 3 * Damage;
- if (Randint != 60)
- System.out.print("Minicrit! : ");
- }
- if (Randint <= 7)
- {
- Damage = 0 * Damage;
- System.out.print("Missed! : ");
- }
- }
- RandInt(92, 97);
- Damage = (float) Damage / ((Randint/10) * P1Defense);
- System.out.print(P2name);
- System.out.print(" does ");
- System.out.print((int) (Damage));
- System.out.print(" damage; ");
- P1Health = P1Health - Damage;
- System.out.print(P1name);
- System.out.print(" has ");
- if (P1Health > 0)
- System.out.print((int) P1Health);
- if (P1Health <= 0)
- System.out.print("0");
- System.out.println(" health remaining.");
- P2PostCombatEffects();
- System.out.println("");
- }
- public static void CombatResolver()
- {
- if (P1Health <= 0)
- {
- System.out.println("");
- System.out.println("[-------------]");
- System.out.print(P2name);
- System.out.println(" is victorious!");
- System.out.println("[-------------]");
- input.next();
- }
- if (P2Health <= 0)
- {
- System.out.println("");
- System.out.println("[-------------]");
- System.out.print(P1name);
- System.out.println(" is victorious!");
- System.out.println("[-------------]");
- input.next();
- }
- }
- public static void Inputs()
- {
- //Names
- System.out.print("P1 Name?- ");
- P1name = input.nextLine();
- System.out.print("P2 Name?- ");
- P2name = input.nextLine();
- //HP
- System.out.print(P1name);
- System.out.print(" Health?- ");
- P1Health = input.nextFloat();
- while (P1Health < 0)
- {
- System.out.println("Invalid input.");
- P1Health = input.nextFloat();
- }
- System.out.print(P2name);
- System.out.print(" Health?- ");
- P2Health = input.nextFloat();
- while (P2Health < 0)
- {
- System.out.println("Invalid input.");
- P2Health = input.nextFloat();
- }
- //nextInt, nextFloat, next, nextLine are all valid here
- //attack
- System.out.print(P1name);
- System.out.print(" Attack?- ");
- P1Attack = input.nextFloat();
- System.out.print(P2name);
- System.out.print(" Attack?- ");
- P2Attack = input.nextFloat();
- //P1 defense
- System.out.print(P1name);
- System.out.print(" Defense (100 or less please)?- ");
- P1Defense = input.nextFloat();
- while (P1Defense > 100 || P1Defense < 0)
- {
- System.out.println("Invalid input.");
- P1Defense = input.nextFloat();
- }
- //P2 defense
- System.out.print(P2name);
- System.out.print(" Defense (100 or less please)?- ");
- P2Defense = input.nextFloat();
- while (P2Defense > 100 || P2Defense < 0)
- {
- System.out.println("Invalid input.");
- P2Defense = input.nextFloat();
- }
- //Max value for inherent defense should be 60, although it is inputted as up to 100.
- P1Defense = (P1Defense*6)/10;
- P2Defense = (P2Defense*6)/10;
- //P1 Armor
- System.out.print(P1name);
- System.out.print(" Armor? (none, leather, chainmail, iron, diamond, enchanted)- ");
- P1Armor = input.next();
- switch (P1Armor.toLowerCase())
- {
- case "leather":
- P1Defense = P1Defense +7;
- break;
- case "chainmail":
- P1Defense = P1Defense +15;
- break;
- case "iron":
- P1Defense = P1Defense +25;
- break;
- case "diamond":
- P1Defense = P1Defense +30;
- break;
- case "enchanted":
- P1Defense = P1Defense +35;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- //P2 Armor
- System.out.print(P2name);
- System.out.print(" Armor? (none, leather, chainmail, iron, diamond, enchanted)- ");
- P2Armor = input.next();
- switch (P2Armor.toLowerCase())
- {
- case "leather":
- P2Defense = P2Defense +7;
- break;
- case "chainmail":
- P2Defense = P2Defense +15;
- break;
- case "iron":
- P2Defense = P2Defense +25;
- break;
- case "diamond":
- P2Defense = P2Defense +30;
- break;
- case "enchanted":
- P2Defense = P2Defense +35;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- //P1 shield
- System.out.print(P1name);
- System.out.print(" Shield? (none, wooden, square, kite)- ");
- P1Armor = input.next();
- switch (P1Armor.toLowerCase())
- {
- case "wooden":
- P1Defense = P1Defense +5;
- break;
- case "square":
- P1Defense = P1Defense +10;
- break;
- case "kite":
- P1Defense = P1Defense +15;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- //P2 shield
- System.out.print(P2name);
- System.out.print(" Shield? (none, wooden, square, kite)- ");
- P2Armor = input.next();
- switch (P2Armor.toLowerCase())
- {
- case "wooden":
- P2Defense = P2Defense +5;
- break;
- case "square":
- P2Defense = P2Defense +10;
- break;
- case "kite":
- P2Defense = P2Defense +15;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- //Fixes Defense values so they can be used in dmg calc.
- P1Defense = Math.abs(P1Defense - 130);
- P2Defense = Math.abs(P2Defense - 130);
- P1Defense = (float) Math.sqrt(P1Defense);
- P2Defense = (float) Math.sqrt(P2Defense);
- //Speed inputs
- System.out.print(P1name);
- System.out.print(" Speed?- ");
- P1Speed = input.nextFloat();
- while (P1Speed <= 0)
- {
- System.out.println("Invalid input.");
- P1Speed = input.nextFloat();
- }
- System.out.print(P2name);
- System.out.print(" Speed?- ");
- P2Speed = input.nextFloat();
- while (P2Speed <= 0)
- {
- System.out.println("Invalid input.");
- P2Speed = input.nextFloat();
- }
- P1Speed = P1Speed + 100;
- P2Speed = P2Speed + 100;
- //Mount inputs
- System.out.print(P1name);
- System.out.print(" Mount? (none, pig, bull, horse, battlehorse, dragon)- ");
- P1Armor = input.next();
- switch (P1Armor.toLowerCase())
- {
- case "pig":
- P1Speed = (float) (P1Speed * 1.25);
- break;
- case "bull":
- P1Speed = (float) (P1Speed * 2.5);
- P1Attack = (float) (P1Attack + 5);
- P1Defense = (float) (P1Defense + 1);
- break;
- case "horse":
- P1Speed = (float) (P1Speed * 4);
- P1Defense = (float) (P1Defense + 3);
- break;
- case "battlehorse":
- P1Speed = (float) (P1Speed * 6);
- P1Attack = (float) (P1Attack + 7);
- P1Defense = (float) (P1Defense + 10);
- break;
- case "dragon":
- P1Speed = (float) (P1Speed * 8);
- P1Attack = (float) (P1Attack + 12);
- P1Defense = (float) (P1Defense + 10);
- P1Burner = true;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- System.out.print(P2name);
- System.out.print(" Mount? (none, pig, bull, horse, battlehorse, dragon)- ");
- P2Armor = input.next();
- switch (P2Armor.toLowerCase())
- {
- case "pig":
- P2Speed = (float) (P2Speed * 1.25);
- break;
- case "bull":
- P2Speed = (float) (P2Speed * 2.5);
- P2Attack = (float) (P2Attack + 5);
- P2Defense = (float) (P2Defense + 1);
- break;
- case "horse":
- P2Speed = (float) (P2Speed * 4);
- P2Defense = (float) (P2Defense + 3);
- break;
- case "battlehorse":
- P2Speed = (float) (P2Speed * 6);
- P2Attack = (float) (P2Attack + 7);
- P2Defense = (float) (P2Defense + 10);
- break;
- case "dragon":
- P2Speed = (float) (P2Speed * 8);
- P2Attack = (float) (P2Attack + 12);
- P2Defense = (float) (P2Defense + 10);
- P2Burner = true;
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- //Weapon inputs
- System.out.print(P1name);
- System.out.print(" Weapon? (none, dagger, sword, whip, lance, poisondagger, flamesword, battleaxe, staff)- ");
- P1Armor = input.next();
- switch (P1Armor.toLowerCase())
- {
- case "dagger":
- P1Speed = (float) (P1Speed + 10);
- P1Attack = (float) ((P1Attack * 1.1) +5);
- break;
- case "sword":
- P1Speed = (float) (P1Speed * .9);
- P1Attack = (float) ((P1Attack * 1.3) +7);
- break;
- case "flamesword":
- P1Speed = (float) (P1Speed * .9);
- P1Attack = (float) ((P1Attack * 1.3) +7);
- P1Burner = true;
- break;
- case "whip":
- P1Attack = (float) (P1Attack * 1.5);
- break;
- case "poisondagger":
- P1Speed = (float) (P1Speed + 10);
- P1Attack = (float) ((P1Attack * 1.1) +5);
- P1Poisoner = true;
- case "lance":
- P1Attack = (P1Attack + P1Speed - 100);
- break;
- case "battleaxe":
- P1Attack = (float) (P1Attack +17);
- break;
- case "staff":
- P1Speed = (float) (P1Speed * 1.2);
- P1Attack = (float) ((P1Attack * 1.2) +3);
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- System.out.print(P2name);
- System.out.print(" Weapon? (none, dagger, sword, whip, lance, poisondagger, flamesword, battleaxe, staff)- ");
- P2Armor = input.next();
- switch (P2Armor.toLowerCase())
- {
- case "dagger":
- P2Speed = (float) (P2Speed + 10);
- P2Attack = (float) ((P2Attack * 1.1) +5);
- break;
- case "sword":
- P2Speed = (float) (P2Speed * .9);
- P2Attack = (float) ((P2Attack * 1.3) +7);
- break;
- case "flamesword":
- P2Speed = (float) (P2Speed * .9);
- P2Attack = (float) ((P2Attack * 1.3) +7);
- P2Burner = true;
- break;
- case "poisondagger":
- P2Speed = (float) (P2Speed + 10);
- P2Attack = (float) ((P2Attack * 1.1) +5);
- P2Poisoner = true;
- break;
- case "whip":
- P2Attack = (float) (P2Attack * 1.5);
- break;
- case "lance":
- P2Attack = (P2Attack + P2Speed - 100);
- break;
- case "battleaxe":
- P2Attack = (float) (P2Attack +17);
- break;
- case "staff":
- P2Speed = (float) (P2Speed * 1.2);
- P2Attack = (float) ((P2Attack * 1.2) +3);
- break;
- default:
- System.out.println("Interpreted as 'none'");
- break;
- }
- System.out.println("---BATTLE---");
- System.out.println("");
- System.out.println("");
- System.out.println("");
- }
- public static int RandInt(float a, float b)
- {
- Randint = (int) (a + (Math.random() * (b - a + 1)));
- return Randint;
- }
- public static void P1PostCombatEffects()
- {
- if (P1Burner == true && Damage != 0 && P2Burning == false)
- {
- RandInt(1,6);
- if (Randint == 6)
- {
- P2Burning = true;
- System.out.print(P2name);
- System.out.println(" caught fire!");
- }
- }
- if (P2Burning == true)
- {
- System.out.print(P2name);
- System.out.print(" is on fire! ");
- RandInt(20, 60);
- Damage = Randint;
- RandInt(1, 2);
- Damage = (float) Damage / (Randint * P2Defense);
- System.out.print((int) Damage);
- System.out.print(" damage taken as a result. ");
- P2Health = P2Health - Damage;
- if (P2Health > 0)
- System.out.print((int) P2Health);
- if (P2Health <= 0)
- System.out.print("0");
- System.out.println(" health left.");
- RandInt(1, 5);
- if (Randint == 1)
- {
- System.out.print(P2name);
- System.out.println(" is no longer burning.");
- P2Burning = false;
- }
- }
- if (P1Poisoner == true && Damage != 0 && P2Poisoned == false)
- {
- RandInt(1,7);
- if (Randint == 6)
- {
- P2Poisoned = true;
- System.out.print(P2name);
- System.out.println(" has been poisoned!");
- }
- }
- if (P2Poisoned == true)
- {
- System.out.print(P2name);
- System.out.print(" is poisoned! ");
- RandInt(30, 60);
- Damage = Randint;
- RandInt(1, 2);
- Damage = (float) Damage / (Randint * P2Defense);
- System.out.print((int) Damage);
- System.out.print(" damage taken as a result. ");
- P2Health = P2Health - Damage;
- if (P2Health > 0)
- System.out.print((int) P2Health);
- if (P2Health <= 0)
- System.out.print("0");
- System.out.println(" health left.");
- RandInt(1, 4);
- if (Randint == 1)
- {
- System.out.print(P2name);
- System.out.println(" is no longer poisoned.");
- P2Poisoned = false;
- }
- }
- if (P2Jarated == true)
- {
- RandInt(1,5);
- if (Randint == 1 || Randint == 2)
- {
- System.out.print(P2name);
- System.out.println(" has recovered from jarate.");
- P2Jarated = false;
- }
- }
- if (P2Jarated == false)
- {
- RandInt(1,35);
- if (Randint == 1)
- {
- P2Jarated = true;
- System.out.print(P2name);
- System.out.println(" has been jarated!");
- }
- }
- }
- public static void P2PostCombatEffects()
- {
- if (P2Burner == true && Damage != 0 && P1Burning == false)
- {
- RandInt(1,6);
- if (Randint == 6)
- {
- P1Burning = true;
- System.out.print(P1name);
- System.out.println(" caught fire!");
- }
- }
- if (P1Burning == true)
- {
- System.out.print(P1name);
- System.out.print(" is on fire! ");
- RandInt(20, 60);
- Damage = Randint;
- RandInt(1, 2);
- Damage = (float) Damage / (Randint * P1Defense);
- System.out.print((int) Damage);
- System.out.print(" damage taken as a result. ");
- P1Health = P1Health - Damage;
- if (P1Health > 0)
- System.out.print((int) P1Health);
- if (P1Health <= 0)
- System.out.print("0");
- System.out.println(" health left.");
- RandInt(1, 5);
- if (Randint == 1)
- {
- System.out.print(P1name);
- System.out.println(" is no longer burning.");
- P1Burning = false;
- }
- }
- if (P2Poisoner == true && Damage != 0 && P1Poisoned == false)
- {
- RandInt(1,7);
- if (Randint == 5)
- {
- P2Poisoned = true;
- System.out.print(P1name);
- System.out.println(" has been poisoned!");
- }
- }
- if (P1Poisoned == true)
- {
- System.out.print(P1name);
- System.out.print(" is poisoned! ");
- RandInt(30, 50);
- Damage = Randint;
- RandInt(1, 2);
- Damage = (float) Damage / (Randint * P1Defense);
- System.out.print((int) Damage);
- System.out.print(" damage taken as a result. ");
- P1Health = P1Health - Damage;
- if (P1Health > 0)
- System.out.print((int) P1Health);
- if (P1Health <= 0)
- System.out.print("0");
- System.out.println(" health left.");
- RandInt(1, 4);
- if (Randint == 1)
- {
- System.out.print(P1name);
- System.out.println(" is no longer poisoned.");
- P1Poisoned = false;
- }
- }
- if (P1Jarated == true)
- {
- RandInt(1,5);
- if (Randint == 1 || Randint == 2)
- {
- System.out.print(P1name);
- System.out.println(" has recovered from jarate.");
- P1Jarated = false;
- }
- }
- if (P1Jarated == false)
- {
- RandInt(1,35);
- if (Randint == 1)
- {
- P1Jarated = true;
- System.out.print(P1name);
- System.out.println(" has been jarated!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement