-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrabble_square.hpp
144 lines (109 loc) · 4.85 KB
/
scrabble_square.hpp
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
#ifndef scrabble_square_h
#define scrabble_square_h
#include "scrabble_piece.hpp"
#include <iostream>
#include <string>
class Scrabble_Game;
//The Bonus enum contains values for all possible bonuses on the board
enum Bonus {NONE, DBL_LET, TRP_LET, DBL_WRD, TRP_WRD};
/**
* This class represents a single square on the scrabble board. In other words
* a Scrabble_Board is made up of instances of Scrabble_Square. Scrabble_Squares
* are responsible for knowing if a piece has been placed on them, if so, what
* piece object has been placed on them, and what bonuses apply to this square.
*/
////////////////////////////////////////////////////////////////////////////////
class Scrabble_Square
////////////////////////////////////////////////////////////////////////////////
{
public:
/**
* Constructor - Initializes this square with no piece and no bonus.
*/
Scrabble_Square() : m_piece(NULL), m_bonus(NONE) {}
/**
* Destructor
*/
~Scrabble_Square() {}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////// PRIMARY INTERFACE ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* add_piece - Adds a piece to this square. This is what ultimately happens
* when a player plays a piece.
*/
void add_piece(const Scrabble_Piece* piece);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// QUERIES /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* is_free - Returns true if no one has played a piece on this square.
*/
bool is_free() const { return (!m_piece); }
/**
* get_bonus() - Returns the bonus associated with this square
*/
Bonus get_bonus() const { return m_bonus; }
/**
* get_piece() - Returns the piece played on this square. We return NULL if
* this square is free.
*/
const Scrabble_Piece* get_piece() const { return m_piece; }
/**
* operator<< - Produces a nice-looking output of the square's state. This is
* intended to be called by Scrabble_Board as it is producing an
* output for the entire board.
*/
std::ostream& operator<<(std::ostream& out) const;
/**
* operator>> - Read square state from istream
*/
std::istream& operator>>(std::istream& out);
// OUTPUT_LEN - The number of characters of output created when operator<<
// is called on a scrabble_square. This is difficult to enforce,
// but it's useful
static const unsigned OUTPUT_LEN = 6;
private: // ================== PRIVATE INTERFACE ==============================
//////////////////////////////////////////////////////////////////////////////
////////////////////////// CONSTRUCTION METHODS //////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/**
* set-parent - Set the parent game
*/
void set_parent(const Scrabble_Game& parent) { m_parent = &parent; }
/**
* set_bonus - Changes the bonus associated with this square to that of the
* argument. We don't want this method to be called by anyone,
* so we made it private and befriended Board_Builder.
*/
void set_bonus(Bonus bonus);
/*
* Get color code for tile
*/
int get_color_code() const;
//////////////////////////////////////////////////////////////////////////////
///////////////////////////// DATA MEMBERS ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// m_parent - Parent game
const Scrabble_Game* m_parent;
// m_piece - A pointer to whatever piece has been played on this square. This
// is NULL if no piece has been played.
const Scrabble_Piece* m_piece;
// m_bonus - The bonus associated with this square.
Bonus m_bonus;
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////// FRIENDS //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
friend class Standard_Board_Builder;
friend class Wwf_Board_Builder;
friend class Wwf_Solo_Board_Builder;
friend class Board_Builder;
};
////////////////////////////////////////////////////////////////////////////////
///////////////////////// ASSCOCIATED OPERATIONS ///////////////////////////////
////////////////////////////////////////////////////////////////////////////////
std::ostream& operator<<(std::ostream& out, const Scrabble_Square& sq);
std::ostream& operator<<(std::ostream& out, const Bonus& b);
std::istream& operator>>(std::istream& in, Scrabble_Square& sq);
std::istream& operator>>(std::istream& in, Bonus& b);
#endif