Commit 74ed21c5 authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Formatted source code

GIT_SILENT
parent cb6fc717
...@@ -33,19 +33,19 @@ QColor ColorScheme::background() const ...@@ -33,19 +33,19 @@ QColor ColorScheme::background() const
{ {
return KStatefulBrush(KColorScheme::Tooltip, return KStatefulBrush(KColorScheme::Tooltip,
KColorScheme::NormalBackground) KColorScheme::NormalBackground)
.brush(QPalette::Active).color(); .brush(QPalette::Active).color();
} }
QColor ColorScheme::foreground() const QColor ColorScheme::foreground() const
{ {
return KStatefulBrush(KColorScheme::Tooltip, return KStatefulBrush(KColorScheme::Tooltip,
KColorScheme::NormalText) KColorScheme::NormalText)
.brush(QPalette::Active).color(); .brush(QPalette::Active).color();
} }
QColor ColorScheme::border() const QColor ColorScheme::border() const
{ {
return KStatefulBrush(KColorScheme::View, return KStatefulBrush(KColorScheme::View,
KColorScheme::NormalText) KColorScheme::NormalText)
.brush(QPalette::Active).color(); .brush(QPalette::Active).color();
} }
...@@ -34,7 +34,8 @@ ChipColor Utils::opponentColorFor(ChipColor color) ...@@ -34,7 +34,8 @@ ChipColor Utils::opponentColorFor(ChipColor color)
} }
QString Utils::colorToString(const ChipColor &color) { QString Utils::colorToString(const ChipColor &color)
{
if (Preferences::useColoredChips()) if (Preferences::useColoredChips())
return (color == Black ? i18n("Blue") : i18n("Red")); return (color == Black ? i18n("Blue") : i18n("Red"));
return (color == Black ? i18n("Black") : i18n("White")); return (color == Black ? i18n("Black") : i18n("White"));
...@@ -54,7 +55,8 @@ QString Utils::moveToString(const KReversiMove& move) ...@@ -54,7 +55,8 @@ QString Utils::moveToString(const KReversiMove& move)
return moveString; return moveString;
} }
int Utils::difficultyLevelToInt() { int Utils::difficultyLevelToInt()
{
for (int i = 0; i < Kg::difficulty()->levels().size(); i++) for (int i = 0; i < Kg::difficulty()->levels().size(); i++)
if (Kg::difficultyLevel() if (Kg::difficultyLevel()
...@@ -64,6 +66,7 @@ int Utils::difficultyLevelToInt() { ...@@ -64,6 +66,7 @@ int Utils::difficultyLevelToInt() {
return -1; return -1;
} }
const KgDifficultyLevel *Utils::intToDifficultyLevel(int skill) { const KgDifficultyLevel *Utils::intToDifficultyLevel(int skill)
{
return Kg::difficulty()->levels()[skill]; return Kg::difficulty()->levels()[skill];
} }
...@@ -60,12 +60,13 @@ struct KReversiMove: public KReversiPos { ...@@ -60,12 +60,13 @@ struct KReversiMove: public KReversiPos {
} }
}; };
namespace Utils { namespace Utils
ChipColor opponentColorFor(ChipColor color); {
QString colorToString(const ChipColor &color); ChipColor opponentColorFor(ChipColor color);
QString moveToString(const KReversiMove& move); QString colorToString(const ChipColor &color);
int difficultyLevelToInt(); QString moveToString(const KReversiMove& move);
const KgDifficultyLevel *intToDifficultyLevel(int skill); int difficultyLevelToInt();
const KgDifficultyLevel *intToDifficultyLevel(int skill);
} }
typedef QList<KReversiMove> MoveList; typedef QList<KReversiMove> MoveList;
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
#include <QString> #include <QString>
class GameStartInformation { class GameStartInformation
{
public: public:
enum PlayerType { enum PlayerType {
......
...@@ -156,7 +156,7 @@ void KReversiMainWindow::loadSettings() ...@@ -156,7 +156,7 @@ void KReversiMainWindow::loadSettings()
// Chip's color // Chip's color
m_coloredChipsAct->setChecked(Preferences::useColoredChips()); m_coloredChipsAct->setChecked(Preferences::useColoredChips());
m_view->setChipsPrefix(Preferences::useColoredChips() ? m_view->setChipsPrefix(Preferences::useColoredChips() ?
KReversiView::Colored : KReversiView::BlackWhite); KReversiView::Colored : KReversiView::BlackWhite);
m_startDialog->setColoredChips(Preferences::useColoredChips()); m_startDialog->setColoredChips(Preferences::useColoredChips());
} }
...@@ -260,29 +260,29 @@ void KReversiMainWindow::slotGameOver() ...@@ -260,29 +260,29 @@ void KReversiMainWindow::slotGameOver()
score.setType(KExtHighscore::Lost); score.setType(KExtHighscore::Lost);
} }
} else if (m_nowPlayingInfo.type[White] == GameStartInformation::Human } else if (m_nowPlayingInfo.type[White] == GameStartInformation::Human
&& m_nowPlayingInfo.type[Black] == GameStartInformation::AI) { // we are playing white && m_nowPlayingInfo.type[Black] == GameStartInformation::AI) { // we are playing white
storeScore = true; storeScore = true;
KExtHighscore::setGameType(((KReversiComputerPlayer *)m_player[Black])->lowestSkill()); KExtHighscore::setGameType(((KReversiComputerPlayer *)m_player[Black])->lowestSkill());
score.setScore(whiteScore); score.setScore(whiteScore);
if (blackScore == whiteScore) { if (blackScore == whiteScore) {
res = i18n("Game is drawn!"); res = i18n("Game is drawn!");
score.setType(KExtHighscore::Draw); score.setType(KExtHighscore::Draw);
} else if (blackScore < whiteScore) { } else if (blackScore < whiteScore) {
res = i18n("You win!"); res = i18n("You win!");
score.setType(KExtHighscore::Won); score.setType(KExtHighscore::Won);
} else { } else {
res = i18n("You have lost!"); res = i18n("You have lost!");
score.setType(KExtHighscore::Lost); score.setType(KExtHighscore::Lost);
} }
} else if (m_nowPlayingInfo.type[Black] == GameStartInformation::Human } else if (m_nowPlayingInfo.type[Black] == GameStartInformation::Human
&& m_nowPlayingInfo.type[White] == GameStartInformation::Human) { // friends match && m_nowPlayingInfo.type[White] == GameStartInformation::Human) { // friends match
if (blackScore == whiteScore) { if (blackScore == whiteScore) {
res = i18n("Game is drawn!"); res = i18n("Game is drawn!");
} else if (blackScore > whiteScore) { } else if (blackScore > whiteScore) {
res = i18n("%1 has won!", m_nowPlayingInfo.name[Black]); res = i18n("%1 has won!", m_nowPlayingInfo.name[Black]);
} else { } else {
res = i18n("%1 has won!", m_nowPlayingInfo.name[White]); res = i18n("%1 has won!", m_nowPlayingInfo.name[White]);
} }
} else { // using Black White names in other cases } else { // using Black White names in other cases
if (blackScore == whiteScore) { if (blackScore == whiteScore) {
...@@ -295,7 +295,7 @@ void KReversiMainWindow::slotGameOver() ...@@ -295,7 +295,7 @@ void KReversiMainWindow::slotGameOver()
} }
if (m_nowPlayingInfo.type[Black] == GameStartInformation::AI if (m_nowPlayingInfo.type[Black] == GameStartInformation::AI
&& m_nowPlayingInfo.type[White] == GameStartInformation::AI) { && m_nowPlayingInfo.type[White] == GameStartInformation::AI) {
res += i18n("\n%1: %2", Utils::colorToString(Black), blackScore); res += i18n("\n%1: %2", Utils::colorToString(Black), blackScore);
res += i18n("\n%1: %2", Utils::colorToString(White), whiteScore); res += i18n("\n%1: %2", Utils::colorToString(White), whiteScore);
} else { } else {
...@@ -318,7 +318,8 @@ void KReversiMainWindow::slotMoveFinished() ...@@ -318,7 +318,8 @@ void KReversiMainWindow::slotMoveFinished()
m_undoAct->setEnabled(m_game->canUndo()); m_undoAct->setEnabled(m_game->canUndo());
} }
void KReversiMainWindow::updateHistory() { void KReversiMainWindow::updateHistory()
{
MoveList history = m_game->getHistory(); MoveList history = m_game->getHistory();
m_historyView->clear(); m_historyView->clear();
...@@ -360,8 +361,7 @@ void KReversiMainWindow::showEvent(QShowEvent*) ...@@ -360,8 +361,7 @@ void KReversiMainWindow::showEvent(QShowEvent*)
if (m_firstShow && m_startInDemoMode) { if (m_firstShow && m_startInDemoMode) {
kDebug() << "starting demo..."; kDebug() << "starting demo...";
startDemo(); startDemo();
} } else if (m_firstShow) {
else if (m_firstShow) {
QTimer::singleShot(0, this, SLOT(slotNewGame())); QTimer::singleShot(0, this, SLOT(slotNewGame()));
} }
m_firstShow = false; m_firstShow = false;
...@@ -384,7 +384,7 @@ void KReversiMainWindow::updateStatusBar() ...@@ -384,7 +384,7 @@ void KReversiMainWindow::updateStatusBar()
if (!m_game->isGameOver()) { if (!m_game->isGameOver()) {
statusBar()->changeItem(i18n("%1 turn", statusBar()->changeItem(i18n("%1 turn",
Utils::colorToString(m_game->currentPlayer())), Utils::colorToString(m_game->currentPlayer())),
COMMON_STATUSBAR_ID); COMMON_STATUSBAR_ID);
} }
} else { // using player's names } else { // using player's names
...@@ -402,7 +402,8 @@ void KReversiMainWindow::updateStatusBar() ...@@ -402,7 +402,8 @@ void KReversiMainWindow::updateStatusBar()
// TODO: test it!!! // TODO: test it!!!
void KReversiMainWindow::startDemo() { void KReversiMainWindow::startDemo()
{
GameStartInformation info; GameStartInformation info;
info.name[0] = info.name[1] = i18n("Computer"); info.name[0] = info.name[1] = i18n("Computer");
info.type[0] = info.type[1] = GameStartInformation::AI; info.type[0] = info.type[1] = GameStartInformation::AI;
...@@ -411,10 +412,10 @@ void KReversiMainWindow::startDemo() { ...@@ -411,10 +412,10 @@ void KReversiMainWindow::startDemo() {
receivedGameStartInformation(info); receivedGameStartInformation(info);
} }
void KReversiMainWindow::clearPlayers() { void KReversiMainWindow::clearPlayers()
{
for (int i = 0; i < 2; i++) // iterating through white to black for (int i = 0; i < 2; i++) // iterating through white to black
if (m_player[i]) if (m_player[i]) {
{
m_player[i]->disconnect(); m_player[i]->disconnect();
delete m_player[i]; delete m_player[i];
m_player[i] = 0; m_player[i] = 0;
...@@ -427,14 +428,11 @@ void KReversiMainWindow::receivedGameStartInformation(GameStartInformation info) ...@@ -427,14 +428,11 @@ void KReversiMainWindow::receivedGameStartInformation(GameStartInformation info)
m_nowPlayingInfo = info; m_nowPlayingInfo = info;
for (int i = 0; i < 2; i++) // iterating through black and white for (int i = 0; i < 2; i++) // iterating through black and white
if (info.type[i] == GameStartInformation::AI) if (info.type[i] == GameStartInformation::AI) {
{
m_player[i] = new KReversiComputerPlayer(ChipColor(i), info.name[i]); m_player[i] = new KReversiComputerPlayer(ChipColor(i), info.name[i]);
((KReversiComputerPlayer *)(m_player[i]))->setSkill(info.skill[i]); ((KReversiComputerPlayer *)(m_player[i]))->setSkill(info.skill[i]);
levelChanged(); levelChanged();
} } else {
else
{
m_player[i] = new KReversiHumanPlayer(ChipColor(i), info.name[i]); m_player[i] = new KReversiHumanPlayer(ChipColor(i), info.name[i]);
} }
...@@ -454,16 +452,14 @@ void KReversiMainWindow::receivedGameStartInformation(GameStartInformation info) ...@@ -454,16 +452,14 @@ void KReversiMainWindow::receivedGameStartInformation(GameStartInformation info)
updateHistory(); updateHistory();
if (info.type[White] == GameStartInformation::AI if (info.type[White] == GameStartInformation::AI
&& info.type[Black] == GameStartInformation::Human) { && info.type[Black] == GameStartInformation::Human) {
Kg::difficulty()->setEditable(true); Kg::difficulty()->setEditable(true);
Kg::difficulty()->select(Utils::intToDifficultyLevel(info.skill[White])); Kg::difficulty()->select(Utils::intToDifficultyLevel(info.skill[White]));
} } else if (info.type[White] == GameStartInformation::Human
else if (info.type[White] == GameStartInformation::Human && info.type[Black] == GameStartInformation::AI) {
&& info.type[Black] == GameStartInformation::AI) {
Kg::difficulty()->setEditable(true); Kg::difficulty()->setEditable(true);
Kg::difficulty()->select(Utils::intToDifficultyLevel(info.skill[Black])); Kg::difficulty()->select(Utils::intToDifficultyLevel(info.skill[Black]));
} } else
else
Kg::difficulty()->setEditable(false); Kg::difficulty()->setEditable(false);
m_hintAct->setEnabled(m_game->isHintAllowed()); m_hintAct->setEnabled(m_game->isHintAllowed());
......
...@@ -42,8 +42,7 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) : ...@@ -42,8 +42,7 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
for (int i = 0; i < diffList.size(); i++) { for (int i = 0; i < diffList.size(); i++) {
ui->blackSkill->addItem(icon, diffList.at(i)->title()); ui->blackSkill->addItem(icon, diffList.at(i)->title());
ui->whiteSkill->addItem(icon, diffList.at(i)->title()); ui->whiteSkill->addItem(icon, diffList.at(i)->title());
if (diffList.at(i)->isDefault()) if (diffList.at(i)->isDefault()) {
{
ui->whiteSkill->setCurrentIndex(i); ui->whiteSkill->setCurrentIndex(i);
ui->blackSkill->setCurrentIndex(i); ui->blackSkill->setCurrentIndex(i);
} }
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
#include <KUser> #include <KUser>
#include <KgThemeProvider> #include <KgThemeProvider>
namespace Ui { namespace Ui
class StartGameDialog; {
class StartGameDialog;
} }
class StartGameDialog : public KDialog class StartGameDialog : public KDialog
......
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