/***************************************************************************
 *   Copyright (C) 2004 by Christian Hubinger                              *
 *   e9806056@student.tuwien.ac.at                                         *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "kfgame.h"

// QT includes

// KDE includes
#include <kdebug.h>

// project includes
#include "kflevel.h"

KFGame::KFGame() {
	m_reachedLevel = -1;
	m_score = -1;
	m_gameHistory.setAutoDelete( true );
	m_skill = -1;
}

KFGame::~KFGame() {
}

void KFGame::startGame( int skill ) {
	m_skill = skill;
	m_gameHistory.clear();
}

void KFGame::endGame() {
	QPtrListIterator<KFLevel> it( m_gameHistory );
	m_score = 0;
	while ( it.current() && ( ! it.atLast() ) ) {
		KFLevel *currLevel = it.current();
		++it;
		
		kdDebug() << "Points in Level " << currLevel->getLevel() << " " << currLevel->getScore() << endl;
		m_score += currLevel->getScore();
	}
	KFLevel *level = m_gameHistory.last();
	m_reachedLevel = level->getLevel() - 1;
}
QPtrList<KFLevel>& KFGame::levelList() {
	return m_gameHistory;
};

void KFGame::startLevel( int level, int moves ) {
	m_reachedLevel = -1;
	m_score = -1;
	KFLevel *newLevel = new KFLevel( level, moves, m_skill );
	m_gameHistory.append( newLevel );
}

KFLevel* KFGame::endLevel( int moves ) {
	KFLevel *currLevel = m_gameHistory.last();
	if ( currLevel ) {
		currLevel->finishedLevel( moves );
		return currLevel;
	} else {
		return 0;
	}
}

KFLevel* KFGame::getLevel() {
	return m_gameHistory.last();
}



