Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Text User Interface for Battle scenes
- */
- import java.util.Random;
- public class BattleGUI
- {
- private static Random generator = new Random();
- public static void displayStats(Person p)
- {
- if(p instanceof Player)
- {
- System.out.println(" _________\n | STATS |\n ¯¯¯¯¯¯¯¯¯");
- System.out.print("LEVEL: " + ((Player)p).getLVL());
- System.out.println(" EXP: " + ((Player)p).getEXP() + "/" + ((Player)p).getEXPtoLVL());
- System.out.println("GOLD: " + ((Player)p).getMoney());
- System.out.printf("ATK:%2d (%+3d) DEF:%2d (%+3d)\nSPD:%2d (%+3d) HP: %d/%d (%+3d)\n", p.getAttack() + ((Player)p).getWeapon().getAttack() + ((Player)p).getArmor().getAttack(), ((Player)p).getWeapon().getAttack() + ((Player)p).getArmor().getAttack(), p.getDefense() + ((Player)p).getWeapon().getDefense() + ((Player)p).getArmor().getDefense(), ((Player)p).getWeapon().getDefense() + ((Player)p).getArmor().getDefense(),p.getSpeed() + ((Player)p).getWeapon().getSpeed() + ((Player)p).getArmor().getSpeed(), ((Player)p).getWeapon().getSpeed() + ((Player)p).getArmor().getSpeed(), p.getCurrentHealth(), p.getHealth() + ((Player)p).getWeapon().getHealth() + ((Player)p).getArmor().getHealth(), ((Player)p).getWeapon().getHealth() + ((Player)p).getArmor().getHealth());
- System.out.println("WEAPON: " + ((Player)p).getWeapon().getName());
- System.out.println("ARMOR: " + ((Player)p).getArmor().getName());
- }
- else
- {
- System.out.printf("ATK:%3d DEF:%3d\nSPD:%3d HP: %3d/%-3d\n", p.getAttack(), p.getDefense(), p.getSpeed(), p.getCurrentHealth(), p.getHealth());
- }
- }
- public static void displayStats(BuffItem i)
- {
- if(i.getAttack() > 0)
- {
- System.out.print("ATK: +" + i.getAttack() + " ");
- }
- if(i.getDefense() != 0)
- {
- System.out.print("DEF: +" + i.getDefense() + " ");
- }
- if(i.getSpeed() != 0)
- {
- System.out.print("SPD: +" + i.getSpeed() + " ");
- }
- if(i.getHealth() != 0)
- {
- System.out.print("HP: +" + i.getHealth() + " ");
- }
- if(i instanceof EquipItem)
- {
- System.out.println("while equipped.");
- }
- if(i instanceof ConsumableItem)
- {
- System.out.println("upon use.");
- }
- }
- public static void displayHealthbar(Person p, int healthBarSize)
- {
- System.out.printf("%-10s ", p.getName());
- System.out.print("[");
- for(int x = 0; x < (p.getCurrentHealth() * 1.0 / p.getHealth()) * (healthBarSize - 2); x++)
- {
- System.out.print("■");
- }
- for(int x = 0; x < (healthBarSize - 2) - ((p.getCurrentHealth() * 1.0 / p.getHealth()) * (healthBarSize - 2)); x++)
- {
- System.out.print(" ");
- if(x % 3 == 0 && x != 0)
- {
- System.out.print(" ");
- }
- }
- System.out.print("] ");
- System.out.println(p.getCurrentHealth()+ "/" + p.getHealth());
- }
- public static void displayBattle(Player p, Enemy e)
- {
- System.out.println("____________________________________________________________________\n____________________________________________________________________");
- System.out.println(" __________\n | BATTLE |\n ¯¯¯¯¯¯¯¯¯¯");
- displayHealthbar(e, 30);
- System.out.println();
- System.out.println(e.getSprite() + "\n");
- displayHealthbar(p, 30);
- System.out.println();
- }
- public static String promptBattleInventory(Player p)
- {
- while(true)
- {
- InventoryGUI.displayBattleInventory(p);
- if(p.getInventory().length == 0)
- {
- System.out.println("Nothing here except dust and spiders.");
- String[] inventoryOptionsNull = {"EXIT"};
- TUI.closedResponsePrompt("Options: EXIT", inventoryOptionsNull);
- return "exit";
- }
- String[] inventoryOptions = {"EXAMINE", "EXIT"};
- String input = TUI.closedResponsePrompt("Options: EXAMINE, EXIT", inventoryOptions);
- if(input.equals("exit"))
- {
- return "exit";
- }
- else if(input.equals("examine"))
- {
- este:while(true)
- {
- int numInput = TUI.closedIntResponse("Input a number to select an item to EXAMINE", p.getInventory().length + 1, 0);
- InventoryGUI.display(p.getInventory()[numInput-1]);
- estes:while(true)
- {
- if(p.getInventory()[numInput-1] instanceof EquipItem)
- {
- String[] itemOptions;
- String itemInput;
- if(!(p.isEquipped((EquipItem)(p.getInventory()[numInput-1]))))
- {
- itemOptions = new String[] {"EQUIP", "DISCARD", "EXIT"};
- itemInput = TUI.closedResponsePrompt("Options: EQUIP, DISCARD, EXIT", itemOptions);
- }
- else
- {
- itemOptions = new String[]{"UNEQUIP","DISCARD","EXIT"};
- itemInput = TUI.closedResponsePrompt("Options: UNEQUIP, DISCARD, EXIT", itemOptions);
- }
- if(itemInput.equals("equip"))
- {
- if (((EquipItem)p.getInventory()[numInput - 1]).getType() == 0)
- {
- p.equipWeapon((EquipItem)(p.getInventory()[numInput - 1]));
- }
- else
- {
- p.equipArmor((EquipItem)(p.getInventory()[numInput - 1]));
- }
- return "You equipped the " + p.getInventory()[numInput - 1].getName();
- }
- if(itemInput.equals("unequip"))
- {
- if (((EquipItem)p.getInventory()[numInput - 1]).getType() == 0)
- {
- p.unequipWeapon();
- }
- else
- {
- p.unequipArmor();
- }
- return "You unequipped the " + p.getInventory()[numInput - 1].getName();
- }
- if(itemInput.equals("discard"))
- {
- if(((EquipItem)(p.getInventory()[numInput - 1])).getType() == 0 && ((EquipItem)(p.getInventory()[numInput - 1])).isEquipped())
- {
- p.unequipWeapon();
- }
- else if(((EquipItem)(p.getInventory()[numInput - 1])).getType() == 1 && ((EquipItem)(p.getInventory()[numInput - 1])).isEquipped())
- {
- p.unequipArmor();
- }
- System.out.println("You discarded the " + p.getInventory()[numInput - 1].getName());
- p.removeItem(numInput-1);
- break este;
- }
- if(itemInput.equals("exit"))
- {
- break este;
- }
- }
- if(p.getInventory()[numInput - 1] instanceof ConsumableItem)
- {
- String[] itemOptions = {"USE", "DISCARD", "EXIT"};
- String itemInput = TUI.closedResponsePrompt("Options: USE, EXIT", itemOptions);
- if(itemInput.equals("use"))
- {
- int healthBoost = p.getCurrentHealth() + ((ConsumableItem)(p.getInventory()[numInput - 1])).getHealth();
- if(healthBoost + (p.getCurrentHealth()) > p.getHealth())
- {
- healthBoost = p.getHealth() - p.getCurrentHealth();
- }
- p.setCurrentHealth(p.getCurrentHealth() + healthBoost);
- String s = "You used 1 " + p.getInventory()[numInput - 1].getName();
- p.removeItem(numInput - 1);
- return s;
- }
- if(itemInput.equals("discard"))
- {
- String s = "You discarded 1 " + p.getInventory()[numInput - 1].getName();
- p.removeItem(numInput-1);
- return s;
- }
- if(itemInput.equals("exit"))
- {
- break este;
- }
- }
- }
- }
- }
- }
- }
- public static String promptBattle(Player p, Enemy e)
- {
- String[] options = {"FIGHT", "CHECK", p.getName().toUpperCase(), "INVENTORY"};
- displayBattle(p, e);
- for(int x = 0; x < e.getEncounter().length() + 4; x++)
- {
- System.out.print("*");
- }
- System.out.println("\n* " + e.getEncounter() + " *");
- for(int x = 0; x < e.getEncounter().length() + 4; x++)
- {
- System.out.print("*");
- }
- System.out.println();
- mainLoop:while(true)
- {
- String input = TUI.closedResponsePrompt("Options: FIGHT, CHECK, " + p.getName().toUpperCase() + ", INVENTORY", options);
- if(input.equals("fight"))
- {
- boolean goesFirst = (p.getSpeed() >= e.getSpeed());
- if(goesFirst)
- {
- int enemyDamage = (p.getAttack() + p.getWeapon().getAttack() - e.getDefense());
- if(enemyDamage <= 0)
- {
- enemyDamage = 1;
- }
- e.setCurrentHealth(e.getCurrentHealth() - enemyDamage);
- if(e.getCurrentHealth() < 0)
- {
- e.setCurrentHealth(0);
- }
- }
- if(e.getCurrentHealth() != 0)
- {
- int playerDamage = (e.getAttack() - p.getArmor().getDefense() - p.getDefense());
- if(playerDamage <= 0)
- {
- playerDamage = 1;
- }
- p.setCurrentHealth(p.getCurrentHealth() - playerDamage);
- if(p.getCurrentHealth() < 0)
- {
- p.setCurrentHealth(0);
- }
- }
- if(e.getCurrentHealth() != 0 && !goesFirst)
- {
- int enemyDamage = (p.getAttack() + p.getWeapon().getAttack() - e.getDefense());
- if(enemyDamage <= 0)
- {
- enemyDamage = 1;
- }
- e.setCurrentHealth(e.getCurrentHealth() - enemyDamage);
- if(e.getCurrentHealth() < 0)
- {
- e.setCurrentHealth(0);
- }
- }
- displayBattle(p, e);
- if(goesFirst)
- {
- System.out.println("You attacked!");
- int enemyDamage = (p.getAttack() + p.getWeapon().getAttack() - e.getDefense());
- if(enemyDamage <= 0)
- {
- enemyDamage = 1;
- }
- System.out.println("Opposing " + e.getName() + " took " + enemyDamage + " damage!");
- if(e.getCurrentHealth() <= 0)
- {
- e.setCurrentHealth(e.getHealth());
- System.out.print("You defeated the " + e.getName() + "! ");
- System.out.println(e.getDeath());
- System.out.println("You found " + e.getMoney() + " gold!");
- p.setMoney(p.getMoney() + e.getMoney());
- System.out.println("You gained " + e.getEXP() + " EXP!");
- p.setEXP(p.getEXP() + e.getEXP());
- p.checkToLevel();
- if(!(e.getLoot().equals(EnemyResources.noLoot)))
- {
- int lootValue = generator.nextInt(e.getLoot().length);
- Entity dropt = e.getLoot()[lootValue].getItem();
- if(dropt instanceof ConsumableItem)
- {
- if(e.getLoot()[lootValue].getAmount() > 1)
- {
- System.out.println("You obtained " + e.getLoot()[lootValue].getAmount() + " " + dropt.getName() + "s!");
- for(int x = 0; x < e.getLoot()[lootValue].getAmount(); x++)
- {
- p.addItem(((ConsumableItem)(dropt)));
- }
- break mainLoop;
- }
- else
- {
- System.out.println("You obtained 1 " + dropt.getName() + "!");
- p.addItem((ConsumableItem)(dropt));
- break mainLoop;
- }
- }
- System.out.println("You obtained " + dropt.getName() + "!");
- p.addItem(((BuffItem)(dropt)));
- }
- break mainLoop;
- }
- }
- System.out.println("The opposing " + e.getName() + " attacked!");
- int playerDamage = (e.getAttack() - p.getArmor().getDefense() - p.getDefense());
- if(playerDamage <= 0)
- {
- playerDamage = 1;
- }
- if(p.getCurrentHealth() < 0)
- {
- p.setCurrentHealth(0);
- }
- System.out.println("You took " + playerDamage + " damage!");
- if(p.getCurrentHealth() <= 0)
- {
- System.out.println("You were defeated by the " + e.getName() + ".");
- if(p.getMoney() > 3)
- {
- System.out.println("You lost " + (p.getMoney()/3) + " gold and some dignity.");
- p.setMoney(p.getMoney() - p.getMoney()/3);
- }
- TUI.closedResponsePrompt("Options: CONTINUE", new String[] {"CONTINUE"});
- p.setCurrentHealth(p.getHealth()/3);
- return "loss";
- }
- if(!goesFirst)
- {
- System.out.println("You attacked!");
- int enemyDamage = (p.getAttack() + p.getWeapon().getAttack() - e.getDefense());
- if(enemyDamage <= 0)
- {
- enemyDamage = 1;
- }
- System.out.println("Opposing " + e.getName() + " took " + enemyDamage + " damage!");
- if(e.getCurrentHealth() <= 0)
- {
- e.setCurrentHealth(e.getHealth());
- System.out.print("You defeated the " + e.getName() + "! ");
- System.out.println(e.getDeath());
- System.out.println("You found " + e.getMoney() + " gold!");
- p.setMoney(p.getMoney() + e.getMoney());
- System.out.println("You gained " + e.getEXP() + " EXP!");
- p.setEXP(p.getEXP() + e.getEXP());
- p.checkToLevel();
- if(!(e.getLoot().equals(EnemyResources.noLoot)))
- {
- int lootValue = generator.nextInt(e.getLoot().length);
- Entity dropt = e.getLoot()[lootValue].getItem();
- if(dropt instanceof ConsumableItem)
- {
- if(e.getLoot()[lootValue].getAmount() > 1)
- {
- System.out.println("You obtained " + e.getLoot()[lootValue].getAmount() + " " + dropt.getName() + "s!");
- for(int x = 0; x < e.getLoot()[lootValue].getAmount(); x++)
- {
- p.addItem(((ConsumableItem)(dropt)));
- }
- break mainLoop;
- }
- else
- {
- System.out.println("You obtained 1 " + dropt.getName() + "!");
- p.addItem((ConsumableItem)(dropt));
- break mainLoop;
- }
- }
- System.out.println("You obtained " + dropt.getName() + "!");
- p.addItem(((BuffItem)(dropt)));
- }
- break mainLoop;
- }
- }
- }
- else if(input.equals("check"))
- {
- System.out.println("Name: " + e.getName());
- System.out.println("Info: " + e.getDesc());
- displayStats(e);
- }
- else if(input.equals(p.getName().toLowerCase()))
- {
- System.out.println("____________________________________________________________________\n____________________________________________________________________");
- System.out.println(p.getSprite());
- System.out.println("Name: " + p.getName());
- System.out.println("Info: Yes, that unicode abomination is in fact you.");
- displayStats(p);
- String[] selfCheckOptions = {"EXIT"};
- TUI.closedResponsePrompt("Options: EXIT", selfCheckOptions);
- displayBattle(p, e);
- }
- else if(input.equals("inventory"))
- {
- String s = promptBattleInventory(p);
- if(s.equals("exit"))
- {
- displayBattle(p, e);
- }
- else
- {
- if(e.getCurrentHealth() != 0)
- {
- int playerDamage = (e.getAttack() - p.getArmor().getDefense() - p.getDefense());
- if(playerDamage <= 0)
- {
- playerDamage = 1;
- }
- p.setCurrentHealth(p.getCurrentHealth() - playerDamage);
- if(p.getCurrentHealth() < 0)
- {
- p.setCurrentHealth(0);
- }
- }
- displayBattle(p, e);
- System.out.println(s);
- System.out.println("The opposing " + e.getName() + " attacked!");
- int playerDamage = (e.getAttack() - p.getArmor().getDefense() - p.getDefense());
- if(playerDamage <= 0)
- {
- playerDamage = 1;
- }
- System.out.println("You took " + playerDamage + " damage!");
- if(p.getCurrentHealth() <= 0)
- {
- System.out.println("You were defeated by the " + e.getName() + ".");
- if(p.getMoney() > 3)
- {
- System.out.println("You lost " + (p.getMoney()/3) + " gold and some dignity.");
- p.setMoney(p.getMoney() - p.getMoney()/3);
- }
- TUI.closedResponsePrompt("Options: CONTINUE", new String[] {"CONTINUE"});
- p.setCurrentHealth(p.getHealth()/3);
- return "loss";
- }
- }
- }
- }
- while(true)
- {
- String[] endOptions = {"CONTINUE", p.getName().toUpperCase(), "INVENTORY"};
- String inputEnd = TUI.closedResponsePrompt("Options: CONTINUE, " + p.getName().toUpperCase() + ", INVENTORY", endOptions);
- if(inputEnd.equals("inventory"))
- {
- InventoryGUI.promptInventory(p);
- }
- else if(inputEnd.equals(p.getName().toLowerCase()))
- {
- System.out.println("____________________________________________________________________\n____________________________________________________________________");
- System.out.println(p.getSprite());
- System.out.println("Name: " + p.getName());
- System.out.println("Info: Yes, that unicode abomination is in fact you.");
- displayStats(p);
- String[] selfCheckOptions = {"EXIT"};
- TUI.closedResponsePrompt("Options: EXIT", selfCheckOptions);
- }
- else if(inputEnd.equals("continue"))
- {
- return "win";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement