summaryrefslogtreecommitdiffstats
path: root/kreversi/kreversi.h
blob: 17599fa261ecea6071cc546a49dd9de521764134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* Yo Emacs, this -*- C++ -*-
 *******************************************************************
 *******************************************************************
 *
 *
 * KREVERSI
 *
 *
 *******************************************************************
 *
 * A Reversi (or sometimes called Othello) game
 *
 *******************************************************************
 *
 * created 1997 by Mario Weilguni <mweilguni@sime.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.
 *
 *******************************************************************
 */


#ifndef KREVERSI_H
#define KREVERSI_H


#include "kzoommainwindow.h"

#include "Score.h"
#include "Game.h"
#include "Engine.h"
//#include "board.h"
#include "qreversigame.h"
#include "qreversigameview.h"


class QLabel;

class KAction;


class KReversi : public KZoomMainWindow 
{
  Q_OBJECT

public:

  enum State { Ready, Thinking, Hint};

  KReversi();
  ~KReversi();
  
  bool isPlaying() const;

  // Methods that deal with the game
  Color  toMove() const           { return m_game->toMove();       }
  Color  humanColor() const       { return m_humanColor;           }
  Color  computerColor() const    { return opponent(m_humanColor); }

  // Methods that deal with the engine.
  void   setStrength(uint);
  uint   strength() const         { return m_engine->strength();   }
  void   interrupt()              { m_engine->setInterrupt(TRUE);  }
  bool   interrupted() const      { return (m_game->toMove() == computerColor()
					    && m_state == Ready);  }

  // State of the program (Hint, Ready, Thinking, etc).
  void     setState(State);
  State    state() const          { return m_state;                }

private:
  // Initialisation
  void     createKActions();

  // View functions.
  QString  getPlayerName();

  virtual void  writeZoomSetting(uint zoom);
  virtual uint  readZoomSetting() const;
  virtual void  writeMenubarVisibleSetting(bool visible);
  virtual bool  menubarVisibleSetting() const;

  virtual void  saveProperties(KConfig *);
  virtual void  readProperties(KConfig *);
  virtual bool  queryExit();


private slots:

  // Slots for KActions.
  void  slotNewGame();
  void  slotOpenGame();
  void  slotSave();
  void  slotHint();
  void  slotUndo();
  void  slotSwitchSides();

  // Interrupt and continue the engines thinking (also KActions).
  void  slotInterrupt();
  void  slotContinue();
  void  slotShowLastMove();
  void  slotShowLegalMoves();

  // Slots for game IO
  void  slotSquareClicked(int, int);

  // Misc slots.
  void  configureNotifications();

  // Some dialogs and other misc stuff.
  void  showHighScoreDialog();
  void  slotEditSettings();
  void  loadSettings();

 public slots: 
  // Slots for the view.
  void  handleMove(uint moveno, Move &move);
  void  showTurn();
  void  showTurn(Color color);
  void  slotGameOver();

private:

  // Private methods
  void  humanMakeMove(int row, int col);
  void  computerMakeMove();
  void  illegalMove();
  void  showGameOver(Color);

  void  saveGame(KConfig *);
  bool  loadGame(KConfig *);


private:
  // Some Actions that need to be manipulated.
  KAction       *stopAction;
  KAction       *continueAction;

  KToggleAction  *showLastMoveAction;
  KToggleAction  *showLegalMovesAction;

  // The game itself and game properties
  QReversiGame  *m_game;	   // The main document - the game

  Color          m_humanColor;	   // The Color of the human player.
  bool           m_gameOver;	   // True if the game is over
  bool           m_cheating;	   // True if the user has changed sides
  uint           m_lowestStrength; // Lowest strength during the game.
  bool           m_competitiveGame;// True if the game has been
				   // competitive during all moves so far.

  State          m_state;          // Ready, Thinking, Hint
  Engine        *m_engine;         // The AI that creates the computers moves.

  // Widgets
  QReversiGameView  *m_gameView;   // The board widget.
};


#endif