/***************************************************************************
 *   Copyright (C) 2004 by ian reinhart geiser                             *
 *   ian@geiseri.com                                                       *
 *                                                                         *
 *   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 "demoboard.h"
#include "boardmodel.h"
#include "human.h"
#include "warrior.h"
#include "player.h"
#include "leather.h"
#include "shortsword.h"
#include "bandit.h"
#include <QHeaderView>

DemoBoard::DemoBoard(QWidget* parent, Qt::WFlags fl)
: QWidget( parent, fl ), Ui::DemoBoard()
{
	setupUi(this);
	qRegisterMetaType<Bandit>("Bandit");

	m_model = new BoardModel(this);
	board->setModel(m_model);

// 	m_model->loadMap("level.xpm");
	m_model->generateMap(25,25);
	board->resizeColumnsToContents();
	board->resizeRowsToContents();
	board->setShowGrid(false);
	board->horizontalHeader()->hide();
	board->verticalHeader()->hide();
	board->horizontalHeader()->setMinimumSectionSize(1);
	board->verticalHeader()->setMinimumSectionSize(1);

	Player *player = new Player( "Player", new HumanMale(), new Warrior() );
	player->wield( new ShortSword() );
	player->wear( new Leather() );
	m_model->addPlayer( player, m_model->columnCount() / 2, m_model->rowCount() / 2);

	connect( up, SIGNAL(clicked()), m_model, SLOT(movePlayerUp()));
	connect( down, SIGNAL(clicked()), m_model, SLOT(movePlayerDown()));
	connect( left, SIGNAL(clicked()), m_model, SLOT(movePlayerLeft()));
	connect( right, SIGNAL(clicked()), m_model, SLOT(movePlayerRight()));
	connect( regen, SIGNAL(clicked()), this, SLOT( regenerateModel() ));
	connect( m_model, SIGNAL(playerDead()), this, SLOT(gameOver() ));
	connect( m_model, SIGNAL(status(const QString&)), status, SLOT(setText(const QString&)));

	resize(800,600);
}

DemoBoard::~DemoBoard()
{
}

/*$SPECIALIZATION$*/

void DemoBoard::gameOver( )
{
	qDebug("end game");
}

void DemoBoard::regenerateModel( )
{
	m_model->generateMap(25,25);
}



