## Homework Assignment 6

### RobotWorld

#### Introduction

Let's continue with you designing and building classes of your own. As always, feel free to ask questions early and often!

RobotWars was a fairly simple computer game that I remember playing in the early 80s.  While I haven't been able to find a copy of it to show you, I have found a "pirate-ey" version called "Seven Seas" that you can play online at PopCap games (http://www.popcap.com/launchpage.php?theGame=sevenseas).  You can also play a version that Dr. Schafer coded up .

The game is played on a grid and has fairly simple rules.  You move a friendly robot around the grid.  There are a variety of obstacles on the grid that can either help you (portals) or hurt you (junk piles and evil robots).  Furthermore, the evil robots pursue your friendly robot.  They too are effected by the portals, junk piles, and other robots. Your goal is to move around the board, avoiding things that hurt you while causing the evil robots to crash into junk piles and each other.  If you can cause all of the evil robots to crash, then you win the game.

#### Task - Implement a version of RobotWars.

You will be constructing your own version of this game for this assignment.  I will STRONGLY encourage you to write your code for this homework using incremental development.  That is, think about the game as a series of small steps, and make sure that you have completed each step before you move on to the next step.  In fact, you may want to save a backup file after each step so that you have something to turn in if you can't make adequate progress on the next step.  I will grade this lab, as a combination of how many steps you get completed, and how well you have used the object oriented design principles.

1)  Set up the basic game board and user interaction

Implement a version of RobotWars that uses the following guidelines

• The game is played on a 12x12 grid.
• You control a single, friendly robot which israndomly  placed on the board at the start of each new game.
• Each time the friendly robot "moves" he may move to either one of the 8 adjacent squares, or he may stay where he is.  [Why this counts as a "move" should be clear later].
• Your game should include a button which generates a new game.
• Your game should include a mechanism for displaying messages.  These can include messages about the status of the game, directions, or "errors" when the user tries to make an illegal move (remember you can only move to one of the 8 adjacent squares or stay where you are).
You may use any method to gather user input that you like -- mouse events, button events, keyboard events, etc.  Just make sure it is clear to the user how the robot is moved.

There will be four portals in our version of this game, located in the four corners of the playing grid.  If your robot moves onto a portal, it is randomly transported to one of the empty squares on the grid.

3)  Add in the dangerous scrap piles and evil robots

Whenever a game is started, you should generate three "scrap piles" and three separate "evil robots" at random locations on the screen.

4)  Configure the evil robots so they pursue your friendly robots.

After you move your robot (and after he is transported if applicable), the evil robots pursue you.  They do this by moving exactly one square towards you in one of the 8 possible directions.  The screenshot below illustrates the possibilities

• If the robot is  in the same row as your new location, it  moves one square horizontally towards you.
• If the robot is  in the same column as your new location, it moves one square vertically towards you.
• If the robot is  not in either the same row or column as your new location, it moves one square diagonally towards you.

5)  Complete the functionality

At this point you should be able to move around the screen and have the robots pursue you, but we haven't implemented any concept of winning or losing yet.  After everyone has moved there are three possibilities - you won, you lost, or the game is still in progress.

The detection of what happened should take place in the following order (some of which you may have already provided).

• If your robot moves onto a square occupied by a portal, it is randomly transported to one of the empty squares on the grid.
• If your robot moves onto a square occupied by an evil robot or a scrap pile, your robot crashes and the game is automatically over.
• If neither of these things happen, then the evil robots pursue you.  If after moving, an evil robot finds himself:
• on a square with you, the game is lost.
• on a scrap pile, he crashes in the pile and is no longer part of the game.
• on a square with another evil robot, they both crash into a newly formed scrap pile.
• [Technically speaking, it is impossible for an evil robot to move onto a portal given the previous rules].
• If all of the evil robots turn to scrap before your friendly robot does, then you win the game.
• The game continues until either you lose or you win.
How complex does my game/code need to be?

You do not need to use fancy graphics to represent the different robots, portals, and scrap piles.  Simple colored circles and/or squares should be sufficient to make the point.

You may design and implement your game in any object-oriented fashion. Keep in mind that, once we have a program built to play the game, we might want to give the player the chance to customize the game in a number of ways. For example:

• Change the size of the playing grid
• Change the number and location of the portals.
• Change the number of scrap piles or evil robots
• Add in new "obstacles" or other evil robots that follow different movement schemes (if you play Seven Seas enough, they introduce ships that move mostly on a diagonal).
• Allow two friendly robots to play in the same grid.  The players alternate who gets to move and the evil robots always pursue the player who just moved.  The goal could be that you work together to kill all the evil robots, or the goal could be to get the evil robots to get your opponent first.
You are not required to implement a program that supports these "extra" features, but you should should design your program with future extensions in mind.

Of course, you may go beyond the bare minimum of the assignment and choose to implement some of these features. If you do, I'll give you extra credit for your extra effort!

If you do look at either Seven Seas or Dr. Schafer's version, please do not feel that you should limit your interface to the interface they used. In fact, do not submit a solution that looks exactly like either.  Have some fun, use your creativity, and create an interface that takes advantage of Java's capabilities, and your interests.

#### Deliverables

By the due date and time, submit the files:

• README.txt - include a list of all classes in your solution in some meaningful order, along with a 1- or 2-line description of the role of each.
• RobotWorldDriver.java
• RobotWorld.java
• any other files you need to submit, in a logical order