Polluter.cpp

/*

Programmer: Jennifer Leopold

Date: November 10, 2016

File: polluter.cpp

Purpose: This file contains the definitions of the functions

for the Polluter class.

*/

#include "polluter.h"

using namespace std;

void Polluter::placeMe(Town& town)

{

// Randomly choose an empty position in town's grid

// and make that this polluter's m_location

m_location = town.getRandomEmpty();

// "Vacate" that location in town

town.vacateLocation(m_location);

// Mark town's grid at that location with polluter's symbol

town.setLocation(m_location, m_symbol);

return;

}

void Polluter::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" polluter's current location in town

town.vacateLocation(m_location);

// Record newLoc as polluter's current location

setLocation(newLoc);

// Mark town's grid at this location with polluter's symbol

town.setLocation(m_location, m_symbol);

return;

}