Skip to content
Snippets Groups Projects
state.cpp 642 B
Newer Older
  • Learn to ignore specific revisions
  • #include "state.h"
    
    #include <exception>
    
    Tomas Vybiral's avatar
    Tomas Vybiral committed
    #include <cstring>
    
    
    #include "spdlog/spdlog.h"
    
    void state::push() const {
        spdlog::get("state")->debug("Pushing current state.");
        history.emplace_back(*this);
    }
    
    state state::pop() {
        if (!history.empty()) {
            auto first = history.front();
            history.pop_front();
            return first;
        } else {
            throw std::length_error("History is empty. So nothing can be poped.");
        }
    }
    
    
    Tomas Vybiral's avatar
    Tomas Vybiral committed
    state& state::operator=(const state& other) {
        player = other.player;
        enemies = other.enemies;
        projectiles = other.projectiles;
        return *this;
    }
    
    
    std::list<state> state::history;