[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-games-devel
Subject: [Kde-games-devel] Patch for KBattleShip
From: "Albert 'TSDgeos' Astals Cid" <tsdgeos () terra ! es>
Date: 2003-05-28 16:47:18
[Download RAW message or body]
The patch removes the need for these files
kbattleship/ksingledialog.cpp
kbattleship/ksingledialog.h
kbattleship/dialogs/singleDlg.ui
as the dialog created with this files can be obtained using
KLineEditDlg::getText and i think is better to use that than 2 more classes.
Also changes some
QTimer::singleShot(0, this, SLOT(slotDeleteClient()));
to
slotDeleteClient();
as i think the effect is the same and we don't need a timer for that.
And finally change
if(m_aiPlaying) m_aiPlayer->slotRequestShot();
of position and get it lower in the code as in the position it was, it was
calling the AI player movement before checking if the player was winning with
that movement.
Also some functions (now that i've removed the QTimer thing) don't need to be
slots, i haven't renamed them nor changed them from private slots to private
in the .h
Should i?
If the patch is merged, i suppose the non needed files should be removed from
makefile.am or something like that, but i hace touched that as i am not very
familiar with automake/autoconf files
The patch comes attached
Comments are welcome :-)
["MY_DIFF" (text/x-diff)]
? MY_DIFF
Index: kbattleship.cpp
===================================================================
RCS file: /home/kde/kdegames/kbattleship/kbattleship/kbattleship.cpp,v
retrieving revision 1.131
diff -u -r1.131 kbattleship.cpp
--- kbattleship.cpp 13 May 2003 14:59:24 -0000 1.131
+++ kbattleship.cpp 28 May 2003 16:28:08 -0000
@@ -25,6 +25,9 @@
#include "kbattleship.moc"
#include <kkeydialog.h>
+
+#include <klineeditdlg.h>
+
KBattleshipApp::KBattleshipApp()
{
setMinimumSize(750, 500);
@@ -33,7 +36,6 @@
m_config = 0;
m_client = 0;
m_server = 0;
- m_single = 0;
m_aiPlayer = 0;
m_aiHits = 0;
@@ -203,9 +205,6 @@
{
m_stat->setShot();
- if(m_aiPlayer != 0)
- m_aiPlayer->slotRequestShot();
-
int showstate;
if(m_enemyshiplist->shipTypeAt(fieldx, fieldy) == 99)
@@ -341,15 +340,17 @@
switch(KMessageBox::questionYesNo(this, i18n("Do you want to restart the game?")))
{
case KMessageBox::Yes:
- QTimer::singleShot(0, this, SLOT(slotRestartAI()));
+ slotRestartAI();
break;
case KMessageBox::No:
- QTimer::singleShot(0, this, SLOT(slotDeleteAI()));
+ slotDeleteAI();
break;
}
return;
}
+
+ if(m_aiPlaying) m_aiPlayer->slotRequestShot();
}
}
}
@@ -442,7 +443,7 @@
m_kbserver = 0;
}
else
- QTimer::singleShot(0, this, SLOT(slotDeleteClient()));
+ slotDeleteClient();
delete m_connection;
m_connection = 0;
@@ -1112,17 +1113,14 @@
void KBattleshipApp::slotSinglePlayer()
{
+ bool ok;
if(!m_aiPlaying)
{
- if(m_single != 0)
- return;
-
slotStatusMsg(i18n("Loading Single-Game dialog..."));
- m_single = new KSingleDialog();
- connect(m_single, SIGNAL(sigStartGame()), this, SLOT(slotStartBattleshipGame()));
- connect(m_single, SIGNAL(sigCancelGame()), this, SLOT(slotDeleteSingleDialog()));
- m_single->show();
+ m_ownNickname = KLineEditDlg::getText( i18n( "Start Game" ) , i18n( "Nick name:" ),
+ QString::fromLocal8Bit(getenv("LOGNAME")), &ok, this);
+ if (ok) slotStartBattleshipGame(true);
slotStatusMsg(i18n("Ready"));
}
@@ -1139,36 +1137,19 @@
slotStatusMsg(i18n("Ready"));
m_stat->clear();
m_chat->clear();
- QTimer::singleShot(0, this, SLOT(slotDeleteAI()));
+ slotDeleteAI();
cleanup(false);
}
}
}
-void KBattleshipApp::slotDeleteSingleDialog()
-{
- delete m_single;
- m_single = 0;
-}
-
-
-void KBattleshipApp::slotStartBattleshipGame()
-{
- slotStartBattleshipGame(true);
-}
-
void KBattleshipApp::slotStartBattleshipGame(bool clearstat)
{
+ m_shootable = false;
m_gameSingle->setText(i18n("&Stop game"));
m_gameNewServer->setEnabled(false);
m_gameServerConnect->setEnabled(false);
slotStatusMsg(i18n("Waiting for the AI player to place the ships..."));
- if(m_single != 0)
- {
- m_ownNickname = m_single->nickname();
- delete m_single;
- m_single = 0;
- }
slotChangeOwnPlayer(m_ownNickname);
slotChangeEnemyPlayer(KGameMisc::randomName());
cleanup(true);
@@ -1178,7 +1159,6 @@
m_connection = 0;
}
m_aiPlaying = true;
- m_shootable = false;
m_stat->clear();
if(clearstat)
m_stat->clearWon();
@@ -1237,11 +1217,11 @@
switch(KMessageBox::questionYesNo(this, i18n("Do you want to restart the game?")))
{
case KMessageBox::Yes:
- QTimer::singleShot(0, this, SLOT(slotRestartAI()));
+ slotRestartAI();
break;
case KMessageBox::No:
- QTimer::singleShot(0, this, SLOT(slotDeleteAI()));
+ slotDeleteAI();
break;
}
}
Index: kbattleship.h
===================================================================
RCS file: /home/kde/kdegames/kbattleship/kbattleship/kbattleship.h,v
retrieving revision 1.66
diff -u -r1.66 kbattleship.h
--- kbattleship.h 13 May 2003 14:59:24 -0000 1.66
+++ kbattleship.h 28 May 2003 16:28:08 -0000
@@ -89,7 +89,6 @@
void slotRestartAI();
void slotDeleteClient();
void slotSinglePlayer();
- void slotDeleteSingleDialog();
void slotServerConnect();
void slotDeleteConnectDialog();
void slotNewServer();
@@ -97,7 +96,6 @@
void slotHighscore();
void slotConfigSound();
void slotShowGrid();
- void slotStartBattleshipGame();
void slotStartBattleshipGame(bool clearstat);
void slotStartBattleshipServer();
void slotConnectToBattleshipServer();
@@ -155,7 +153,6 @@
KToggleAction *m_configSound;
KToggleAction *m_configGrid;
KBattleshipSound *m_sound;
- KSingleDialog *m_single;
KClientDialog *m_client;
KServerDialog *m_server;
KHighscoreDialog *m_score;
_______________________________________________
kde-games-devel mailing list
kde-games-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-games-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic