C++ Project OF Zombie Hunter Game (Test Your Survival Skills)-Tested For Microsoft Visual C++ 2010 (Zombie Game)

Leave a Comment
 /*The following C++ Program, is for the zombie game, in this initially 3 zombies will be there denoted by 'Z', & the player will be denoted by '@'. The player & zombies will move in 3x3 box arena, & the aim of the game is to gain the maximum number of moves without being eaten by zombies*/

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <cassert>
#include <stdlib.h>
using namespace std;

///////////////////////////////////////////////////////////////////////////
// Manifest constants
///////////////////////////////////////////////////////////////////////////

const int MAXROWS = 20;
// max number of rows in the arena
const int MAXCOLS = 20;
// max number of columns in the arena
const int MAXZOMBIES = 100;
// max number of zombies allowed

const int NORTH = 0;
const int EAST = 1;
const int SOUTH = 2;
const int WEST = 3;
const int NUMDIRS = 4;
const int STATIONARY = 4;

const int EMPTY = 0;
const int HAS_BRAIN = 1;

///////////////////////////////////////////////////////////////////////////
// Type definitions
///////////////////////////////////////////////////////////////////////////

class Arena;
// This is needed to let the compiler know that Arena is a
// type name, since it's mentioned in the Zombie declaration.

class Zombie
{
public:
// Constructor
Zombie(Arena* ap, int r, int c);

// Accessors
int row() const;
int col() const;
bool isDead() const;

// Mutators
void move();

private:
Arena* m_arena;
int m_row;
int m_col;
int m_nBrains;
bool noMove;
// You'll probably find that a zombie object needs additional
// data members to support your implementation of the behavior affected
// by poisoned brains.
};

class Player
{
public:
// Constructor
Player(Arena *ap, int r, int c);

// Accessors
int row() const;
int col() const;
bool isDead() const;

// Mutators
string dropBrain();
string move(int dir);
void setDead();

private:
Arena* m_arena;
int m_row;
int m_col;
bool m_dead;
};

class Arena
{
public:
// Constructor/destructor
Arena(int nRows, int nCols);
~Arena();

// Accessors
int rows() const;
int cols() const;
Player* player() const;
int zombieCount() const;
int getCellStatus(int r, int c) const;
int numberOfZombiesAt(int r, int c) const;
void display(string msg) const;

// Mutators
void setCellStatus(int r, int c, int status);
bool addZombie(int r, int c);
bool addPlayer(int r, int c);
void moveZombies();

private:
int m_grid[MAXROWS][MAXCOLS];
int m_rows;
int m_cols;
Player* m_player;
Zombie* m_zombies[MAXZOMBIES];
int m_totalZombies;
int m_nZombies;
int m_turns;

// Helper functions
void checkPos(int r, int c) const;
};

class Game
{
public:
// Constructor/destructor
Game(int rows, int cols, int nZombies);
~Game();

// Mutators
void play();

private:
Arena* m_arena;

// Helper functions
string takePlayerTurn();
};

///////////////////////////////////////////////////////////////////////////
// Auxiliary function declarations
///////////////////////////////////////////////////////////////////////////

int randInt(int lowest, int highest);
bool charToDir(char ch, int& dir);
bool attemptMove(const Arena& a, int dir, int& r, int& c);
bool recommendMove(const Arena& a, int r, int c, int& bestDir);
void clearScreen();
void rotateLeft(Zombie* zombie[], int n, int pos);
int lowestCostPos(int arr[], int n);
bool isValidMove(const Arena& a, int dir, int r, int c);

///////////////////////////////////////////////////////////////////////////
// Zombie implementation
///////////////////////////////////////////////////////////////////////////

Zombie::Zombie(Arena* ap, int r, int c)
{
if (ap == nullptr)
{
cout << "***** A zombie must be created in some Arena!" << endl;
exit(1);
}
if (r < 1 || r > ap->rows() || c < 1 || c > ap->cols())
{
cout << "***** Zombie created with invalid coordinates (" << r << ","<< c << ")!" << endl;
exit(1);
}
m_arena = ap;
m_row = r;
m_col = c;
noMove = false;
m_nBrains = 0;
}

int Zombie::row() const
{
return m_row;
}

int Zombie::col() const
{
return m_col;
}

bool Zombie::isDead() const
{
if (m_nBrains >= 2)
return true;
else
return false;
}

void Zombie::move()
{
if (m_nBrains == 1 && noMove)
{
noMove = false;
return;
}

else
{
int randDir = randInt(NORTH, WEST);
attemptMove(*m_arena, randDir, m_row, m_col);
//Random movement
}

if (m_arena->getCellStatus(m_row, m_col) == HAS_BRAIN)
{
noMove = true;
m_arena->setCellStatus(m_row, m_col, EMPTY);
m_nBrains++;
}

if (m_nBrains == 1 && !noMove)
{
noMove = true;
}

/
/ Return without moving if the zombie has eaten one brain (so is
// supposed to move only every other turn) and this is a turn it
// does not move.

// Otherwise, attempt to move in a random direction; if it can't
// move, don't move. If it lands on a poisoned brain, eat the brain,
// so it is no longer on that grid point.
}

///////////////////////////////////////////////////////////////////////////
// Player implementation
///////////////////////////////////////////////////////////////////////////

Player::Player(Arena* ap, int r, int c)
{
if (ap == nullptr)
{
cout << "***** The player must be created in some Arena!" << endl;
exit(1);
}
if (r < 1 || r > ap->rows() || c < 1 || c > ap->cols())
{
cout << "**** Player created with invalid coordinates (" << r<< "," << c << ")!" << endl;
exit(1);
}
m_arena = ap;
m_row = r;
m_col = c;
m_dead = false;
}

int Player::row() const
{
return m_row;
}

int Player::col() const
{
return m_col;
}

string Player::dropBrain()
{
if (m_arena->getCellStatus(m_row, m_col) == HAS_BRAIN)
return "There's already a brain at this spot.";
m_arena->setCellStatus(m_row, m_col, HAS_BRAIN);
return "A brain has been dropped.";
}

string Player::move(int dir)
{
// Attempt to move the player one step in the indicated
// direction. If this fails,
// return "Player couldn't move; player stands."
// A player who moves onto a zombie dies, and this
// returns "Player walked into a zombie and died."
// Otherwise, return one of "Player moved north.",
// "Player moved east.", "Player moved south.", or
// "Player moved west."
switch(dir)
{
case NORTH:
if (!attemptMove(*m_arena, NORTH, m_row, m_col))
return "Player couldn't move; player stands.";
if (m_arena->numberOfZombiesAt(m_row, m_col) >= 1)
{
setDead();
return "Player walked into a zombie and died.";
}

return "Player moved north.";
case EAST:
if (!attemptMove(*m_arena, EAST, m_row, m_col))
return "Player couldn't move; player stands.";
if (m_arena->numberOfZombiesAt(m_row, m_col) >= 1)
{
setDead();
return "Player walked into a zombie and died.";
}

return "Player moved east.";
case SOUTH:
if (!attemptMove(*m_arena, SOUTH, m_row, m_col))
return "Player couldn't move; player stands.";
if (m_arena->numberOfZombiesAt(m_row, m_col) >= 1)
{
setDead();
return "Player walked into a zombie and died.";
}

return "Player moved south.";
case WEST:
if (!attemptMove(*m_arena, WEST, m_row, m_col))
return "Player couldn't move; player stands.";
if (m_arena->numberOfZombiesAt(m_row, m_col) >= 1)
{
setDead();
return "Player walked into a zombie and died.";
}

return "Player moved west.";
}
}

bool Player::isDead() const
{
return m_dead;
}

void Player::setDead()
{
m_dead = true;
}

///////////////////////////////////////////////////////////////////////////
// Arena implementation
///////////////////////////////////////////////////////////////////////////

Arena::Arena(int nRows, int nCols)
{
if (nRows <= 0 || nCols <= 0 || nRows > MAXROWS || nCols > MAXCOLS)
{
cout << "***** Arena created with invalid size " << nRows << " by "
<< nCols << "!" << endl;
exit(1);
}
m_rows = nRows;
m_cols = nCols;
m_player = nullptr;
m_nZombies = 0;
m_totalZombies = 0;

m_turns = 0;
for (int r = 1; r <= m_rows; r++)
for (int c = 1; c <= m_cols; c++)
setCellStatus(r, c, EMPTY);
}

Arena::~Arena()
{
delete[] m_zombies;
delete m_player;
}

int Arena::rows() const
{
return m_rows;
}

int Arena::cols() const
{
return m_cols;
}

Player* Arena::player() const
{
return m_player;
}

int Arena::zombieCount() const
{
return m_nZombies;
}

int Arena::getCellStatus(int r, int c) const
{
checkPos(r, c);
return m_grid[r-1][c-1];
}

int Arena::numberOfZombiesAt(int r, int c) const
{
if (r > MAXROWS || c > MAXCOLS)
exit(1);
int numOfZombies = 0;
for (int i = 0; i < m_nZombies; i++)
{
if (m_zombies[i] == nullptr)
continue;
if (m_zombies[i]->row() == r && m_zombies[i]->col() == c)
numOfZombies++;
}
return numOfZombies;
}

void Arena::display(string msg) const
{
char displayGrid[MAXROWS][MAXCOLS];
int r, c;

// Fill displayGrid with dots (empty) and stars (brains)
for (r = 1; r <= rows(); r++)
for (c = 1; c <= cols(); c++)
switch(numberOfZombiesAt(r, c))
{
case 0:
displayGrid[r-1][c-1] = (getCellStatus(r,c) == EMPTY ? '.' : '*');
break;
case 1:
displayGrid[r-1][c-1] = 'Z';
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
displayGrid[r-1][c-1] = '0' + numberOfZombiesAt(r, c);
break;
default:
displayGrid[r-1][c-1] = '9';
break;
}


// Indicate player's position
if (m_player != nullptr)
displayGrid[m_player->row()-1][m_player->col()-1] = (m_player->isDead() ? 'X' : '@');

// Draw the grid
clearScreen();
for (r = 1; r <= rows(); r++)
{
for (c = 1; c <= cols(); c++)
cout << displayGrid[r-1][c-1];
cout << endl;
}
cout << endl;

// Write message, zombie, and player info
if (msg != "")
cout << msg << endl;
cout << "There are " << zombieCount() << " zombies remaining." << endl;
if (m_player == nullptr)
cout << "There is no player!" << endl;
else if (m_player->isDead())
cout << "The player is dead." << endl;
cout << m_turns << " turns have been taken." << endl;
}

void Arena::setCellStatus(int r, int c, int status)
{
checkPos(r, c);
m_grid[r-1][c-1] = status;
}

bool Arena::addZombie(int r, int c)
{
if (m_nZombies == MAXZOMBIES)
return false;
m_zombies[m_nZombies] = new Zombie(this, r, c);
m_nZombies++;
m_totalZombies++;
return true;
}

bool Arena::addPlayer(int r, int c)
{
// Don't add a player if one already exists
if (m_player != nullptr)
return false;

// Dynamically alocate a new Player and add it to the arena
m_player = new Player(this, r, c);
return true;
}

void Arena::moveZombies()
{
// Move all zombies. Move each zombie. Mark the player as dead if necessary.
// Release any dead dynamically allocated zombie.
for (int i = 0; i < m_nZombies; i++)
{
if (m_zombies[i] == nullptr)
continue;

m_zombies[i]->move();

if (m_player->row() == m_zombies[i]->row() && m_player->col() == m_zombies[i]->col())
{
m_player->setDead();
break;
}
if (m_zombies[i]->isDead())
{
delete m_zombies[i];
m_zombies[i] = nullptr;
m_nZombies--;
}
}
// Another turn has been taken
m_turns++;
}

void Arena::checkPos(int r, int c) const
{
if (r < 1 || r > m_rows || c < 1 || c > m_cols)
{
cout << "***** " << "Invalid arena position (" << r << ","<< c << ")" << endl;
exit(1);
}
}

///////////////////////////////////////////////////////////////////////////
// Game implementation
///////////////////////////////////////////////////////////////////////////

Game::Game(int rows, int cols, int nZombies)
{
if (nZombies < 0 || nZombies > MAXZOMBIES)
{
cout << "***** Game created with invalid number of zombies: "<< nZombies << endl;
exit(1);
}
int nEmpty = rows * cols - nZombies - 1;
// 1 for Player
if (nEmpty < 0)
{
cout << "***** Game created with a " << rows << " by "<< cols << " arena, which is too small too hold a player and "<< nZombies << " zombies!" << endl;
exit(1);
}

// Create arena
m_arena = new Arena(rows, cols);

// Add player
int rPlayer;
int cPlayer;
do
{
rPlayer = randInt(1, rows);
cPlayer = randInt(1, cols);
} while (m_arena->getCellStatus(rPlayer, cPlayer) != EMPTY);
m_arena->addPlayer(rPlayer, cPlayer);
// Populate with zombies
while (nZombies > 0)
{
int r = randInt(1, rows);
int c = randInt(1, cols);
if (r == rPlayer && c == cPlayer)
{
continue;
}
m_arena->addZombie(r, c);
nZombies--;

}

}

Game::~Game()
{
delete m_arena;
}

string Game::takePlayerTurn()
{
for (;;)
{
cout << "Your move (n/e/s/w/x or nothing): ";
string playerMove;
getline(cin, playerMove);

Player* player = m_arena->player();
int dir;

if (playerMove.size() == 0)
{
if (recommendMove(*m_arena, player->row(), player->col(), dir))
return player->move(dir);
else
return player->dropBrain();
}
else if (playerMove.size() == 1)
{
if (tolower(playerMove[0]) == 'x')
return player->dropBrain();
else if (charToDir(playerMove[0], dir))
return player->move(dir);
}



cout << "Player move must be nothing, or 1 character n/e/s/w/x." << endl;
}
}

void Game::play()
{
m_arena->display("");
while ( ! m_arena->player()->isDead() && m_arena->zombieCount() > 0)
{
string msg = takePlayerTurn();
Player* player = m_arena->player();
if (player->isDead())
break;
m_arena->moveZombies();
m_arena->display(msg);
}
if (m_arena->player()->isDead())
cout << "You lose." << endl;
else
cout << "You win." << endl;
}

///////////////////////////////////////////////////////////////////////////
// Auxiliary function implementation
///////////////////////////////////////////////////////////////////////////

// Return a uniformly distributed random int from lowest to highest, inclusive
int randInt(int lowest, int highest)
{
if (highest < lowest)
swap(highest, lowest);
return lowest + (rand() % (highest - lowest + 1));
}

bool charToDir(char ch, int& dir)
{
switch (tolower(ch))
{
default: return false;
case 'n': dir = NORTH; break;
case 'e': dir = EAST; break;
case 's': dir = SOUTH; break;
case 'w': dir = WEST; break;
}
return true;
}

// Return false without changing anything if moving one step from (r,c)
// in the indicated direction would run off the edge of the arena.
// Otherwise, update r and c to the position resulting from the move and
// return true.
bool attemptMove(const Arena& a, int dir, int& r, int& c)
{
switch(dir)
{
case NORTH:
if (!isValidMove(a, dir, r, c))
return false;
r -= 1;
return true;
case EAST:
if (!isValidMove(a, dir, r, c))
return false;
c += 1;
return true;
case SOUTH:
if (!isValidMove(a, dir, r, c))
return false;
r += 1;
return true;
case WEST:
if (!isValidMove(a, dir, r, c))
return false;
c -= 1;
return true;
}
return false;
}

// Recommend a move for a player at (r,c): A false return means the
// recommendation is that the player should drop a brain and not move;
// otherwise, this function sets bestDir to the recommended direction
// to move and returns true.
bool recommendMove(const Arena& a, int r, int c, int& bestDir)
{
int cost[5];
for (int i = 0; i < 4; i++) //If moving one direction is invalid, give it high cost. Else, initialize all costs to 0
{
cost[i] = 0;
if (!isValidMove(a, i, r, c))
cost[i] += 100;
}


int zombiesNorth = a.numberOfZombiesAt(r-1, c);
int zombiesEast = a.numberOfZombiesAt(r, c+1);
int zombiesSouth = a.numberOfZombiesAt(r+1, c);
int zombiesWest = a.numberOfZombiesAt(r, c-1);
int zombiesNorthWest = a.numberOfZombiesAt(r-1, c-1);
int zombiesNorthEast = a.numberOfZombiesAt(r-1, c+1);
int zombiesSouthWest = a.numberOfZombiesAt(r+1, c-1);
int zombiesSouthEast = a.numberOfZombiesAt(r+1, c+1);
int zombiesTwoNorth = a.numberOfZombiesAt(r-2, c);
int zombiesTwoEast = a.numberOfZombiesAt(r, c+2);
int zombiesTwoSouth = a.numberOfZombiesAt(r+2, c);
int zombiesTwoWest = a.numberOfZombiesAt(r, c-2);

//Adjacent zombies are cost 4 for each
cost[NORTH] += zombiesNorth * 4;
cost[EAST] += zombiesEast * 4;
cost[SOUTH] += zombiesSouth * 4;
cost[WEST] += zombiesWest * 4;

//Diagonal zombies add a cost of 2 to the subdirections

//Northwest
cost[NORTH] += zombiesNorthWest * 2;
cost[WEST] += zombiesNorthWest * 2;
//Northeast
cost[NORTH] += zombiesNorthEast * 2;
cost[EAST] += zombiesNorthEast * 2;
//Southwest
cost[SOUTH] += zombiesSouthWest * 2;
cost[WEST] += zombiesSouthWest * 2;
//Southeast
cost[SOUTH] += zombiesSouthEast * 2;
cost[EAST] += zombiesSouthEast * 2;

//Zombies two squares in a line are a cost of 1
cost[NORTH] += zombiesTwoNorth;
cost[EAST] += zombiesTwoEast;
cost[SOUTH] += zombiesTwoSouth;
cost[WEST] += zombiesTwoWest;

//Not moving has no cost, unless zombies are nearby. Then cost is 3
if (zombiesNorth >= 1 || zombiesEast >= 1 || zombiesSouth >= 1 || zombiesWest >= 1)
cost[STATIONARY] = 3;
else
cost[STATIONARY] = 0;


if (lowestCostPos(cost, 5) == STATIONARY)
return false;
else
{
bestDir = lowestCostPos(cost, 5);
return true;
}
}

int lowestCostPos(int arr[], int n)
{
int lowestCost = arr[n - 1];
int lowestPos = n - 1;
for (int i = n - 1; i >= 0; i--)
{
if (arr[i] < lowestCost)
{
lowestCost = arr[i];
lowestPos = i;
}
}

if (arr[STATIONARY] == lowestCost)
return STATIONARY;
else
return lowestPos;
}

void rotateLeft(Zombie* zombie[], int n, int pos)
{
if (n < 0 || pos < 0 || pos > n)
return;

Zombie* toBeMoved = zombie[pos];

for (int k = pos; k < n - 1; k++)
zombie[k] = zombie[k+1];

zombie[n - 1] = toBeMoved;
return;
}

bool isValidMove(const Arena& a, int dir, int r, int c)
{
switch(dir)
{
case NORTH:
if (r - 1 <= 0)
return false;
else
return true;
case EAST:
if (c + 1 > a.cols())
return false;
else
return true;
case SOUTH:
if (r + 1 > a.rows())
return false;
else
return true;
case WEST:
if (c - 1 <= 0)
return false;
else
return true;
}
return false;
}
// DO NOT MODIFY THE CODE BETWEEN HERE AND THE MAIN ROUTINE
#ifdef _MSC_VER // Microsoft Visual C++

#include <windows.h>

void clearScreen()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
COORD upperLeft = { 0, 0 };
DWORD dwCharsWritten;// TODO: implement this function
// Delete the following line and replace it with the correct code.
FillConsoleOutputCharacter(hConsole, TCHAR(' '), dwConSize, upperLeft,
&dwCharsWritten);
SetConsoleCursorPosition(hConsole, upperLeft);
}

#else
// not Microsoft Visual C++, so assume UNIX interface

#include <cstring>

void clearScreen()
{
static const char* term = getenv("TERM");
static const char* ESC_SEQ = "\x1B["; // ANSI Terminal esc seq: ESC [
if (term == nullptr || strcmp(term, "dumb") == 0)
cout << endl;
else
cout << ESC_SEQ << "2J" << ESC_SEQ << "H" << flush;
}

#endif

///////////////////////////////////////////////////////////////////////////
// Test functions
///////////////////////////////////////////////////////////////////////////

void thisFunctionWillNeverBeCalled()
{
// If the student deleted or changed the manifest constants, this
// won't compile.

const bool b1 = (MAXROWS == 20 && MAXCOLS == 20 && MAXZOMBIES == 100 &&
EMPTY == 0 && HAS_BRAIN == 1 &&
NORTH == 0 && EAST == 1 && SOUTH == 2 && WEST == 3);
char a1[b1 ? 1 : -1]; // illegal negative size array if b1 is false

// If the student deleted or changed the interfaces to the public
// functions, this won't compile. (This uses magic beyond the scope
// of CS 31.)

Zombie z(static_cast<Arena*>(0), 1, 1);
int (Zombie::*pz1)() const = &Zombie::row;
int (Zombie::*pz2)() const = &Zombie::col;
bool (Zombie::*pz3)() const = &Zombie::isDead;
void (Zombie::*pz4)() = &Zombie::move;

Player p(static_cast<Arena*>(0), 1, 1);
int (Player::*pp1)() const = &Player::row;
int (Player::*pp2)() const = &Player::col;
bool (Player::*pp3)() const = &Player::isDead;
string (Player::*pp4)() = &Player::dropBrain;
string (Player::*pp5)(int) = &Player::move;
void (Player::*pp6)() = &Player::setDead;

Arena a(1, 1);
int (Arena::*pa1)() const = &Arena::rows;
int (Arena::*pa2)() const = &Arena::cols;
Player* (Arena::*pa3)() const = &Arena::player;
int (Arena::*pa4)() const = &Arena::zombieCount;
int (Arena::*pa5)(int,int) const = &Arena::getCellStatus;
int (Arena::*pa6)(int,int) const = &Arena::numberOfZombiesAt;
void (Arena::*pa7)(string) const = &Arena::display;
void (Arena::*pa8)(int,int,int) = &Arena::setCellStatus;
bool (Arena::*pa9)(int,int) = &Arena::addZombie;
bool (Arena::*pa10)(int,int) = &Arena::addPlayer;
void (Arena::*pa11)() = &Arena::moveZombies;

Game g(1,1,1);
void (Game::*pg1)() = &Game::play;
}

void findTheZombie(const Arena& a, int& r, int& c)
{
if (a.numberOfZombiesAt(r-1, c) == 1) r--;
else if (a.numberOfZombiesAt(r+1, c) == 1) r++;
else if (a.numberOfZombiesAt(r, c-1) == 1) c--;
else if (a.numberOfZombiesAt(r, c+1) == 1) c++;
else assert(false);
}

void doBasicTests()
{
{
Arena a(10, 20);
a.addPlayer(2, 5);
Player* pp = a.player();
assert(pp->row() == 2 && pp->col() == 5 && ! pp->isDead());
//PASS
assert(pp->move(NORTH) == "Player moved north."); //PASS
assert(pp->row() == 1 && pp->col() == 5 && ! pp->isDead());
//PASS
assert(pp->move(NORTH) == "Player couldn't move; player stands."); //PASS
assert(pp->row() == 1 && pp->col() == 5 && ! pp->isDead());
//PASS
pp->setDead();
assert(pp->row() == 1 && pp->col() == 5 && pp->isDead());
//PASS
}
{
Arena a(10, 20);
int r = 4;
int c = 4;
a.setCellStatus(r-1, c, HAS_BRAIN);
a.setCellStatus(r+1, c, HAS_BRAIN);
a.setCellStatus(r, c-1, HAS_BRAIN);
a.setCellStatus(r, c+1, HAS_BRAIN);
a.addZombie(r, c);
a.addPlayer(8, 18);
assert(a.zombieCount() == 1 && a.numberOfZombiesAt(r, c) == 1);
//PASS
a.moveZombies();
assert(a.zombieCount() == 1 && a.numberOfZombiesAt(r, c) == 0);
//PASS
findTheZombie(a, r, c);
assert(a.getCellStatus(r, c) != HAS_BRAIN);
//PASS
a.moveZombies();
assert(a.zombieCount() == 1 && a.numberOfZombiesAt(r, c) == 1);
//PASS
a.moveZombies();
assert(a.zombieCount() == 1 && a.numberOfZombiesAt(r, c) == 0);
//PASS
findTheZombie(a, r, c);
a.moveZombies();
assert(a.zombieCount() == 1 && a.numberOfZombiesAt(r, c) == 1);
a.setCellStatus(r-1, c, HAS_BRAIN);
a.setCellStatus(r+1, c, HAS_BRAIN);
a.setCellStatus(r, c-1, HAS_BRAIN);
a.setCellStatus(r, c+1, HAS_BRAIN);
a.moveZombies();
assert(a.zombieCount() == 0 && a.numberOfZombiesAt(r, c) == 0);
assert(a.numberOfZombiesAt(r-1, c) == 0);
assert(a.numberOfZombiesAt(r+1, c) == 0);
assert(a.numberOfZombiesAt(r, c-1) == 0);
assert(a.numberOfZombiesAt(r, c+1) == 0);

for (int k = 0; k < MAXZOMBIES/4; k++)
{
a.addZombie(7, 18);
a.addZombie(9, 18);
a.addZombie(8, 17);
a.addZombie(8, 19);
}
assert(! a.player()->isDead());
a.moveZombies();
assert(a.player()->isDead());
}
cout << "Passed all basic tests" << endl;
exit(0);
}


///////////////////////////////////////////////////////////////////////////
// main()
///////////////////////////////////////////////////////////////////////////

int main()
{
// Initialize the random number generator
srand(static_cast<unsigned int>(time(0)));
//doBasicTests();
Game g(3, 5, 3);
g.play();
system("pause");
return 0;
}



Screenshots:
Initial Condition Of  the Zombie Game, C++ Project OF Zombie Game (Test Your Survival Skills)-Tested For Microsoft Visual C++ 2010 (Zombie Game)
Initial Condition Of  the Zombie Game, C++ Project OF Zombie Game (Test Your Survival Skills)

When The Player Moved, C++ Project OF Zombie Game (Test Your Survival Skills)-Tested For Microsoft Visual C++ 2010 (Zombie Game)
When The Player Moved
When The Player Lost The Game, C++ Project OF Zombie Game (Test Your Survival Skills)-Tested For Microsoft Visual C++ 2010 (Zombie Game)
When The Player Lost The Game


0 comments: