Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class FightGame {
- public static void main(String[] args) {
- healthReset();
- }
- public static void healthReset() {
- int hpu = 100;
- int hpo = 100;
- yourTurn(hpu, hpo);
- }
- public static void yourTurn(int hpu, int hpo) {
- // define starting stats
- Scanner scanner = new Scanner(System.in);
- Random rand = new Random();
- Fighter You = new Fighter();
- Fighter Opponent = new Fighter();
- System.out.println("Choose your fighter!");
- System.out.println("1 for Red, 2 for Blue, 3 for Green, 4 for Yellow, 5 for Purple, 6 for Orange, 7 for Pink, 8 for Black, 9 for Random, 0 for RandomStats");
- int fighterChoice = scanner.nextInt();
- if (fighterChoice == 0)
- {
- fighterChoice = rand.nextInt(8) + 1;
- }
- switch (fighterChoice) {
- // attack, heal, defense, hp
- case 1: You.setStats(15, 3, 5, 110);
- case 2: You.setStats(8, 7, 7, 120);
- case 3: You.setStats(10, 10, 2, 125);
- case 4: You.setStats(40, 5, 5, 80);
- case 5: You.setStats(20, 1, 20, 150);
- case 6: You.setStats(11, 4, 4, 180);
- case 7: You.setStats(5, 25, 10, 115);
- case 8: You.setStats(50, 0, 0, 100);
- case 9: You.setStats(rand.nextInt(30)+1 , rand.nextInt(30)+1, rand.nextInt(30)+1, rand.nextInt(200)+50);
- }
- int adu = 10;
- int ado = 10;
- int heu = 5;
- int heo = 5;
- int deu = 9;
- int deo = 9;
- int actionu;
- while (hpu > 0 || hpo >= 0) {
- System.out.println("1 to Attack, 0 to Heal, 2 to Defend, 3 for Info");
- System.out.println(hpu + " " + hpo);
- // WinLose conditions start
- if (hpu > 0 & hpo <= 0) {
- System.out.println("You Win!");
- playAgain();
- }
- if (hpo > 0 & hpu <= 0) {
- System.out.println("You Lose!");
- playAgain();
- }
- if (hpo <= 0 & hpu <= 0) {
- System.out.println("You Tied!?! How did you do that?");
- playAgain();
- }
- // WinLose conditions end
- Random rand = new Random();
- int actiono = rand.nextInt(3);
- // Your action start
- actionu = scanner.nextInt();
- switch (actionu) {
- case 3:
- System.out.println("1-Attack: Deal damage equal to your attack stat to your opponent.");
- System.out.println("0-Heal: Recover HP equal to your heal stat");
- System.out.println("2-Defend: Only take damage equal to your opponents attack minus your defense if they attack. Reflects excess blocked damage.");
- System.out.println("3-Info: Display these help lines.");
- System.out.println("Any other input will skip your turn.");
- yourTurn(hpu, hpo);
- case 1:
- System.out.println("You Attack");
- switch (actiono) {
- case 2:
- if (adu >= deo)
- {
- hpo -= adu - deo;
- }
- else {
- hpu -= deo - adu;
- }
- System.out.println("Opponent Defends");
- yourTurn(hpu, hpo);
- default:
- break;
- }
- hpo -= adu;
- opponentTurn(hpu, hpo, actionu, actiono);
- case 0:
- System.out.println("You Heal");
- hpu += heu;
- opponentTurn(hpu, hpo, actionu, actiono);
- case 2:
- defend(adu, ado, hpu, hpo, deu, deo, heu, heo, actionu, actiono);
- default:
- System.out.println("Invalid Action");
- opponentTurn(hpu, hpo, actionu, actiono);
- // Your action end
- }
- }
- }
- public static void opponentTurn(int hpu, int hpo, int actionu, int actiono) {
- int adu = 10;
- int ado = 10;
- int heu = 5;
- int heo = 5;
- int deu = 9;
- int deo = 9;
- switch (actiono) {
- case 1:
- System.out.println("Opponent Attacks");
- hpu -= ado;
- yourTurn(hpu, hpo);
- case 0:
- System.out.println("Opponent Heals");
- hpo += heo;
- yourTurn(hpu, hpo);
- case 2:
- defend(ado, adu, hpu, hpo, deu, deo, heu, heo, actionu, actiono);
- default:
- System.out.println("At Default, Invalid Action");
- yourTurn(hpu, hpo);
- }
- }
- public static void defend(int ado, int adu, int hpu, int hpo, int deu, int deo, int heu, int heo, int actionu, int actiono) {
- switch (actiono) {
- case 1:
- System.out.println("You Defend");
- System.out.println("Opponent Attacks");
- if (adu >= deo)
- {
- hpo -= adu - deo;
- }
- else {
- hpu -= deo - adu;
- }
- yourTurn(hpu, hpo);
- case 0:
- System.out.println("You Defend");
- System.out.println("Opponent Heals");
- hpo += heo;
- yourTurn(hpu, hpo);
- case 2:
- switch (actionu) {
- case 2:
- System.out.println("You Defend");
- System.out.println("Opponent Defends");
- yourTurn(hpu, hpo);
- default:
- System.out.println("Opponent Defends");
- yourTurn(hpu, hpo);
- }
- default:
- System.out.println("At Default, Invalid Action");
- yourTurn(hpu, hpo);
- }
- switch (actionu) {
- case 0:
- System.out.println("You Heal");
- System.out.println("Opponent Defends");
- hpu += heu;
- yourTurn(hpu, hpo);
- case 2:
- switch (actiono) {
- case 2:
- System.out.println("You Defend");
- System.out.println("Opponent Defends");
- yourTurn(hpu, hpo);
- default:
- }
- default:
- System.out.println("At Default, Invalid Action");
- yourTurn(hpu, hpo);
- }
- }
- public static void playAgain() {
- System.out.println("Would you like to play again?");
- System.out.println("1 to play again, 0 to quit");
- Scanner scanner = new Scanner(System.in);
- int playagain = scanner.nextInt();
- switch (playagain) {
- case 1:
- healthReset();
- case 0:
- System.exit(0);
- default:
- playAgain();
- }
- }
- }
- /////////////////////////////////////////nextcode
- public class Fighter
- {
- private int attackDamage;
- private int healAmount;
- private int defenseStrength;
- private int startingHealth;
- public void setStats(int adf, int haf, int dsf, int shf)
- {
- attackDamage = adf;
- healAmount = haf;
- defenseStrength = dsf;
- startingHealth = shf;
- }
- public int getAttackDamage()
- {
- return attackDamage;
- }
- public int getHealAmount()
- {
- return healAmount;
- }
- public int getDefenseStrength()
- {
- return defenseStrength;
- }
- public int getStartingHealth()
- {
- return startingHealth;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment