/// <summary> /// Constructor for the battle engine. /// </summary> private BattleEngine(PartyClass playerParty, PartyClass enemyParty) { // If either are null, exit this class if (playerParty == null || enemyParty == null) { BattleDebug.debugPrint("PlayerParty or EnemyParty is null! Not initializing..."); return; } // If the party sizes aren't correct, also exit if (playerParty.Count <= 0 || enemyParty.Count <= 0) { BattleDebug.debugPrint("PlayerParty or EnemyParty do not have any combatants!"); return; } this.playerParty = playerParty; this.enemyParty = enemyParty; // Set all times to 0 // NOTE: Time should be set based on how much speed a character has playerParty.Initialize(true); enemyParty.Initialize(true); // Set the character triggers to respond playerParty.Ready += ReadyHandler; enemyParty.Ready += EnemyReadyHandler; // Flag that the battle is going on and the timer should update for (int i = 0; i < playerParty.Count; i++) { playerParty.Party[i].BattleGoing = true; } for (int i = 0; i < enemyParty.Count; i++) { enemyParty.Party[i].BattleGoing = true; } // Initialize debug controls and variables debugOn = true; battleDebug = new Debugger("BattleDebug", debugOn); // Signal that the engine has initialized OnInitialized(); }
public static void StartNewBattle(PartyClass playerParty, PartyClass enemyParty) { // If either are null, exit this class if (playerParty == null || enemyParty == null) { throw new InvalidOperationException("PlayerParty or EnemyParty is null!"); } // check if we are already in battle if (singleton != null) { throw new InvalidOperationException("There can only be one battle at a time."); } singleton = new BattleEngine(playerParty, enemyParty); }
/// <summary> /// Load graphics content for the screen (in this case, the battle engine and all necessary classes). /// </summary> public override void LoadContent() { // Create the menu screen menuScreen = new BattleMenuScreen(new Vector2(10, 515)); menuScreen.ScreenManager = this.ScreenManager; // Load the textures if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); battleDialog = content.Load<Texture2D>("battledialog"); battleMenu = content.Load<Texture2D>("battlemenuback"); battleTimer = content.Load<Texture2D>("battletime"); redBox = content.Load<Texture2D>("redbox"); blueBox = content.Load<Texture2D>("bluebox"); // Load the character sprites AnimatingSprite playerSprite = new AnimatingSprite(redBox); AnimatingSprite enemySprite = new AnimatingSprite(blueBox); // DEBUG: Create a dummy party List<CombatCharacter> testList = new List<CombatCharacter>(ChronoConstants.cMaxPartyMembers); CharacterStats testStat = new CharacterStats(1, 10, 10, 10, 10, 10, 10, 10); testStat.Speed = 50; PlayerClass testPlayer = new PlayerClass("Dummy", testStat, playerSprite, 0); testStat.Speed = 25; PlayerClass testPlayer2 = new PlayerClass("Dummy2", testStat, playerSprite, 0); testPlayer.HP = 25; testPlayer2.HP = 25; testList.Add(testPlayer); testList.Add(testPlayer2); PartyClass testParty = new PartyClass(testList); EnemyClass testEnemy = new EnemyClass("Enemy1", testStat, enemySprite); EnemyClass testEnemy2 = new EnemyClass("Enemy2", testStat, enemySprite); List<CombatCharacter> enemyList = new List<CombatCharacter>(ChronoConstants.cMaxPartyMembers); enemyList.Add(testEnemy); enemyList.Add(testEnemy2); PartyClass enemyParty = new PartyClass(enemyList); testParty.InBattle = true; enemyParty.InBattle = true; // Link events from the battle engine testParty.Ready += ReadyHandler; //enemyPlayer.Ready += EnemyReadyHandler; menuScreen.AttackSelected += AttackHandler; BattleEngine.Defeat += DefeatHandler; BattleEngine.Victory += VictoryHandler; // Initialize the engine BattleEngine.StartNewBattle(testParty, enemyParty); // Create the battle director battleDirector = new BattleDirector(ScreenManager.Arrow); }