Commit 659c9c04 authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Added name property to KReversiPlayer class

Added property field and needed APIs.
Also fixed memory leak.
parent dea7daa5
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "kreversicomputerplayer.h" #include "kreversicomputerplayer.h"
KReversiComputerPlayer::KReversiComputerPlayer(ChipColor color): KReversiComputerPlayer::KReversiComputerPlayer(ChipColor color, QString name):
KReversiPlayer(color) KReversiPlayer(color, name)
{ {
m_engine = new Engine(1); m_engine = new Engine(1);
} }
......
...@@ -31,7 +31,7 @@ class KReversiComputerPlayer : public KReversiPlayer ...@@ -31,7 +31,7 @@ class KReversiComputerPlayer : public KReversiPlayer
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit KReversiComputerPlayer(ChipColor color); explicit KReversiComputerPlayer(ChipColor color, QString name);
~KReversiComputerPlayer(); ~KReversiComputerPlayer();
/** /**
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "kreversihumanplayer.h" #include "kreversihumanplayer.h"
KReversiHumanPlayer::KReversiHumanPlayer(ChipColor color): KReversiHumanPlayer::KReversiHumanPlayer(ChipColor color, QString name):
KReversiPlayer(color) KReversiPlayer(color, name)
{ {
} }
......
...@@ -31,7 +31,7 @@ class KReversiHumanPlayer : public KReversiPlayer ...@@ -31,7 +31,7 @@ class KReversiHumanPlayer : public KReversiPlayer
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit KReversiHumanPlayer(ChipColor color); explicit KReversiHumanPlayer(ChipColor color, QString name);
/** /**
* Overriden slots from @see KReversiPlayer * Overriden slots from @see KReversiPlayer
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "kreversiplayer.h" #include "kreversiplayer.h"
KReversiPlayer::KReversiPlayer(ChipColor color): KReversiPlayer::KReversiPlayer(ChipColor color, QString name):
m_state(UNKNOWN), m_color(color) m_state(UNKNOWN), m_color(color), m_name(name)
{ {
} }
...@@ -32,3 +32,8 @@ ChipColor KReversiPlayer::getColor() const ...@@ -32,3 +32,8 @@ ChipColor KReversiPlayer::getColor() const
{ {
return m_color; return m_color;
} }
QString KReversiPlayer::getName() const
{
return m_name;
}
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#define KREVERSI_PLAYER_H #define KREVERSI_PLAYER_H
#include "kreversigame.h" #include "kreversigame.h"
#include <QString>
class KReversiGame; class KReversiGame;
enum KReversiPlayerState { enum KReversiPlayerState {
...@@ -37,14 +39,20 @@ class KReversiPlayer: public QObject ...@@ -37,14 +39,20 @@ class KReversiPlayer: public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit KReversiPlayer(ChipColor color); explicit KReversiPlayer(ChipColor color, QString name);
/** /**
* Used to get player color * Used to get player color
* @return color of player * @return color of player
*/ */
ChipColor getColor() const; ChipColor getColor() const;
/**
* Used to get player's name
* @return player's name
*/
QString getName() const;
public slots: public slots:
/** /**
* Triggered by KReversiGame before game starts * Triggered by KReversiGame before game starts
...@@ -94,6 +102,11 @@ protected: ...@@ -94,6 +102,11 @@ protected:
* Player's chip color * Player's chip color
*/ */
ChipColor m_color; ChipColor m_color;
/**
* Player's name to be shown at UI
*/
QString m_name;
}; };
#endif // KREVERSIPLAYER_H #endif // KREVERSIPLAYER_H
...@@ -227,10 +227,10 @@ void KReversiMainWindow::slotNewGame() ...@@ -227,10 +227,10 @@ void KReversiMainWindow::slotNewGame()
if (m_historyView) if (m_historyView)
m_historyView->clear(); m_historyView->clear();
human = new KReversiHumanPlayer(Black); human = new KReversiHumanPlayer(White, "Player");
computer = new KReversiComputerPlayer(White); computer = new KReversiComputerPlayer(Black, "Computer");
/// TODO: DELETE HUMAN AND COMPUTER /// TODO: DELETE HUMAN AND COMPUTER
m_game = new KReversiGame(human, computer); m_game = new KReversiGame(computer, human);
levelChanged(); levelChanged();
connect(m_game, SIGNAL(gameOver()), SLOT(slotGameOver())); connect(m_game, SIGNAL(gameOver()), SLOT(slotGameOver()));
m_game->setDelay(300); m_game->setDelay(300);
...@@ -253,6 +253,8 @@ void KReversiMainWindow::slotNewGame() ...@@ -253,6 +253,8 @@ void KReversiMainWindow::slotNewGame()
void KReversiMainWindow::slotGameOver() void KReversiMainWindow::slotGameOver()
{ {
delete human;
delete computer;
m_hintAct->setEnabled(false); m_hintAct->setEnabled(false);
//TODO: only if it is not computer-computer match //TODO: only if it is not computer-computer match
......
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