<commit_before>/** 
 * @file hud_fox.cpp
 * @brief Purpose: Contains methods to game class' management.
 * 
 * MIT License
 * Copyright (c) 2017 MindScape
 *
 * https://github.com/TecProg2017-2/mindscape/blob/master/LICENSE.md
 */
#include "../include/hud_fox.hpp"
#include "../engine/include/log.hpp"

using namespace mindscape;

/**
 * @brief Class Contructor.  
 * 
 * Sets Hud Fox's firsts informations (attributes' values).
 * (Hud Fox: Fox's health bar).  
 *
 * @param name Hud Fox's name(name of the object).
 * @param position Hud Fox's coordinates in the game's map.
 * @param priority Hud Fox's priority in game's execution.  
 * @return void.
 */
HudFox::HudFox(
    std::string name,
    std::pair<int, int> position,
    int priority)
    :engine::GameObject(
        name,
        position,
        priority,
        {
            //No engine Keyboard Event needed.
        }
    ) {
        initialize_animations();
        initialize_audio_effects();
};

/**
 * @brief Initiates Hud Fox's sound effect.  
 * 
 * Sets sound effect of heart.
 * @return void.
 */
void HudFox::initialize_audio_effects() {
    
    DEBUG("Started");
    
    /* Initiates sound effect */
    engine::Audio * take_this_hp = nullptr;
    take_this_hp = new engine::Audio(
        "heart", "../assets/audios/effects_songs/mindscape_heart.wav", 
        engine::Audio::CHUNK);
    
    /* Set duration of the sound effect and add component in game */
    take_this_hp->set_duration(1);
    add_component(take_this_hp);

    DEBUG("Ended");
}

/**
 * @brief Notifies Hud Fox of Fox's state.  
 * 
 * Verifies Fox's state and sets stars' animation depending of the quantity of
 *  stars collected.
 *
 * @param game_object Object for observe game's situation, 
 * in this case, the Fox.
 * @return void.
 */
void HudFox::notify(engine::Observable* game_object) {
    
    Fox* fox = nullptr;
    fox = dynamic_cast<Fox *>(game_object);

    if(fox) {
    /* If the fox exists */ 
        bool give_hp = false; /*< Boolean. Boolean that defines if 
        hp is being given or not */
        give_hp = fox->get_animation_hud_fading();
        
        engine::Animation* actual = NULL;
        actual = get_actual_animation();
        
        if(actual == animations["three_star_fading"]) {
        /* If stars are fading */    
            if(actual->is_finished) {   
            /* If stars already faded */
                give_hp = false;
                fox->set_star_count(0);
                set_actual_animation(animations["zero_star"]);
            }
        }

        else {
        /* If the animation is not stars fading */  
            int count = 0; /*< Integer. Number of stars */
            count = fox->get_star_count();
             
            if(count == 0) {
            /* If there are no stars */
                if(!(get_actual_animation() == animations["zero_star"])) {
                    set_actual_animation(animations["zero_star"]);
                }
            }

            else if(count == 1) {
            /* If there is one star */    
                if(!(get_actual_animation() == animations["one_star"])){
                    set_actual_animation(animations["one_star"]);
                }
            }

            else if(count == 2) {
            /* If there are two stars */    
                if(!(get_actual_animation() == animations["two_star"])) {
                    set_actual_animation(animations["two_star"]);
                }
            }

            else if(count == 3 && !give_hp) {
            /* If there are three stars and is not giving hp */
                if(!(get_actual_animation() == animations["three_star"])) {
                    set_actual_animation(animations["three_star"]);
                }  
            }

            else if(count == 3 && give_hp) {
            /* If there are three stars and is giving hp */
                fox->set_animation_hud_fading(false);
                set_actual_animation(animations["three_star_fading"]);
                play_song("heart");
            }
        }
    }

    else {
        /* Do nothing */
        WARN("HudFox: Fox IS NULL");<commit_msg>[DEFAULT BEHAVIOUR] Applies default behaviour in Hud_Fox.cpp<commit_after>/** 
 * @file hud_fox.cpp
 * @brief Purpose: Contains methods to game class' management.
 * 
 * MIT License
 * Copyright (c) 2017 MindScape
 *
 * https://github.com/TecProg2017-2/mindscape/blob/master/LICENSE.md
 */
#include "../include/hud_fox.hpp"
#include "../engine/include/log.hpp"

using namespace mindscape;

/**
 * @brief Class Contructor.  
 * 
 * Sets Hud Fox's firsts informations (attributes' values).
 * (Hud Fox: Fox's health bar).  
 *
 * @param name Hud Fox's name(name of the object).
 * @param position Hud Fox's coordinates in the game's map.
 * @param priority Hud Fox's priority in game's execution.  
 * @return void.
 */
HudFox::HudFox(
    std::string name,
    std::pair<int, int> position,
    int priority)
    :engine::GameObject(
        name,
        position,
        priority,
        {
            //No engine Keyboard Event needed.
        }
    ) {
        initialize_animations();
        initialize_audio_effects();
};

/**
 * @brief Initiates Hud Fox's sound effect.  
 * 
 * Sets sound effect of heart.
 * @return void.
 */
void HudFox::initialize_audio_effects() {
    
    DEBUG("Started");
    
    /* Initiates sound effect */
    engine::Audio * take_this_hp = nullptr;
    take_this_hp = new engine::Audio(
        "heart", "../assets/audios/effects_songs/mindscape_heart.wav", 
        engine::Audio::CHUNK);
    
    /* Set duration of the sound effect and add component in game */
    take_this_hp->set_duration(1);
    add_component(take_this_hp);

    DEBUG("Ended");
}

/**
 * @brief Notifies Hud Fox of Fox's state.  
 * 
 * Verifies Fox's state and sets stars' animation depending of the quantity of
 *  stars collected.
 *
 * @param game_object Object for observe game's situation, 
 * in this case, the Fox.
 * @return void.
 */
void HudFox::notify(engine::Observable* game_object) {
    
    Fox* fox = nullptr;
    fox = dynamic_cast<Fox *>(game_object);

    if(fox) {
    /* If the fox exists */ 
        bool give_hp = false; /*< Boolean. Boolean that defines if 
        hp is being given or not */
        give_hp = fox->get_animation_hud_fading();
        
        engine::Animation* actual = NULL;
        actual = get_actual_animation();
        
        if(actual == animations["three_star_fading"]) {
        /* If stars are fading */    
            if(actual->is_finished) {   
            /* If stars already faded */
                give_hp = false;
                fox->set_star_count(0);
                set_actual_animation(animations["zero_star"]);
            }

            else {
                /* Do nothing */
            }
        }

        else {
        /* If the animation is not stars fading */  
            int count = 0; /*< Integer. Number of stars */
            count = fox->get_star_count();
             
            if(count == 0) {
            /* If there are no stars */
                if(!(get_actual_animation() == animations["zero_star"])) {
                    set_actual_animation(animations["zero_star"]);
                }

                else {
                    /* Do nothing */
                }
            }

            else if(count == 1) {
            /* If there is one star */    
                if(!(get_actual_animation() == animations["one_star"])){
                    set_actual_animation(animations["one_star"]);
                }

                else {
                    /* Do nothing */
                }
            }

            else if(count == 2) {
            /* If there are two stars */    
                if(!(get_actual_animation() == animations["two_star"])) {
                    set_actual_animation(animations["two_star"]);
                }

                else {
                    /* Do nothing */
                }
            }

            else if(count == 3 && !give_hp) {
            /* If there are three stars and is not giving hp */
                if(!(get_actual_animation() == animations["three_star"])) {
                    set_actual_animation(animations["three_star"]);
                } 
                else {
                    /* Do nothing */
                }
            }

            else if(count == 3 && give_hp) {
            /* If there are three stars and is giving hp */
                fox->set_animation_hud_fading(false);
                set_actual_animation(animations["three_star_fading"]);
                play_song("heart");
            }

            else {
                /* Do nothing */
            }
        }
    }

    else {
        /* Do nothing */
        WARN("HudFox: Fox IS NULL");
{'fraction_non_alphanumeric': 0.11937422060990817, 'fraction_numerical': 0.0038544382723047273, 'mean_word_length': 1.7011635027556644, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1496243', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2446, 'n_words': 627}