Assignment 4. CS330 Programming Languages, Summer 2006
PLEASE READ CAREFULLY
MISSING DETAILS MAY COST YOU
(10% of final grade - 10 points)
War of worldcraft - C++ (10)
The purpose of this assignment is to familiarize you with
Object-Oriented
Programming through a simplified but not trivial assignment. Your task
is to write a collection of classes and functions to manipulate GameEntities.
Your simplified game will consist of two derived classes from GameEntity
Wizard and Queen. All
Game Entities have a position (expressed as two
integers x and y) and a number of stamina points (also an integer).
Specific Game Entities like Wizard or Queen must support two member
functions: moveTo(new_x, new_y)
and info. The implementation
of this function is specific to each derived class. The info function just
displays the type of GameEntity as
well as the name of the particular instance
and the current stamina points. The moveTo(new_x,
new y) changes
the coordinates of the GameEntity
in the same way independently
of the particular derived class and reduces the staminaPoints in a
derived
class dependent way. Essentially the code that's common should go in
GameEntity and
the code that's derived class specific should go in the corresponding
derived class. More specifically Queens loose 10 stamina points
everytime they move and Wizard loose 5 stamina points.
A framework that can be used as a foundation to build your code
is provided:
asn3_cs330.tar.gz
The framework contains the client code in main.cpp, a Makefile and
the header files for all the classes and the desired output. Your task
will be to provide
.cpp files with the implementation of all the member functions so that
when
the code is executed it produces the same output as output.txt. You
will
need to add appropriate cout statements in constructors and destructors
as well as implement the info
function accordingly.
Part 1 world1 (3 points)
The first part of the assignment is to implement a straightforward
approach
to creating a collection of GameEntities
using pointers. Then you can iterate
over the collection calling functions that through dynamic binding are
specific to the
run-time derived class type of each
GameEntity.
More simply the code in
world1 should work and
produce the corresponding
output.
Part 2 world2 (4 points)
In this part you are asked to implement a GameEntitySurrogate class that
can be used to control memory allocation and putting objects of diverse
types into a single container. To implement this you will need
to support a clone() method
for each derived class from GameEntity.
The code in world2 should work and produce the corresponding output.
Part 3 world3 (3 points)
In this part you are asked to implement a GameEntityFactory that
enables the run-time creation of objects for which their type is not
known
at run-time. The main idea is to use a map container to map a string
corresponding to the type of the GameEntity
such as "Wizard"
to a GameEntitySurrogate that can be used as a prototype to
"clone" GameEntities as needed. The setName method is used
to change the name appropriately.
The code in world3 should work and produce the corresponding output.