Activist.cpp
Programmer: Jennifer Leopold
Date: November 10, 2016
File: activist.cpp
Purpose: This file contains the definitions of the functions
for the Activist class.
*/
#include "activist.h"
using namespace std;
void Activist::placeMeInMiddle(Town &town)
{
// First, make sure the town isn't completely full
town.checkForOverPopulatedTown();
// "Vacate" activist's current location in town
town.vacateLocation(m_location);
// Determine the "middle" point of the town's grid
short midPoint = town.getSize()/2;
Point p(midPoint, midPoint);
// Mark that town's location with this activist's symbol
town.setLocation(p, m_symbol);
// Record position p as this activist's current location
setLocation(p);
return;
}
void Activist::randMove(Town &town)
{
Point newLoc;
bool occupied = true;
// First, make sure the town isn't completely full
town.checkForOverPopulatedTown();
// Find an unoccupied position to move to
while (occupied)
{
// Choose a location that is a random move
// from current location
newLoc = m_location.getRandomNeighbor();
// Don't want to go there if there is something
// already there
occupied = town.positionOccupied(newLoc);
}
// "Vacate" activist's current location in town
town.vacateLocation(m_location);
// Record newLoc as activist's current location
setLocation(newLoc);
// Mark town's grid at this location with activist's symbol
town.setLocation(m_location, m_symbol);
return;
}
ostream& operator <<(ostream& outs, const Activist& activist)
{
outs << activist.m_name
<< ": state = " << activist.m_state
<< ", dignity = " << activist.m_dignity
<< ", toxicity = " << activist.m_toxicity
<< ", location = " << activist.m_location;
return outs;
}