// This class will run a combat simulation using the Weapon and Creature classes

import java.util.*;

public class CombatSimulation {
	
	// Constants for the warrior creature
	private static final int WARRIOR_HP 		= 50;
	private static final int WARRIOR_STR 		= 10;
	private static final int WARRIOR_SKILL 		= 15;
	private static final int WARRIOR_AC 		= 5;
	private static final String WARRIOR_NAME 	= "Gnusto Frotz";
	private static final String WARRIOR_TYPE 	= "valiant warrior";
	private static final String WARRIOR_PRONOUN	= "his";
	
	// Constants for the monster creature
	private static final int MONSTER_HP 		= 50;
	private static final int MONSTER_STR 		= 15;
	private static final int MONSTER_SKILL 		= 10;
	private static final int MONSTER_AC 		= 7;
	private static final String MONSTER_NAME 	= "Schmoo";
	private static final String MONSTER_TYPE 	= "gruesome monster";
	private static final String MONSTER_PRONOUN	= "its";
	
	// Constants for the monster's weapon (claws)
	private static final int CLAWS_DAMAGE_MOD 	= 3;
	private static final String CLAWS_NAME 		= "claws";
	private static final String CLAWS_HIT 		= "slashes";
	private static final String CLAWS_MISS 		= "swipes at but misses";

	// Constants for the warriors weapon (sword)
	private static final int SWORD_DAMAGE_MOD 	= 5;
	private static final String SWORD_NAME 		= "sword";
	private static final String SWORD_HIT 		= "stabs";
	private static final String SWORD_MISS 		= "swings at but misses";


	// main(): application entry point	
	public static void main(String args[]) {
		
		// Create the warrior's weapon (sword)
		Weapon sword = new Weapon(SWORD_DAMAGE_MOD, SWORD_NAME,
								  SWORD_HIT, SWORD_MISS);

		// Create the monster's weapon (claws)
		Weapon claws = new Weapon();
		claws.setDamageModifier(CLAWS_DAMAGE_MOD);
		claws.setName(CLAWS_NAME);
		claws.setHitVerb(CLAWS_HIT);
		claws.setMissVerb(CLAWS_MISS);
		
		// Create the warrior
		Creature warrior = new Creature();
		warrior.setHitPoints(WARRIOR_HP);
		warrior.setStrength(WARRIOR_STR);
		warrior.setSkill(WARRIOR_SKILL);
		warrior.setArmorClass(WARRIOR_AC);
		warrior.setName(WARRIOR_NAME);
		warrior.setType(WARRIOR_TYPE);
		warrior.setPronoun(WARRIOR_PRONOUN);

		// Create the monster
		Creature monster = new Creature(MONSTER_HP, MONSTER_STR, MONSTER_SKILL,
										MONSTER_AC, MONSTER_NAME, MONSTER_TYPE,
										MONSTER_PRONOUN);
										
		// Arm the creatures with their weapons
		monster.setWeapon(claws);
		warrior.setWeapon(sword);
		
		// While both creatures are still alive...
		while (monster.isAlive() && warrior.isAlive()) {

			// The monster tries to attack the warrior
			if (monster.tryToAttack(warrior.getArmorClass())) {
				// If the monster hit, the warrior takes damage
				System.out.println(monster.constructHitString(warrior));
				warrior.takeDamage(monster.calcHitDamage());
			} else {
				System.out.println(monster.constructMissString(warrior));
			}
			
			System.out.println();
			
			// If the warrior dies, break out of this loop
			if (warrior.isAlive() == false)	{
				break;
			}
			
			// The warrior tries to attack the monster
			if (warrior.tryToAttack(monster.getArmorClass())) {
				// If the warrior hit, the monster takes damage
				System.out.println(warrior.constructHitString(monster));
				monster.takeDamage(warrior.calcHitDamage());

			} else {
				System.out.println(warrior.constructMissString(monster));
			}

			System.out.println();

		}
		
		// Figure out whose alive and dead (good example of the ? : operator)
		Creature alive = warrior.isAlive() ? warrior : monster;
		Creature dead  = warrior.isAlive() ? monster : warrior;
		
		// print out a message to indicate the outcome of the battle.  
		System.out.print(dead.getName()+" dies.  ");
		System.out.println(alive.getName()+" is victorious!");
	}
}