Commit 697f7a0b authored by Matt Williams's avatar Matt Williams
Browse files

Add UI for starting a game against the computer. There's no AI yet though,

svn path=/trunk/playground/games/ksquares/; revision=616228
parent e6e971d3
......@@ -14,7 +14,7 @@ set(ksquares_SRCS
kde4_automoc(${ksquares_SRCS})
kde4_add_ui_files(ksquares_SRCS newgamedialog.ui scoresdialog.ui prefs_base.ui)
kde4_add_ui_files(ksquares_SRCS newgamedialog.ui scoresdialog.ui prefs_base.ui prefs_ai.ui)
kde4_add_kcfg_files(ksquares_SRCS GENERATE_MOC settings.kcfgc) #GENERATE_MOC is not needed but it doesn't work without it for some reason :S
......
......@@ -68,6 +68,14 @@ void KSquares::fileNew()
dialog.playerTwoName->setText(Settings::playerNames().at(1));
dialog.spinHeight->setValue(Settings::boardHeight());
dialog.spinWidth->setValue(Settings::boardWidth());
if (Settings::humanList().at(0) == 2)
dialog.playerOneHuman->setCheckState(Qt::Checked);
else
dialog.playerOneHuman->setCheckState(Qt::Unchecked);
if (Settings::humanList().at(1) == 2)
dialog.playerTwoHuman->setCheckState(Qt::Checked);
else
dialog.playerTwoHuman->setCheckState(Qt::Unchecked);
//run dialog
dialog.exec();
......@@ -80,14 +88,35 @@ void KSquares::fileNew()
tempNames.append(dialog.playerTwoName->text());
Settings::setPlayerNames(tempNames);
QList<int> tempHuman;
tempHuman.append(dialog.playerOneHuman->checkState());
tempHuman.append(dialog.playerTwoHuman->checkState());
Settings::setHumanList(tempHuman);
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));
switch(dialog.playerOneHuman->checkState())
{
case 0:
playerList.append(KSquaresPlayer(dialog.playerOneName->text(), false));
break;
case 2:
playerList.append(KSquaresPlayer(dialog.playerOneName->text(), true));
break;
}
switch(dialog.playerTwoHuman->checkState())
{
case 0:
playerList.append(KSquaresPlayer(dialog.playerTwoName->text(), false));
break;
case 2:
playerList.append(KSquaresPlayer(dialog.playerTwoName->text(), true));
break;
}
//create phsical board
m_view->createBoard(Settings::boardWidth(), Settings::boardHeight());
......@@ -114,7 +143,7 @@ void KSquares::gameOver(QVector<KSquaresPlayer> playerList)
for(int i = 0; i < playerList.size(); i++)
{
scoreTableModel->setItem(i, 0, new QStandardItem(Settings::playerNames().at(i)));
scoreTableModel->setItem(i, 0, new QStandardItem(playerList.at(i).name()));
QString temp;
temp.setNum(playerList.at(i).score());
......@@ -129,9 +158,9 @@ void KSquares::gameOver(QVector<KSquaresPlayer> playerList)
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"), "prefs_base");
QWidget *aiSettingsDlg = new QWidget;
ui_prefs_ai.setupUi(aiSettingsDlg);
dialog->addPage(aiSettingsDlg, i18n("AI"), "ksquares_ai");
//connect(dialog, SIGNAL(settingsChanged(const QString &)), m_view, SLOT(settingsChanged()));
dialog->show();
......
......@@ -20,6 +20,7 @@
#include "gameboardview.h"
#include "ksquaresgame.h"
#include "ui_prefs_base.h"
#include "ui_prefs_ai.h"
class KToggleAction;
......@@ -41,6 +42,7 @@ class KSquares : public KMainWindow
void setupAccel();
void setupActions();
Ui::prefs_base ui_prefs_base;
Ui::prefs_ai ui_prefs_ai;
GameBoardView *m_view;
KSquaresGame* sGame;
......
......@@ -3,7 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="ksquaresrc"/>
<kcfgfile name="ksquaresrc"/>
<group name="Game Settings">
<entry name="NumOfPlayers" type="Int">
<label>Number of Players</label>
......@@ -13,6 +14,10 @@ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<label>Player Names</label>
<default>Player 1,Player 2</default>
</entry>
<entry name="HumanList" type="IntList">
<label>Human or AI</label>
<default>1,1</default>
</entry>
<entry name="BoardWidth" type="Int">
<label>Width of board</label>
<default>10</default>
......@@ -22,4 +27,11 @@ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<default>7</default>
</entry>
</group>
<group name="AI">
<entry name="Difficulty" type="Int">
<label>Difficulty</label>
<whatsthis>How difficult the AI should be</whatsthis>
<default>0</default>
</entry>
</group>
</kcfg>
......@@ -37,7 +37,7 @@ class KSquaresGame : public QObject
protected:
int numOfPlayers;
int currentPlayerId; // from 0 to n; -1 is null player
int currentPlayerId; // from 0 to (n-1); -1 is null player
QVector<int> points;
bool anotherGo;
int width;
......
......@@ -5,7 +5,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>269</width>
<width>368</width>
<height>211</height>
</rect>
</property>
......@@ -30,32 +30,22 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<widget class="QLabel" name="labelPLayer1Name" >
<item row="2" column="0" >
<widget class="QLabel" name="labelPLayer2Name" >
<property name="whatsThis" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The name of the first player&lt;/p>&lt;/body>&lt;/html></string>
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Sans;">The name of the second player&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="text" >
<string>Player 1:</string>
<string>Player 2:</string>
</property>
<property name="buddy" >
<cstring>playerTwoName</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QSpinBox" name="spinWidth" >
<property name="minimum" >
<number>1</number>
</property>
<property name="value" >
<number>10</number>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="labelHeight" >
<property name="whatsThis" >
......@@ -72,22 +62,35 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="playerOneName" />
<item row="0" column="0" >
<widget class="QLabel" name="numOfPlayersLabel" >
<property name="text" >
<string>Number of players</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="playerTwoName" />
</item>
<item row="4" column="1" >
<widget class="QSpinBox" name="spinHeight" >
<property name="minimum" >
<number>1</number>
<item row="1" column="0" >
<widget class="QLabel" name="labelPLayer1Name" >
<property name="whatsThis" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The name of the first player&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="value" >
<number>10</number>
<property name="text" >
<string>Player 1:</string>
</property>
<property name="buddy" >
<cstring>playerTwoName</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="playerOneName" />
</item>
<item row="3" column="0" >
<widget class="QLabel" name="labelWidth" >
<property name="whatsThis" >
......@@ -104,31 +107,31 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="labelPLayer2Name" >
<property name="whatsThis" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Sans;">The name of the second player&lt;/p>&lt;/body>&lt;/html></string>
</property>
<item row="1" column="2" >
<widget class="QCheckBox" name="playerOneHuman" >
<property name="text" >
<string>Player 2:</string>
<string>Human?</string>
</property>
<property name="buddy" >
<cstring>playerTwoName</cstring>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="numOfPlayersLabel" >
<item row="2" column="2" >
<widget class="QCheckBox" name="playerTwoHuman" >
<property name="text" >
<string>Number of players</string>
<string>Human?</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" >
<item row="0" column="1" colspan="2" >
<widget class="QSpinBox" name="spinNumOfPlayers" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="maximum" >
<number>5</number>
</property>
......@@ -137,6 +140,26 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="3" column="1" colspan="2" >
<widget class="QSpinBox" name="spinWidth" >
<property name="minimum" >
<number>1</number>
</property>
<property name="value" >
<number>10</number>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2" >
<widget class="QSpinBox" name="spinHeight" >
<property name="minimum" >
<number>1</number>
</property>
<property name="value" >
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" >
......
<ui version="4.0" >
<class>prefs_ai</class>
<widget class="QWidget" name="prefs_ai" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>AI Settings</string>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="KComboBox" name="kcfg_Difficulty" >
<item>
<property name="text" >
<string>Easy</string>
</property>
</item>
<item>
<property name="text" >
<string>Medium</string>
</property>
</item>
<item>
<property name="text" >
<string>Hard</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="label_difficulty" >
<property name="toolTip" >
<string comment="How challenging the AI should be" />
</property>
<property name="text" >
<string>AI Difficulty</string>
</property>
<property name="buddy" >
<cstring>kcfg_Difficulty</cstring>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -2,4 +2,4 @@
File=ksquares.kcfg
ClassName=Settings
Singleton=true
Mutators=PlayerNames,BoardWidth,BoardHeight,NumOfPlayers
Mutators=PlayerNames,BoardWidth,BoardHeight,NumOfPlayers, Difficulty, HumanList
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