Robots game

Your goal in this lab is to design and write a program to play robots. This will be a graded lab which you'll work on in groups of two. (You may work on your own if you ask for approval in advance.) First, carefully plan out your program. Before doing any programming, you should get your plan endorsed.

Play robots

The UNIX program robots predates the ubiquitousness of graphical interfaces, so you have to play using keyboard input.

  1. In Emacs, type M-x man (for manual-page), and enter -M ~mc38/man robots. This gives your directions on how to play. (The -M ~mc38/man part says ``Please look for the man page in the MC38 directory.'')

  2. In a Unix shell window, type ~mc38/bin/robots.

Plan your program

Your goal is to write a program to play this game. Your game will use a graphical interface, and need not include all the options in the Unix version. You need not include a score file. But you will need to decide on how the user will input decisions on where to move and how to teleport.

Just as Horstmann plans out the Clock game in chapter 8, you should plan out your program. You should have at least two classes (probably more), and should plan on most of your code being in member functions (as opposed to non-member functions).

Decide in advance what order you will write your classes and functions. You don't need to program a whole class all at once. On the contrary, I recommend coding part of it, testing a bit, and continuing. Plan how you will test as you go along.

  1. Each card has a list of member functions and instance variables. (Instance variables are the private variables.)

  2. One additional card lists non-member functions (if any) along with the purpose of each.

  3. Number all member functions and procedures in the order you intend to code and test them. You'll put the number (1) in front of all methods and procedures you can test on their own without writing any others. Put a (2) in front of procedures you can't write until you've written procedures from (1), and so forth.

  4. Identify with a (*) all methods which appear challenging to write. These are ones which you hope you can break up later into smaller procedures once you've thought about the robots program more.
You must get your plan endorsed before continuing.

Write a working program

  1. Write a program to play the game. Be sure that the code is clean, and that all procedures are short and clear. (If you have time, feel free to add whatever features you think would enhance or personalize your program, but be sure your code is clean before embarking on ambitious plans.)

  2. Rather than documenting each little member function, place documentation for the class in the class's header file. So each class declaration will have at least one header comment, and each non-member function will have at least one header comment.

  3. Write a file called README which has the following:

Common problems

We'll maintain a list of common issues and problems here.

The program ~mc38/labs/robots/random_points.cc reads characters from the keyboard, and places those characters on random points in cwin. It demontrates how to address the first few problems below.

  1. How do I get input from the keyboard?

    See ~mc38/labs/robots/random_points.cc

    In particular, you need the system ("stty raw"); to let the computer know you want to read a character as soon as it's typed, and not wait for the "return" or "enter" key to be hit.

  2. How do I get the screen to update?

    Stuff isn't drawn until either (1) you do something like a cwin.get_point() or (2) you return from main() or (3) there are many things that need to be drawn (filling a buffer). If you include a loop which draws 50 points off the screen, the window will be forced to redraw.

          for (int i = 0; i < 50; i++)
             cwin << Point (-15,-15);
    

  3. What if the compiler gives a ton of warnings at link time?

    Maybe you forgot to include a library like -lX11. Check the compilation command your Makefile uses with care.

  4. What if at compile time stuff is defined more than once?

  5. Why can't I make a vector of objects?

    Perhaps you don't have a default constructor for that class, i.e., one which takes no arguments.

  6. What if I have a very mysterious error near the top of a file?

    Check the end of an included .h file. Perhaps you left a ; off the end of a class declaration?

  7. How do I change the graphics window size?

    In short, you can't. The graphics classes are limited for pedagogical reasons. The book describes all graphics classes in the appendix.