Project 1

In your first project you will create a first approach to a simple object-oriented simulation called "Robot Wars"*. The simulation will consist of a large number of simple robots that move within a grid. Each robot acts independently, moving where it wants to, and attacking any robot it encounters.

Each position in the grid is called a cell, and a single cell can contain any number of robots. When several robots are located in the came cell a battle ensues.

Each robot has to have a direction it's going, a positive speed, and an energy level (or number of hit points). Every time a robot is hit during a battle its energy level gets decreased by a certain number of points. Once the energy level reaches zero, the robot dies.

Even though the battlefield is a discrete grid, each robot should have floating point coordinates that you need to recompute into cells. This will give the robots a chance to move in any direction through the field. Please notice that at each step real robot coordinates are to be recomputed into integer cell coordinates, the robot can stay at the same cell. For example, if the initial coordinates of a robot were (7.2, 17.8) and its new coordinates are (7.9, 18.5), then the robot still located in the same cell (7, 18) like shown on the picture.

Note that battlefield should be limited in size. For example, we can decide that x-coordinate of any robot is to be inside the range [0, 800] and y-coordinate is to be inside [0, 500]. Your program should give the user an option to enter these numbers (TextBoxes, remember?!). Please also note that the number of vertical and horizontal cells does not depend on the size of the field. These are two additional parameters that should be either hardcoded or entered by the user (or both - hardcode default values and prompt the user if she/he wants to change them).

However, we compute all robot positions in usual (X, Y) coordinates stored in floating point numbers, remember that at the end you will need to draw robots' pictures and these pictures should be placed according to Visual Studio pixel coordinates. The difference is the direction of the Y-axis (it's going down) and the pixel coordinates are, of course, integers.

For example, a robot with Euclid coordinates (100,200) has screen coordinates (75,240):
Xscreen = 100 * 600/800 = 75
Yscreen = 400 - 200 * 400/500 = 400 - 160 = 240

Don't forget that a robot cannot go outside of the field limits. In other words, you need to decide what a robot to do when it reaches a boundary (stay where it is, change a direction to the opposite, turn, etc).

Assignment

  1. Please perform Object-Oriented Analysis and draw a UML datagram with all classes you think you need to develop your program.
  2. Show the relationships between the classes.
  3. For each class describe:
    • public data members and methods
    • private data members and methods
    • static data members and methods (if there is any)
  4. Describe the algorithm of battle. That is, specify the sequence of steps your program should take to simulate a robot battle. Make sure that your algorithm can handle a battle of several robots. In this case, you need to decide how a robot selects its target. Provide the detailed description how the number of hit points deducted from the wobot under attack is computed.
  5. Describe how a robot chooses a new direction when it reaches the battlefield boundaries.
  6. If you decide to make "smart" robots (that is, let the robots decide which direction the robot is going on the next move) provide the detailed description of the algorithm as well as the information the robot need to make that decision.
  7. You can plan ahead and add more features to your robots. The features can include something like: armor, weapons, engine power, max speed, reaction time, visibility angle (we can assume that the robot can "see" objects only within some angle of the direction it is moving), etc. You also can assume that all these features are provided by additional objects (sub-objects of the robot) the robot can buy. Use your imagination, think what features would be interested to add in the future.


* The idea is from C++ and Object-Oriented Programming by Kip R. Irvin.