- /*
- * ==============================================================================
- * Name : TicTacToeBoard.h
- * Part of : TicTacToe
- * Interface :
- * Description :
- * Version :
- *
- * Copyright (c) 2005 Nokia Corporation.
- * ==============================================================================
- */
- #ifndef __TICTACTOE_BOARD_H__
- #define __TICTACTOE_BOARD_H__
- // INCLUDES
- #include <e32std.h>
- // CONSTANTS
- const TInt KTicTacToeRows = 3;
- const TInt KTicTacToeColumns = 3;
- const TInt KTicTacToeCells = KTicTacToeRows * KTicTacToeColumns;
- // MACROS
- // DATA TYPES
- enum TTicTacToePlayer
- {
- ETttPlayerNone, ETttPlayerNought, ETttPlayerCross
- };
- // FUNCTION PROTOTYPES
- // FORWARD DECLARATIONS
- // CLASS DECLARATION
- /**
- * Maintains the state of the board, allows moves to be made and checks whether
- * a player has won.
- */
- class TTicTacToeBoard
- {
- public: // Constructors and destructor
- /**
- * C++ default constructor.
- */
- TTicTacToeBoard();
- /**
- * Destructor.
- */
- virtual ~TTicTacToeBoard();
- public: // New functions
- /**
- * Reset the board to initial state.
- */
- void Reset();
- /**
- * Get the player who has taken a given cell.
- * @param aColumn Zero-based column index.
- * @param aRow Zero-based row index.
- * @return The player.
- */
- TTicTacToePlayer Player(TInt aColumn, TInt aRow) const;
- /**
- * Attempt to move a player into a cell.
- * @param aCell Zero-based cell index.
- * @param aPlayer Which player.
- * @return ETrue if the move was made.
- */
- TBool Move(TInt aCell, TTicTacToePlayer aPlayer);
- /**
- * Check whether a player has three in a row.
- * @param aPlayer Which player.
- * @return ETrue if the player has won.
- */
- TBool HasWon(TTicTacToePlayer aPlayer);
- /**
- * Check whether the game is a draw.
- * @return ETrue if it is.
- */
- TBool IsDraw();
- private: // Data
- // Contents of the grid cells
- TTicTacToePlayer iCells[KTicTacToeCells];
- // Flag indicating whether the game is finished
- TBool iCanMove;
- };
- #endif // __TICTACTOE_BOARD_H__
- // End of File