here's what to do:

Imagine that you are part of a team creating a role-playing game. As a Support Programmer, you
have been tasked by your Project Lead with creating the classes needed for player combat. For the
first prototype, you will have to be able to create an attack() function that will simulate combat
1. Using http://www.gliffy.com/, create a UML diagram of your proposed classes. Sign up first.
Save it as a PNG in Exam folder. Note: Having problems with the connection? You can always
use the scratch paper and pen provided to design the UML. Thanks!

2. Using either Netbeans (for Java) or Microsoft Visual C++ Express (for C++), create a program
that instantiates your UML classes.
Go To: Desktop -> [Name] -> Exam2_Java for JAVA Language using NetBeans or;
Go To: Desktop -> [Name] -> Exam2_C for C++ Language using Visual C++ Express.
3. Create the attack() function, and call it in your program. When called, the calling instantiated
class will try to attack a target class. If the attack hits, the target class is dealt damage. The result of
the attack should then be output on the debug console. There are still no final specifications yet for
what variables will determine combat damage or the chance to hit, so create your code to be flexible
enough to accommodate any possible additions or changes in the combat design.
4. Submit the UML PNG file, the binary executable and the source code of your program.


8 Years
Discussion Span
Last Post by Alex Edwards

This actually reminded me of the project I'm working on.

You could do something like this, where you use an Engageable interface to allow implementing classes to attack one another.

Here's the interface (in Java)

//import CharacterData.*;
//import DisplayPackage.*;

 * interface Engageable
 * Provides a means of Engagement between
 * one Engageable and another.
 * All Engageables are expected to have valid Stats.
public interface Engageable{
     * Returns true if the calling Engageable object is
     * still alive/concious, or false otherwise.
     * Typically an Engageable target is alive so long
     * as their HP is over 0, but other conditions may
     * discourage liveliness.
    public boolean isAlive();
     * Sets the current Stats
    public void setStats(Stats s);
     * To be clear, this method doesn't access the other
     * target's stats to alter it to a newly allocated
     * stat. Instead it is to set the reference of the
     * calling objects otherTargetStats. For example, if
     * class User implements Engageable and needs a way
     * of referencing the current target's stats then
     * he/she can simply call this method for their own
     * private variable Stats otherTargetStats.
    public void setTargetStats(Stats s);
     * Returns the current Stats
    public Stats getStats();
     * Returns the other target's stats or null if the
     * other target hasn't been specified.
     * This method is preferred so that Engageable commands
     * can be scaled from one target vs. another.
    public Stats getTargetStats();
     * Perform an attack on another Engageable target.
    public void attack(Engageable other);
     * Attack the currently set Engageable target
    public void attack();
     * Triggers for the caller to receive damage.
     * This method is typically called when the caller
     * is to be penalized when attacking an enemy with a
     * special ability.
    public void receiveDamage();
     * Triggers for the caller to receive damage from
     * the given Engageable target.
    public void receiveDamage(Engageable other);
     * Sets the target for the next Engageable action
    public void setTarget(Engageable other);
     * Returns the currently set Engageable target, or
     * null if no target is set.
    public Engageable getTarget();

Of course you don't need a lot of the methods mentioned above, just use the target/attack/receive damage methods.

Your course seems fairly advanced as it is lenient enough to accept Java or C++.

As for the UML I'm not familiar enough with it (yet) to help you so you'll have to do some research.

However, at least you'll know that each class that will receive damage can do so by implementing the Engageable interface.

This can easily be rewritten to be C++ compatible. Just rewrite the above code (the necessary methods only) as pure virtual methods in a class and have the desirable opponent classes inherit from that abstract class.

Hopefully this will help you get started. If not, sorry for trying =P


how will i convert it into c++? i need the said program in c++...thanks a lot

It's not too hard to convert this to C++.

C++ does not have interfaces, because C++ doesn't need them.

Here's an idea of how you could convert this from Java to C++ --

#include <iostream>
#include <cstdlib>

namespace CombatSpace{ // namespace not necessary, put this class definition in a Header file

     class Engageable{
                    virtual boolean isAlive() = 0;
                    virtual void attack(Engageable *other) = 0;
                    // other desired methods from Engageable interface

so how will i be able to integrate the UML file here?

I don't like to repeat myself but I'll say it again if you were glancing over my previous comments--

I'm not proficient enough with UML to help you.

The only thing I can give you is a guess - you'll have to determine which classes will inherit from the Engageable abstract class then you can develop a UML based on that.

I have no idea what classes you'll be using, attacking with or implementing. Obviously because of that the Engageable interface will most likely need to be modified.

For example, if the targets are not expected to attack back you may want to define another class that just takes damage. I'd give this class an appropriate name like "Victim" or "Civilian" and adjust the Engageable interface to be able to set/get Civilians and attack them and of course Civilians can receive damage.

Cruel in theory, but effective. Once again your program simply needs to be "flexibile" so it's completely up to you.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.