A TOKEN CLASS: token.h and token.cpp
// token.h
// A class to simulate playing tokens on a game board
#ifndef _TOKEN_H
#define _TOKEN_H
#include <bool.h>
#include <stdlib.h>
#include <dice.h>
class token
{
public:
token(char name, int startPos, int winPos, int maxDiceRoll);
bool move();
int getPos() const;
char getName() const;
private:
char myName;
int myPosition;
int myWinningPos;
dice myDice;
};
#include "token.cpp" // hook to include implementation file for token
#endif
____________________
// token.cpp
token::token(char name, int startPos, int winPos, int maxDiceRoll)
: myName(name), myPosition(startPos), myWinningPos(winPos), myDice(maxDiceRoll)
{
// all private variables initialized using initializer list
}
bool token::move()
{
int n = myDice.roll();
myPosition += n;
if (myPosition >= myWinningPos)
return true;
else
return false;
}
int token::getPos() const
{
return myPosition;
}
char token::getName() const
{
return myName;
}