Real-time Stat Updates
Throughout playing the game the player's score, health and possibly attack power will change. Below we will show how those UI elements change.
Below is a function that is inside both the Battle Form and the Level Forms, although the function in the Levels forgo updating the Enemy's health since that is only needed in the battle screen. The health bars are just a fraction of the current health over the max health, so the health level is apparent at a glance. Each other element is just a label, and has the ToString called to print itself on the UI element. UpdateStats() is called after any button click in form battle, for the overworld, the stats update on the same tick that updated the time label uses to show the elapsed time.
private void UpdateStats() {
float playerHealthPer = player.Health / (float)player.MaxHealth;
float enemyHealthPer = enemy.Health / (float)enemy.MaxHealth;
const int MAX_HEALTHBAR_WIDTH = 226;
lblPlayerHealthFull.Width = (int)(MAX_HEALTHBAR_WIDTH * playerHealthPer);
lblEnemyHealthFull.Width = (int)(MAX_HEALTHBAR_WIDTH * enemyHealthPer);
lblPlayerHealthFull.Text = player.Health.ToString() + "/" + player.MaxHealth.ToString();
lblEnemyHealthFull.Text = enemy.Health.ToString() + "/" + enemy.MaxHealth.ToString();
lblPlayerStrength.Text = "Attack Power: " + (player._strength * 4).ToString();
lblPlayerScore.Text = "Score: " + player.Score.ToString();
}
Here is an example of the game state where the player has defeated two enemies, and is fighting a third.

Last updated