Skip to content

Commit

Permalink
Finishes CombatMenu and adds a tester.
Browse files Browse the repository at this point in the history
  • Loading branch information
aknobloch committed Nov 7, 2016
1 parent 0656a64 commit 7b3156a
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 66 deletions.
14 changes: 14 additions & 0 deletions AnEndlessNight/src/main/CombatTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main;

import main.MenuSystem.MenuLoader;

public class CombatTester {

public static void main(String[] args) {

Game.initializeGame();
MenuLoader.loadStartMenu(null);

}

}
191 changes: 125 additions & 66 deletions AnEndlessNight/src/main/MenuSystem/CombatMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
import main.CombatSystem.DamageHandler;
import main.CombatSystem.EscapeController;
import main.CombatSystem.Monster;
import main.CombatSystem.StatusCondition;

/**
*
* @author Aaron
*
*/
public class CombatMenu extends AbstractMenu {

static boolean battleContinuing;

public CombatMenu(MenuLoader menuLoader) {
super(menuLoader);
Expand All @@ -19,69 +26,110 @@ void mainPrompt() {

Monster currentMonster = Game.getHero().getRoom().getMonster();
System.out.println("A " + currentMonster.getName() + " stares you down.");
System.out.println("What is your next move?");
System.out.println();
System.out.println("1. Attack Monster");
System.out.println("2. Brace Yourself");
System.out.println("3. Attempt to Flee");
System.out.println("4. Use Item");
System.out.println();

battleContinuing = true;

int userChoice = -1;
boolean validInput = false;

do {
try {

userChoice = GameInput.getInt();
validInput = true;

} catch (IOException e) {

System.out.println("You mumble incoherently. You should be wary of nonsensical babbling, ");
System.out.println("else you be labeled insane.");
System.out.println();
validInput = false;

}

} while( ! validInput);

if(userChoice == 1) {

attack(currentMonster);
while(battleContinuing) {

System.out.println("What is your next move?");
System.out.println();
System.out.println("1. Attack Monster");
System.out.println("2. Brace Yourself");
System.out.println("3. Attempt to Flee");
System.out.println("4. Use Item");
System.out.println();


int userChoice = -1;
boolean validInput = false;

do {
try {

userChoice = GameInput.getInt();
validInput = true;

} catch (IOException e) {

System.out.println("You mumble incoherently. You should be wary of nonsensical babbling, ");
System.out.println("else you be labeled insane.");
System.out.println();
validInput = false;

}

} while( ! validInput);

if(userChoice == 1) {

attack(currentMonster);

}
else if(userChoice == 2) {

defend(currentMonster);

}
else if(userChoice == 3) {

flee(currentMonster);

}
else if(userChoice == 4) {
// TODO: handle item use
}
else {
// something went wrong
this.mainPrompt();
}
}
else if(userChoice == 2) {

defend(currentMonster);


}

private void attack(Monster currentMonster) {

DamageHandler combatManager = new DamageHandler();
System.out.println("You raise your " + Game.getHero().getEquippedWeapon().getName() +
" and bring it down on the " + currentMonster.getName());

int monsterAttackResult = combatManager.attackMonster();

if(monsterAttackResult == 0)
{
System.out.println("Your attack barely grazes the creature, leaving it undamaged.");
System.out.println();
monsterAttack();
}
else if(userChoice == 3) {

flee(currentMonster);
else if(monsterAttackResult == -1)
{
System.out.println("Your attack sinks deep into the " + currentMonster.getName() +
", mortally wounding it.");
System.out.println("Its body slumps over as the last breath escapes its body.");
System.out.println();

battleContinuing = false;
MenuLoader.loadGameMenu(this);
}
else if(userChoice == 4) {
// TODO: handle item use
}
else {
// something went wrong
this.mainPrompt();
else
{
System.out.println("Your weapon vibrates as it strikes the creature, wounding it.");
System.out.println("The creature has " + monsterAttackResult + " health remaining.");
System.out.println();
monsterAttack();
}

}

private void defend(Monster currentMonster) {

DamageHandler combatManager = new DamageHandler();
int monsterDamage = currentMonster.getStrength();
// defending reduces monster damage by 1/3
monsterDamage = monsterDamage - (monsterDamage / 3);
Game.getHero().addStatusCondition(StatusCondition.DEFENSE_BUFF);

System.out.println("You brace yourself for an attack.");

monsterAttack();

Game.getHero().removeStatusCondition(StatusCondition.DEFENSE_BUFF);

}

private void flee(Monster battleMonster) {
Expand All @@ -93,41 +141,52 @@ private void flee(Monster battleMonster) {

System.out.println("You feign an attack, and dart off while the " + battleMonster.getName() + " attempts to brace itself.");
System.out.println();
battleContinuing = false;
MenuLoader.loadGameMenu(this);

}
else {

System.out.println("You try to escape, but the " + battleMonster.getName() + " is too fast.");

DamageHandler combat = new DamageHandler();
int combatResult = combat.attackHero();
monsterAttack();

if(combatResult == -1) {

heroDeath();

}
else if(combatResult == 0) {

System.out.println("The creature attempts to attack, but you swiftly dodge.");
System.out.println();

}
else {

System.out.println("It attacks you, leaving you with " + combatResult + " left.");
System.out.println();

}
}
}

private void monsterAttack() {

System.out.println("The creature attacks!");

DamageHandler combat = new DamageHandler();
int combatResult = combat.attackHero();

if(combatResult == -1) {

battleContinuing = false;
heroDeath();

}
else if(combatResult == 0) {

System.out.println("The creature lunges, but you swiftly dodge.");
System.out.println();

}
else {

System.out.println("It attacks you, leaving you with " + combatResult + " health left.");
System.out.println();

}

}

private void heroDeath() {

System.out.println("Your knees crumple and your vision fades as your wounds become too much to bear.");
System.out.println();
battleContinuing = false;
MenuLoader.loadStartMenu(this);

}
Expand Down

0 comments on commit 7b3156a

Please sign in to comment.