rp-scrabble
Simple, terminal-based Scrabble game
Public Member Functions | Private Attributes | List of all members
Play Class Reference

#include <play.h>

Collaboration diagram for Play:
Collaboration graph
[legend]

Public Member Functions

 Play (Player *p)
 
 ~Play ()
 
void setPlayer (Player *p)
 
bool validate (std::string tileStr, Board *b, int r, int c, char dir)
 
std::vector< std::vector< Tile * > > getWords (std::vector< Tile * > tilesInStr, Board *b, int r, int c, char dir)
 
std::vector< Tile * > getConnectedWord (Tile *t, char dir)
 
void calculatePoints (std::vector< std::vector< Tile * >> words, std::vector< Tile * > tileStrVec)
 
int getPointsMade ()
 
bool confirmPlay ()
 
void reset ()
 
void show ()
 

Private Attributes

int pointsMade
 
PlayerplayMaker
 
std::string playStr
 
std::vector< std::vector< Tile * > > wordsInPlay
 

Detailed Description

Definition at line 23 of file play.h.

Constructor & Destructor Documentation

◆ Play()

Play::Play ( Player p)

Construct a Play

Parameters
pPointer to the Player who is making the Play

This function shall note throw exceptions

Definition at line 19 of file play.cc.

◆ ~Play()

Play::~Play ( )

Play destructor

Definition at line 29 of file play.cc.

Member Function Documentation

◆ calculatePoints()

void Play::calculatePoints ( std::vector< std::vector< Tile * >>  words,
std::vector< Tile * >  tileStrVec 
)

Calculate the points made when the play was made

Parameters
wordsThe words to consider for calculation
tileStrVecTiles that were placed in the Play

This function shall not throw exceptions.

Definition at line 296 of file play.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ confirmPlay()

bool Play::confirmPlay ( )

Ask whether the play should be confirmed or not

Returns
true if confirmed, false otherwise

This function shall not throw exceptions.

Definition at line 363 of file play.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getConnectedWord()

vector< Tile * > Play::getConnectedWord ( Tile t,
char  searchDir 
)

Get the word that a Tile is part of

Parameters
tTile in question
searchDirDirection of search
Returns
Vector of Tiles that make up the found "word"
Exceptions
std::stringcontaining the error message

Definition at line 254 of file play.cc.

Here is the call graph for this function:

◆ getPointsMade()

int Play::getPointsMade ( )

Getter for pointsMade data member

Returns
pointsMade

This function shall not throw exceptions.

Definition at line 351 of file play.cc.

Here is the caller graph for this function:

◆ getWords()

vector< vector< Tile * > > Play::getWords ( std::vector< Tile * >  tilesInStr,
Board b,
int  r,
int  c,
char  dir 
)

Get all new words that were made as a result of successful play

Parameters
tilesInStrVector of Tiles that were placed
bPointer to the Board where the Tiles were placed
rRow where the first Tile goes
cColumn where first tile goes
dirDirection of placement
Returns
A 2D vector of Tiles containing all the words made as vectors of Tiles
Exceptions
std::stringcontaining the error message

Definition at line 175 of file play.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void Play::reset ( )

Reset the Play to initial conditions

This function shall not throw exceptions.

Definition at line 387 of file play.cc.

Here is the caller graph for this function:

◆ setPlayer()

void Play::setPlayer ( Player p)

Set the maker of the Play

Parameters
pPointer to a Player object

This function shall not throw exceptions.

Definition at line 62 of file play.cc.

◆ show()

void Play::show ( )

"Pretty print" the Play

Definition at line 37 of file play.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate()

bool Play::validate ( std::string  tileStr,
Board b,
int  r,
int  c,
char  dir 
)

Validates whether a requested play is possible or not. Rejection restores the game's condition as it was before the play was made.

Algorithm-

  1. Start from first placed Tile
  2. Check whether the Tile has any neighbours that were placed before the current Tile (ie. check if the play connects with a previously placed word)
  3. If so, play is valid, return true, otherwise, move to next Tile
  4. If all placed Tiles are exhausted, return false
Parameters
tileStrString of letters that represent the Tiles to be placed
bPointer to the Board where the tiles are to be placed
rRow where the first Tile goes
cColumn where first tile goes
dirDirection of placement
Returns
true if valid, false otherwise
Exceptions
std::stringcontaining the error message
Warning
Cannot be used to validate the first play

Definition at line 90 of file play.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ playMaker

Player* Play::playMaker
private

Definition at line 26 of file play.h.

◆ playStr

std::string Play::playStr
private

Definition at line 27 of file play.h.

◆ pointsMade

int Play::pointsMade
private

Definition at line 25 of file play.h.

◆ wordsInPlay

std::vector<std::vector<Tile*> > Play::wordsInPlay
private

Definition at line 28 of file play.h.


The documentation for this class was generated from the following files: