Logo Search packages:      
Sourcecode: fillets-ng version File versions

LevelCountDown.cpp

/*
 * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */
#include "LevelCountDown.h"

#include "LevelStatus.h"
#include "RoomAccess.h"
#include "Room.h"
#include "LogicException.h"
#include "CountAdvisor.h"

//-----------------------------------------------------------------
/**
 * Prepare countdown.
 */
00021 LevelCountDown::LevelCountDown(const RoomAccess *access)
{
    m_countdown = -1;
    m_access = access;
    m_levelStatus = NULL;
}
//-----------------------------------------------------------------
/**
 * Resets counter.
 * @throws LogicException when levelStatus is not filled
 */
void
00033 LevelCountDown::reset()
{
    if (NULL == m_levelStatus) {
        throw LogicException(ExInfo("level status is NULL"));
    }
    m_levelStatus->setRunning(true);
    m_countdown = -1;
}
//-----------------------------------------------------------------
/**
 * Countdown to zero.
 * @param advisor advisor which known usable coundown values
 * @return true when counter is at zero
 */
bool
00048 LevelCountDown::countDown(const CountAdvisor *advisor)
{
    bool result = false;
    if (m_countdown < 0) {
        setCountDown(advisor);
    }
    else if (m_countdown > 0) {
        m_countdown--;
    }
    else {
        result = true;
    }
    return result;
}
//-----------------------------------------------------------------
void
LevelCountDown::setCountDown(const CountAdvisor *advisor)
{
    if (m_access->const_room()->isSolved()) {
        m_countdown = advisor->getCountForSolved();
    }
    else if (m_access->const_room()->cannotMove()) {
        m_countdown = advisor->getCountForWrong();
    }
    else {
        m_countdown = -1;
    }
}
//-----------------------------------------------------------------
bool
LevelCountDown::isFinishedEnough() const
{
    return m_countdown == 0 && m_access->const_room()->isSolved();
}
//-----------------------------------------------------------------
bool
LevelCountDown::isWrongEnough() const
{
    return m_countdown == 0 && m_access->const_room()->cannotMove() &&
        !m_access->const_room()->isSolved();
}
//-----------------------------------------------------------------
/**
 * Write best solution to the file.
 * Save moves and models state.
 */
    void
00095 LevelCountDown::saveSolution()
{
    m_levelStatus->setComplete();
    std::string current_moves = m_access->const_room()->getMoves();
    m_levelStatus->writeSolvedMoves(current_moves);
}
//-----------------------------------------------------------------
/**
 * Creates next state or returns NULL.
 * @return returns NULL when only quitState() is needed
 */
GameState *
00107 LevelCountDown::createNextState()
{
    return m_levelStatus->createPoster();
}


Generated by  Doxygen 1.6.0   Back to index