kreversiplayer.h 4.04 KB
Newer Older
Denis Kuplyakov's avatar
Denis Kuplyakov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*******************************************************************
 *
 * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com>
 *
 * This file is part of the KDE project "KReversi"
 *
 * KReversi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * KReversi is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KReversi; see the file COPYING.  If not, write to
 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 ********************************************************************/

Denis Kuplyakov's avatar
Denis Kuplyakov committed
24 25 26
#ifndef KREVERSI_PLAYER_H
#define KREVERSI_PLAYER_H

27
#include "kreversigame.h"
28 29
#include <QString>

Denis Kuplyakov's avatar
Denis Kuplyakov committed
30 31
class KReversiGame;

32 33 34
/**
 * Indicates current state of the player
 */
Denis Kuplyakov's avatar
Denis Kuplyakov committed
35
enum KReversiPlayerState {
36
    /** Player is waiting for his move or smth else */
Denis Kuplyakov's avatar
Denis Kuplyakov committed
37
    WAITING,
38
    /** Player is thinking about his move */
Denis Kuplyakov's avatar
Denis Kuplyakov committed
39
    THINKING,
40
    /** Player state is unknown */
Denis Kuplyakov's avatar
Denis Kuplyakov committed
41 42
    UNKNOWN
};
43 44 45
/**
 * Represents abstract player. It is interface.
 */
Denis Kuplyakov's avatar
Denis Kuplyakov committed
46 47 48 49
class KReversiPlayer: public QObject
{
    Q_OBJECT
public:
50 51 52 53 54
    /**
     * Construct player with specified @p color and @p name.
     * @param hintAllowed determines whether hints are allowed for player
     * @param undoAllowed determines whether undos are allowed for player
     */
Laurent Montel's avatar
Laurent Montel committed
55
    explicit KReversiPlayer(ChipColor color, const QString &name,
Denis Kuplyakov's avatar
Denis Kuplyakov committed
56
                            bool hintAllowed, bool undoAllowed);
Denis Kuplyakov's avatar
Denis Kuplyakov committed
57 58

    /**
59 60
     *  Used to get player color
     *  @return color of player
Denis Kuplyakov's avatar
Denis Kuplyakov committed
61 62 63
     */
    ChipColor getColor() const;

64 65 66 67 68 69
    /**
     *  Used to get player's name
     *  @return player's name
     */
    QString getName() const;

Denis Kuplyakov's avatar
Denis Kuplyakov committed
70 71 72 73 74 75 76 77 78 79 80
    /**
     *  @return is hint allowed for player or not
     */
    bool isHintAllowed() const;

    /**
     *  KReversiGame triggers it to to increase used hints count
     */
    void hintUsed();

    /**
Denis Kuplyakov's avatar
Denis Kuplyakov committed
81
     *  @return how many times player has used hints
Denis Kuplyakov's avatar
Denis Kuplyakov committed
82 83 84
     */
    int getHintsCount();

Denis Kuplyakov's avatar
Denis Kuplyakov committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    /**
     *  @return is undo allowed for player
     */
    bool isUndoAllowed() const;

    /**
     *  KReversiGame triggers it to to increase used undos count
     */
    void undoUsed();

    /**
     *  @return how many times player has used undo
     */
    int getUndoCount();

100
public Q_SLOTS:
Denis Kuplyakov's avatar
Denis Kuplyakov committed
101 102
    /**
     *  Triggered by KReversiGame before game starts
103
     *  Implementation should assign @p game to m_game
Denis Kuplyakov's avatar
Denis Kuplyakov committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
     */
    virtual void prepare(KReversiGame* game) = 0;

    /**
     *  It triggered from KReversiGame.
     *  Means that player should start think about his move.
     */
    virtual void takeTurn() = 0;

    /**
     *  It triggered from KReversiGame.
     *  Means that player can't do move and skips it.
     */
    virtual void skipTurn() = 0;

    /**
     *  Triggered by KReversiGame to notify player that game is over.
     */
    virtual void gameOver() = 0;

124
Q_SIGNALS:
Denis Kuplyakov's avatar
Denis Kuplyakov committed
125 126 127 128 129
    /**
     *  Player emit it when want to notify about his move
     */
    void makeMove(KReversiMove);

130 131 132 133 134
    /**
     * Player emit it after he has prepared after getting prepare command
     */
    void ready();

Denis Kuplyakov's avatar
Denis Kuplyakov committed
135 136
protected:
    /**
137
     *  Game which player is playing
Denis Kuplyakov's avatar
Denis Kuplyakov committed
138 139 140 141 142 143 144 145 146 147 148 149
     */
    KReversiGame *m_game;

    /**
     *  Is player thinking or waiting
     */
    KReversiPlayerState m_state;

    /**
     *  Player's chip color
     */
    ChipColor m_color;
150 151 152 153 154

    /**
     *  Player's name to be shown at UI
     */
    QString m_name;
Denis Kuplyakov's avatar
Denis Kuplyakov committed
155 156 157 158 159 160 161 162 163 164

    /**
     *  Are hints enabled for player
     */
    bool m_hintAllowed;

    /**
     *  How many times player has used hint
     */
    int m_hintCount;
Denis Kuplyakov's avatar
Denis Kuplyakov committed
165 166 167 168 169 170 171 172 173 174

    /**
     *  Can player request undo or not
     */
    bool m_undoAllowed;

    /**
     *  How many times player has used undo
     */
    int m_undoCount;
Denis Kuplyakov's avatar
Denis Kuplyakov committed
175 176 177
};

#endif // KREVERSIPLAYER_H