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

Added name property to KReversiPlayer class

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