Activist.h
/*
Programmer: Jennifer Leopold
Date: November 10, 2016
File: activist.h
Purpose: This file contains the definition of an Activist class.
*/
#ifndef ACTIVIST_H
#define ACTIVIST_H
#include <iostream>
#include <string>
#include "point.h"
#include "town.h"
using namespace std;
// Constants for Activist's "state"
const int NORMAL = 0;
const int COOL = 1;
const int GONE = 2;
// Default symbol (char) for activist on grid
const char DEFAULT_ACTIVIST_SYMBOL = 'A';
// Limits and initial values for member var's dignity,
// toxicity, and location (in terms of x and y coords)
const int MIN_DIGNITY = 0;
const int MAX_DIGNITY = 100;
const int INIT_DIGNITY = 100;
const float MIN_TOXICITY = 0;
const float MAX_TOXICITY = 3.0;
const float INIT_TOXICITY = 0.05;
const int INIT_ACTIVIST_LOC_X = -1;
const int INIT_ACTIVIST_LOC_Y = -1;
class Activist
{
private:
// Member var's for activist's name, state, symbol (on
// grid), location (on grid), dignity, and toxicity
string m_name;
int m_state;
char m_symbol;
Point m_location;
int m_dignity;
float m_toxicity;
public:
// Parameterized constructor for Activist.
// Preconditions: None
// Postconditions: m_name and m_symbol set to specified
// values, respectively. m_state set to NORMAL. m_location
// set to Point(INIT_ACTIVIST_LOC_X, INIT_ACTIVIST_LOC_Y).
// m_dignity set to INIT_DIGNITY. m_toxicity set to
// INIT_TOXICITY.
Activist(string name, char symbol = DEFAULT_ACTIVIST_SYMBOL)
: m_name(name), m_state(NORMAL), m_symbol(symbol),
m_location(Point(INIT_ACTIVIST_LOC_X,
INIT_ACTIVIST_LOC_Y)),
m_dignity(INIT_DIGNITY), m_toxicity(INIT_TOXICITY) { }
// Mutator for m_location.
// Preconditions: p has values for its x and y coordinates.
// Postconditions: m_location's x and y coordinates have
// been set to those of p.
void setLocation(const Point &p)
{
m_location = p;
return;
}
// Place this Activist in the middle of the specified town's
// grid.
// Preconditions: None.
// Postconditions: The middle position of the town's grid
// now contains this Activist's m_symbol, and this
// Activist's m_location is now the middle point of the
// specified town.
void placeMeInMiddle(Town &town);
// Take a step in a random direction in the specified
// town (without "stepping on anything").
// Preconditions: None.
// Postconditions: A randomly chosen position of the town's
// grid now contains this Activist's m_symbol, and this
// Activist's m_location is now the randomly chosen
// position.
void randMove(Town &town);
// Overloaded operator for <<.
// Preconditions: None
// Postconditions: Activist's member var values will be
// output to outs, thereby modifying ostream outs, and
// outs is returned.
friend ostream& operator <<(ostream& out,
const Activist& activist);
};
#endif