I'm also working on a game project, and I'm stuck. I guess I'll have to post the specs so you guys can see what I have to do.
Here are the specs:
The valley floor can be viewed as a 10 by 10 grid. The northwest corner (upper left on the screen display) is consider to have coordinates (0,0). The northeast corner (upper right) is (0,9), the southwest is (9,0) and the southeast is (9,9). At any time, each robot is at one of the 100 grid points, facing north, east, south, or west. More than one robot may occupy the same spot. Each time a step elapses in the history of the valley, every robot with any energy remaining may turn and then move one grid unit in the direction it is facing. A robot starts out with 60 units of energy, and each attempt to move costs it one unit of energy. A grid point in the valley may contain an energy source, and if a robot arrives at such a point, its energy level goes back up to 60.
The program skeleton you are to flesh out defines three classes that represent the three kinds of objects this program works with: Valley, Robot, and EnergySource. Details of the interface to these classes are in the program skeleton, but here are the essential responsibilites of each class:
* When a valley object is created, it has no robots or energy sources.
* When a valley object goes away, any robots or energy sources it contains must be destroyed.
* A robot may be created and added to a valley object.
* An energy source may be created and added to a valley object.
* A valley object may be displayed on the screen, showing the locations of the robots and energy sources, and the energy remaining for each robot in the valley. (If a robot is at an energy source, only the robot appears in the display; if two robots are at the same spot, only one of them appears in the display.)
* Given a robot, a valley object may be asked if there is another robot at the same location as the one given.
* A valley object may be asked if there is an energy source at a given position.
* A valley object may be told to direct each robot in the valley to take a step.
* This simple class merely records and reports an energy source's position.
* A robot is created with a name, a position, and the direction it is initially facing. A robot starts life with 60 energy units.
* A robot may be told to take a step. A robot with no remaining energy will not move. Otherwise, the robot will attempt to move. In detail, this means: With 1/3 probability, the robot will pick a random direction to face; otherwise, it will stay facing in its current direction. The robot will attempt to move one grid unit in the direction it is facing. (It may not be able to move if its way is blocked by the mountains at the edge of the valley.) The move attempt costs one energy unit. If the robot moves onto an energy source, it is recharged to 60 energy units. If a robot with at least 30 energy units moves onto a spot occupied by a robot with 0 units, it will transfer 10 units to that other robot to give it a chance to get to an energy source.
* Robots have no memory of where they've been or what they've seen there. Robots don't know where other robots are; at best, a robot may find out from the valley object it belongs to what other robot, if any, is where it's currently standing.
* If when a robot takes a step, it arrives at a spot where there are at least two other robots, we'll keep things simple: it finds out about one of them and donates energy if appropriate. Then it's done with its step. It does not try to check for other robots at that spot.
You must not make any deletions, additions, or changes to the public interface of any of the classes -- we're depending on them staying the same so that we can test your programs.
I will post my code below.