Overview of Design:
DataTypes The data for the game are stored in JSON objects declared at the top of the JSBattle.js. These could also be loaded from external files.
Player: playerJSON - basic stats of player: name, hp, attack, defense playerAbilities - special abilities the player can use during combat (ex: super attack). An ability has a name, type (damage / heal), timer (current cooldown timer), cooldown (number of turns till reuse), and amount (how much damage / healing / etc) Enemies: goblinJSON, dragonJSON - includes name, total HP, attack, defense, damage, coin, itemList enemyList - master list of all enemies. Items: Items are stored in ItemList.csv. This file is read in by jquery.csv and stored in the respective item lists by the GetItemListFromIDList function. ex: playerItems = GetItemListFromIDList(playerItemList); loads the [1,1,3] from the CSV file (2 small healing potions and a rusty dagger)
Game Initialization 1. Before anything, call initGame("battleArea", "battleLog"); Pass in the names of the Divs used for the battle Area and the battle log. 2. InitGame will store the Divs to use, as well as load the player, item and enemy data from respective JSON and CSV lists. 3. Lastly, it will call DisplayGameWorld(), which will print the options to the player.
Battle Loop 1. To start a battle between the player and an enemy, call initBattleWithEnemy(enemy) 2. This will call initBattle(enemyJSON), which will load the enemyJSON and enemyItem list, as well as start the battle loop. 3. The battleLoop() uses an Interval timer of 1 second for each phase state of the battle. 4. Battle Phases: 0. "Let the battle begin." Initialized state 1. Waiting for player input 2. Enemy Attack 3. Win Battle: Display the Game Options 4. Lose Battle: Display the Game Options 5. The attack calculation - done in the getAttackRatio() function. Ratio = ((((attack - defense) / (attack + defense))) + 1 / 2) * 100. The player/enemy must then roll under the ratio to hit. Damage is deducted from teh player/enemy HP. 6. On victory (WinBattle(), the items from enemyItemList are added to the playerItem list. 7. The main Game screen is displayed DisplayGameWorld()
Display The raw HTML is created for display in the Display and Print functions:
UpdateDisplay() - called in the battleLoop to update the Battle display. printBattle() - prints the current stats, abilities, and usable items of the player and enemy engaged in battle. DisplayAbilities() - helper function to display current player abilities DisplayItems() - helper function to display current player items to use in battle DisplayGameWorld() - displays the "home screen" of the game - options to start a new battle, view equipment, inventory or store DisplayInventory() - current player inventory DisplayEquipment() - current player equipment DisplayStats() - current player stats DisplayNewStore(storeIDList) - display store with given store ID
Logging Logging is done throughout the battle, by adding to the combatStatus variable. This variable is then displayed in the battleLog div.