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

#include <player.h>

Collaboration diagram for Player:
Collaboration graph
[legend]

Public Member Functions

 Player (std::string n)
 
 ~Player ()
 
std::string getName ()
 
void setName (std::string)
 
void toggleTurn ()
 
void updateScore (int points)
 
int getScore ()
 
TiletileFromRack (int index)
 
bool placeTile (Tile *t, Board *b, int r, int c)
 
std::vector< Tile * > placeTileStr (std::string str, Board *b, int r, int c, char dir)
 
void draw (int count, Bag *b)
 
bool rackIsEmpty ()
 
void returnToRack (Tile *t, Board *b)
 
void showScore ()
 
void show ()
 

Private Attributes

int score
 
bool turn
 
std::string playerName
 
Rackrack
 

Detailed Description

Implements a player

Each player has a name, a rack, and a score associated with them

Definition at line 19 of file player.h.

Constructor & Destructor Documentation

◆ Player()

Player::Player ( std::string  n)

Construct a Player

Parameters
nName of Player

This function shall not throw exceptions

Definition at line 21 of file player.cc.

◆ ~Player()

Player::~Player ( )

Remove rack pointer

Definition at line 32 of file player.cc.

Member Function Documentation

◆ draw()

void Player::draw ( int  count,
Bag b 
)

Draw new Tiles from the Bag

Parameters
countNumber of Tiles to draw
bPointer to the Bag from which to draw from

This function shall not throw exceptions.

Definition at line 114 of file player.cc.

Here is the call graph for this function:

◆ getName()

string Player::getName ( )

Getter for member playerName

This function shall not throw exceptions.

Definition at line 67 of file player.cc.

◆ getScore()

int Player::getScore ( )

Getter for member score

These functions shall not throw exceptions.

Definition at line 77 of file player.cc.

◆ placeTile()

bool Player::placeTile ( Tile t,
Board b,
int  r,
int  c 
)

Place a Tile on the Board

Parameters
tPointer to the Tile to be placed
bPointer of Board to place on
rRow where Square to be returned is
cColumn where Square to be returned is
Exceptions
std::stringcontaining the error message
Returns
true if successful, false otherwise
Note
This function is a simple pass-through to the implementation in Board

Definition at line 133 of file player.cc.

Here is the call graph for this function:

◆ placeTileStr()

vector< Tile * > Player::placeTileStr ( std::string  str,
Board b,
int  r,
int  c,
char  dir 
)

Place a series of Tiles on the Board

Parameters
strA string of letters that represent Tiles
bPointer to the Board where the Tiles must be placed
rRow where the first Tile goes
cColumn where the first Tile goes
dirDirection of placement ('h'/'v')
Exceptions
std::stringcontaining error message

Definition at line 175 of file player.cc.

Here is the call graph for this function:

◆ rackIsEmpty()

bool Player::rackIsEmpty ( )

Check if the player's rack is empty

Returns
true if empty, false otherwise

This function shall not throw exceptions.

Definition at line 195 of file player.cc.

◆ returnToRack()

void Player::returnToRack ( Tile t,
Board b 
)

Return a Tile from the Board to the player's rack

Parameters
tPointer to the Tile to be retrieved
bPointer to the Board from which to retrieve

This function shall not throw exceptions.

Definition at line 208 of file player.cc.

Here is the call graph for this function:

◆ setName()

void Player::setName ( std::string  name)

Set player name

Parameters
nameThe name of the player

This function shall not throw exceptions.

Definition at line 89 of file player.cc.

◆ show()

void Player::show ( )

"Pretty print" the Player object

Definition at line 40 of file player.cc.

◆ showScore()

void Player::showScore ( )

Show players score, with appropriate formatting

Definition at line 52 of file player.cc.

Here is the call graph for this function:

◆ tileFromRack()

Tile * Player::tileFromRack ( int  index)

Get a Tile from the Players rack

Parameters
indexNumerical index of the position of the Tile to get
Returns
Pointer to the requested Tile, nullpointer if not found

This function shall not throw exceptions.

Note
This function is redundant

Definition at line 159 of file player.cc.

◆ toggleTurn()

void Player::toggleTurn ( )

Toggle the "turn" data member

This function shall not throw exceptions.

Definition at line 143 of file player.cc.

◆ updateScore()

void Player::updateScore ( int  points)

Update the Player's score

Parameters
pointsPoints to add to current score

This function shall not throw exceptions.

Definition at line 101 of file player.cc.

Member Data Documentation

◆ playerName

std::string Player::playerName
private

Definition at line 23 of file player.h.

◆ rack

Rack* Player::rack
private

Definition at line 24 of file player.h.

◆ score

int Player::score
private

Definition at line 21 of file player.h.

◆ turn

bool Player::turn
private

Definition at line 22 of file player.h.


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