Commit e6e971d3 authored by Matt Williams's avatar Matt Williams
Browse files

QVector of players resets properly between games

Adding temporary icons

svn path=/trunk/playground/games/ksquares/; revision=616212
parent 294fd36a
......@@ -30,3 +30,4 @@ install(TARGETS ksquares DESTINATION ${BIN_INSTALL_DIR})
install( FILES ksquares.desktop DESTINATION ${XDG_APPS_DIR} )
install( FILES ksquares.kcfg DESTINATION ${KCFG_INSTALL_DIR} )
install( FILES ksquaresui.rc DESTINATION ${DATA_INSTALL_DIR}/ksquares )
kde4_install_icons(${ICON_INSTALL_DIR})
......@@ -173,7 +173,7 @@ void GameBoardScene::checkForNewSquares()
//cout << index1 << ", " << index2 << ", " << index3 << ", " << index4 << " - " << lineDrawn.size() << endl;
if (lineDrawn.at(index1) and lineDrawn.at(index2) and lineDrawn.at(index3) and lineDrawn.at(index4))
{
kdDebug() << "Square " << i << " completed." << endl;
//kdDebug() << "Square " << i << " completed." << endl;
emit squareComplete(i);
}
}
......@@ -183,7 +183,7 @@ void GameBoardScene::checkForNewSquares()
void GameBoardScene::setSquareOwner(int squareIndex, int owner)
{
kdDebug() << "Square " << squareIndex << " owned by player " << owner << "." << endl;
//kdDebug() << "Square " << squareIndex << " owned by player " << owner << "." << endl;
squareOwnerTable[squareIndex] = owner;
drawSquare(squareIndex);
}
......
......@@ -20,8 +20,11 @@ GameBoardView::GameBoardView(QWidget *parent) : QGraphicsView(parent)
void GameBoardView::createBoard(int height, int width)
{
/*if (gameScene)
delete gameScene;*/
if (gameScene)
{
//delete gameScene;
gameScene = 0;
}
if ((height == 1) and (width == 1))
return;
gameScene = new GameBoardScene(height, width, this);
......
......@@ -23,22 +23,24 @@ using std::endl;
#include <kstdaccel.h>
#include <kaction.h>
#include <kstandardaction.h>
#include "gameboardscene.h"
#include <kdebug.h>
#include "gameboardscene.h"
#include "newgamedialog.h"
#include "scoresdialog.h"
KSquares::KSquares() : KMainWindow(), m_view(new GameBoardView(this))
{
kdDebug() << "4" << endl;
sGame = new KSquaresGame();
//connect(m_view, SIGNAL(gameStarted()), sGame, SLOT(startGame()));
connect(sGame, SIGNAL(playerChangedSig(int)), this, SLOT(playerChanged(int)));
setCentralWidget(m_view);
setupActions();
statusBar()->insertPermanentItem("Player: ", 0);
statusBar()->insertPermanentItem("Current Player", 0);
statusBar()->show();
setAutoSaveSettings();
//fileNew(); //uncomment to start a new game on startup
}
KSquares::~KSquares()
......@@ -52,8 +54,8 @@ void KSquares::setupActions()
KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
// custom menu and menu item - the slot is in the class KSquaresView
KAction *custom = new KAction(i18n("Swi&tch Colors"), actionCollection(), "switch_action");
custom->setIcon(KIcon("colorize"));
//KAction *custom = new KAction(i18n("Swi&tch Colors"), actionCollection(), "switch_action");
//custom->setIcon(KIcon("colorize"));
setupGUI();
}
......@@ -78,20 +80,19 @@ void KSquares::fileNew()
tempNames.append(dialog.playerTwoName->text());
Settings::setPlayerNames(tempNames);
//Settings::setPlayerOneName(dialog.playerOneName->text());
//Settings::setPlayerTwoName(dialog.playerTwoName->text());
Settings::setBoardHeight(dialog.spinHeight->value());
Settings::setBoardWidth(dialog.spinWidth->value());
Settings::writeConfig();
//create players
QVector<KSquaresPlayer> playerList;
playerList.append(KSquaresPlayer(dialog.playerOneName->text(), true));
playerList.append(KSquaresPlayer(dialog.playerTwoName->text(), true));
//create phsical board
m_view->createBoard(Settings::boardWidth(), Settings::boardHeight());
//start game etc.
//sGame->createGame(dialog.spinNumOfPlayers->value(), Settings::boardWidth(), Settings::boardHeight());
sGame->createGame(playerList, Settings::boardWidth(), Settings::boardHeight());
sGame->startGame();
......@@ -130,15 +131,14 @@ void KSquares::optionsPreferences()
KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
QWidget *generalSettingsDlg = new QWidget;
ui_prefs_base.setupUi(generalSettingsDlg);
dialog->addPage(generalSettingsDlg, i18n("General"), "package_setting");
//dialog->addPage(generalSettingsDlg, i18n("General"), "prefs_base");
//connect(dialog, SIGNAL(settingsChanged(const QString &)), m_view, SLOT(settingsChanged()));
dialog->show();
}
void KSquares::playerChanged(int playerNumber)
{
//QString temp;
//temp.setNum(playerNumber);
statusBar()->changeItem(Settings::playerNames().at(playerNumber), 0);
}
......
......@@ -6,5 +6,5 @@ Icon=ksquares
Type=Application
DocPath=ksquares/ksquares.html
GenericName=Connect the dots to create squares
Terminal=0
Categories=Qt;KDE;Game;
Terminal=false
Categories=Qt;KDE;Game;ArcadeGame;
......@@ -25,18 +25,9 @@ KSquaresGame::~KSquaresGame()
kdDebug() << "Destroying game" << endl;
}
/*void KSquaresGame::createGame(uint players, int startWidth, int startHeight)
{
kdDebug() << "Creating Game with " << players << " player(s)" << endl;
width = startWidth;
height = startHeight;
currentPlayerId = 0;
points.resize(0);
points.fill(0, players);
}*/
void KSquaresGame::createGame(QVector<KSquaresPlayer> startPlayers, int startWidth, int startHeight)
{
endGame(); //reset everything
kdDebug() << "Creating Game with " << startPlayers.size() << " player(s)" << endl;
width = startWidth;
height = startHeight;
......@@ -57,9 +48,9 @@ void KSquaresGame::startGame()
int KSquaresGame::nextPlayer()
{
anotherGo = false; //just ro reset the variable
anotherGo = false; //just to reset the variable
currentPlayerId >= (players.size()-1) ? currentPlayerId = 0 : currentPlayerId++;
kdDebug() << "- Moving to next player: player " << currentPlayer() << endl;
kdDebug() << "- Moving to next player: " << players.at(currentPlayer()).name() << "(" << currentPlayer() << ")" << endl;
emit playerChangedSig(currentPlayer());
return currentPlayer();
......@@ -67,7 +58,7 @@ int KSquaresGame::nextPlayer()
void KSquaresGame::playerSquareComplete(int index)
{
kdDebug() << "- - Player " << currentPlayer() << " has completed a square" << endl;
kdDebug() << "- - " << players[currentPlayer()].name() << "(" << currentPlayer() << ") has completed a square" << endl;
anotherGo = true;
emit setSquareOwnerSig(index, currentPlayer());
//points[currentPlayer()-1]++;
......@@ -83,7 +74,7 @@ void KSquaresGame::playerSquareComplete(int index)
{
kdDebug() << "Game Over" << endl;
emit gameOverSig(players);
endGame();
//endGame();
}
}
......@@ -107,10 +98,10 @@ void KSquaresGame::endGame()
{
kdDebug() << "Game Values Resetting" << endl;
numOfPlayers = 0;
players.resize(0);
width = 0;
height = 0;
currentPlayerId = -1;
//points.resize(0);
anotherGo = false;
}
......
......@@ -15,14 +15,16 @@
class KSquaresPlayer
{
public:
KSquaresPlayer(QString newName = "Player", bool isPlayerHuman = true) {human = isPlayerHuman; playerScore = 0; playerName = newName;} //defaults to human player
//KSquaresPlayer(QString newName, bool isPlayerHuman = true) {human = isPlayerHuman; playerScore = 0; playerName = newName;}
KSquaresPlayer(const KSquaresPlayer& ksp) {human = ksp.isHuman(); playerScore = ksp.score();} //copy constructor
KSquaresPlayer(QString newName = "Player", bool isPlayerHuman = true) {setName(newName); human = isPlayerHuman; playerScore = 0;} //defaults to human player
KSquaresPlayer(const KSquaresPlayer& ksp) {human = ksp.isHuman(); playerScore = ksp.score(); setName(ksp.name());} //copy constructor
void setName(QString newName) {playerName = newName;}
QString name() {return playerName;}
QString name() const {return playerName;}
void setScore(int newScore) {playerScore = newScore;}
int score() const {return playerScore;}
void incScore() {playerScore++;}
bool isHuman() const {return human;}
private:
......
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="KSquares" version="1">
<!--
<MenuBar>
<Menu name="move"><text>&amp;Move</text>
<Action name="switch_action" />
</Menu>
<Menu name="move"><text>&amp;Move</text>
<Action name="switch_action" />
</Menu>
</MenuBar>
-->
</kpartgui>
......@@ -18,54 +18,50 @@
static const char description[] =
I18N_NOOP("Draw lines to make squares");
static const char version[] = "0.0.1";
static const char version[] = "0.1.1";
static KCmdLineOptions options[] =
{
{ "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
{ "+[URL]", I18N_NOOP( "Document to open" ), 0 },
KCmdLineLastOption
};
int main(int argc, char **argv)
{
kdDebug() << "1" << endl;
KAboutData about("ksquares", I18N_NOOP("KSquares"), version, description,
KAboutData::License_GPL, "(C) 2006 Matt Williams}", 0, 0, "matt@milliams.com");
about.addAuthor( "Matt Williams", 0, "matt@milliams.com" );
KCmdLineArgs::init(argc, argv, &about);
KCmdLineArgs::addCmdLineOptions(options);
kdDebug() << "2" << endl;
KApplication app;
kdDebug() << "3" << endl;
KSquares *widget = new KSquares;
// see if we are starting with session management
if (app.isSessionRestored())
{
RESTORE(KSquares);
}
else
{
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() == 0)
{
//ksquares *widget = new ksquares;
widget->show();
}
else
{
int i = 0;
for (; i < args->count(); i++)
{
//ksquares *widget = new ksquares;
widget->show();
}
}
args->clear();
}
return app.exec();
KSquares *widget = new KSquares;
// see if we are starting with session management
if (app.isSessionRestored())
{
RESTORE(KSquares);
}
else
{
// no session.. just start up normally
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (args->count() == 0)
{
//ksquares *widget = new ksquares;
widget->show();
}
else
{
int i = 0;
for (; i < args->count(); i++)
{
//ksquares *widget = new ksquares;
widget->show();
}
}
args->clear();
}
return app.exec();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment