function progressTurn() {

    // If the battle is finished(either due to the player or enemy dying), flip the switch to redirect to an appropriate screen
    if (finished) {
      setGameover(true);
    }

    // If the enemy died in the last turn, start tallying experience gains and such. 
    else if (!isEnemyAlive) {
      // Give player the gold for killing the enemy
      let goldGain = enemy.goldVal;
      let expGain = enemy.expVal;
      let potionGain = givePotion();

      let totalGold = player.gold + goldGain;
      let totalEXP = player.exp + expGain;
      let totalPotions = player.potions + potionGain;

      if (potionGain > 0) {
        dispatch({
          type: GAIN_LOOT,
          payload: {
            message: `You gained ${goldGain} gold, ${expGain} exp and found ${potionGain} potion(s)`,
            potions: totalPotions,
            gold: totalGold,
            exp: totalEXP
          }
        })
      } else {
        dispatch({
          type: GAIN_LOOT,
          payload: {
            message: `You gained ${goldGain} gold, ${expGain} exp`,
            potions: totalPotions,
            gold: totalGold,
            exp: totalEXP,
          }
        })
      }

      if (totalEXP > player.maxEXP) {
        setLevelUp(true);
      } else {
        setFinished(true);
      }
    }

    // Check if the player lost their HP during this turn. If they did, prepare for GameOver redirection.
    else if (checkForDeath(player.currentHP) == false) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You have been defeated!!!`,
      })
      setCommandAvailability(false);
      setPlayerAliveness(false);
      setFinished(true);
    }

    // Check whether enemy's HP has reached 0. If it has, toggle the flag to make image disappear. Next time Continue is pressed, it'll calculate gold and exp gains.
    else if (checkForDeath(enemyHP) == false) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You have defeated the ${enemy.name}!!`,
      })
      setCommandAvailability(false);
      setEnemyAliveness(false);
    }

    // If nobody died, check if it is the player's turn
    else if (playerTurn) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `It is your turn!`,
      })

      setCommandAvailability(true); // If it is, let them choose a command
    }

    // Check whether it is the enemy's turn. If it is, have the enemy attack by default.
    else if (enemyTurn) {
      enemyAttack()
    }

    /* This ONLY handles the transition from playerTurn to enemyTurn (not vice-versa as there is no need) 
    It might seem odd, but this in-between step allows for the message to be displayed informing the player
    that the enemy is attacking*/
    else {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `The ${enemy.name} is getting ready to attack you`,
      })

      setEnemyTurn(true);
    }
  }
/* The player clicks the "Continue" button on the message-bar. This is where the bulk of the logic happens. 
  Do not change the order in which the checks are handled; it's based on priority. */
The player clicks the "Continue" button on the message-bar. This is where the bulk of the logic happens.
Do not change the order in which the checks are handled; it's based on priority.
The player clicks the " Continue " button on the message - bar . This is where the bulk of the logic happens . Do not change the order in which the checks are handled ; it ' s based on priority .
function progressTurn() {
    if (finished) {
      setGameover(true);
    }
    else if (!isEnemyAlive) {
      let goldGain = enemy.goldVal;
      let expGain = enemy.expVal;
      let potionGain = givePotion();
      let totalGold = player.gold + goldGain;
      let totalEXP = player.exp + expGain;
      let totalPotions = player.potions + potionGain;
      if (potionGain > 0) {
        dispatch({
          type: GAIN_LOOT,
          payload: {
            message: `You gained ${goldGain} gold, ${expGain} exp and found ${potionGain} potion(s)`,
            potions: totalPotions,
            gold: totalGold,
            exp: totalEXP
          }
        })
      } else {
        dispatch({
          type: GAIN_LOOT,
          payload: {
            message: `You gained ${goldGain} gold, ${expGain} exp`,
            potions: totalPotions,
            gold: totalGold,
            exp: totalEXP,
          }
        })
      }
      if (totalEXP > player.maxEXP) {
        setLevelUp(true);
      } else {
        setFinished(true);
      }
    }
    else if (checkForDeath(player.currentHP) == false) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You have been defeated!!!`,
      })
      setCommandAvailability(false);
      setPlayerAliveness(false);
      setFinished(true);
    }
    else if (checkForDeath(enemyHP) == false) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `You have defeated the ${enemy.name}!!`,
      })
      setCommandAvailability(false);
      setEnemyAliveness(false);
    }
    else if (playerTurn) {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `It is your turn!`,
      })
      setCommandAvailability(true); 
    }
    else if (enemyTurn) {
      enemyAttack()
    }
    else {
      dispatch({
        type: CHANGE_MESSAGE,
        payload: `The ${enemy.name} is getting ready to attack you`,
      })
      setEnemyTurn(true);
    }
  }
function progressTurn ( ) { if ( finished ) { setGameover ( true ) ; } else if ( ! isEnemyAlive ) { let goldGain = enemy . goldVal ; let expGain = enemy . expVal ; let potionGain = givePotion ( ) ; let totalGold = player . gold + goldGain ; let totalEXP = player . exp + expGain ; let totalPotions = player . potions + potionGain ; if ( potionGain > 0 ) { dispatch ( { type : GAIN_LOOT , payload : { message : ` ${ goldGain } ${ expGain } ${ potionGain } ` , potions : totalPotions , gold : totalGold , exp : totalEXP } } ) } else { dispatch ( { type : GAIN_LOOT , payload : { message : ` ${ goldGain } ${ expGain } ` , potions : totalPotions , gold : totalGold , exp : totalEXP , } } ) } if ( totalEXP > player . maxEXP ) { setLevelUp ( true ) ; } else { setFinished ( true ) ; } } else if ( checkForDeath ( player . currentHP ) == false ) { dispatch ( { type : CHANGE_MESSAGE , payload : ` ` , } ) setCommandAvailability ( false ) ; setPlayerAliveness ( false ) ; setFinished ( true ) ; } else if ( checkForDeath ( enemyHP ) == false ) { dispatch ( { type : CHANGE_MESSAGE , payload : ` ${ enemy . name } ` , } ) setCommandAvailability ( false ) ; setEnemyAliveness ( false ) ; } else if ( playerTurn ) { dispatch ( { type : CHANGE_MESSAGE , payload : ` ` , } ) setCommandAvailability ( true ) ; } else if ( enemyTurn ) { enemyAttack ( ) } else { dispatch ( { type : CHANGE_MESSAGE , payload : ` ${ enemy . name } ` , } ) setEnemyTurn ( true ) ; } }
The player clicks the "Continue" button on the message-bar.
The player clicks the " Continue " button on the message - bar .
// If the battle is finished(either due to the player or enemy dying), flip the switch to redirect to an appropriate screen // If the enemy died in the last turn, start tallying experience gains and such.  // Give player the gold for killing the enemy // Check if the player lost their HP during this turn. If they did, prepare for GameOver redirection. // Check whether enemy's HP has reached 0. If it has, toggle the flag to make image disappear. Next time Continue is pressed, it'll calculate gold and exp gains. // If nobody died, check if it is the player's turn // If it is, let them choose a command // Check whether it is the enemy's turn. If it is, have the enemy attack by default. /* This ONLY handles the transition from playerTurn to enemyTurn (not vice-versa as there is no need) 
    It might seem odd, but this in-between step allows for the message to be displayed informing the player
    that the enemy is attacking*/