Saturday, May 19, 2007

PA4 FAQ (Part I)

Q: Who will be the grader for this project?
A: Daniel. So, questions regarding the requirement and grading criteria should be directed to him. (and be nice to him :)

Q: Should I work on this project in Unix?
A: No, you shouldn't. It is a little tricky to get graphic programs running remotely on a unix machine. You will need an X Windows server installed on your computer, and you will have to do some simple configurations. (I probably can show that in my office hours if you are really interested.)

Q: Is MouseMotionListener needed?
A: No.

Q: I have no idea where to start. Can you help?
A: I would take the following steps...
1) Develop an applet that allows users to play the game. Don't worry about the buttons. Don't worry about the status messages at the bottom.
2) Add the status bar message by using the showStatus method.
3) Add the status message (Move #, % red, % green, whose move it is). There are (>=) two ways you can do this: by using JLabel or by calling drawText method from inside the paint method. I think drawText is simpler.
4) Put the four buttons at the bottom. Use setLayout(null) and setBounds to specify the locations of each button.
5) Implement each button's functionality. Start with the Reset button, then the Color button, and the Computer vs. Human button.
6) Test everything. Write the README.txt file. Test everything again.
7) Attempt the extra credit only if you are sure everything else is working correctly.
8) Turn it in and smile :)

Q: Step 1 seems like a big step. I don't know how to do it. Can you help?
A: Here you go ...
[Spoiler Warning!]

Monopole is your main applet. The logic of the main program is here. The paint method is here. Think about other classes as helper classes. Write them and use them at your discretion. The recommended classes are explained on the assignment sheet.

Can you get by with putting everything on Monopole.java and not writing other classes? Yes, you can probably make your program work, but it'll probably be messy and your style points may suffer (up to Daniel's judgement).

Here is how I would do it. Keep in mind that there is no need to follow me. This is just an example, and it may not even be the best one.

I will develop a simple applet that accepts the mouseClicked event. I'm not worried about the colors, the Square, and the Board at this point. I will first try to keep track of all the poles that the users place on the board.

I will write a simple class Move that contains the x, y coordinates of each move, and the type of the charge (positive or negative). Then I will declare a 1-dimensional array of Move (and call it moves) -- the size should be at least 42. I will need another integer to keep track of how many moves are currently stored.

Whenever the user clicks at some point, I'll create a new Move and append it to the moves array. Now, to visualize it, I override the paint method of the applet. I paint a circle for each of the move.

I have got a simple applet that interacts with the user. Now it is not hard to write the Board class which contains a 150x150 array of Squares. Each square should contain its coordinate on the board, as well as a value of type double to store the net charge acting on it. Each time the user clicks on the board, I can re-evaluate the whole Board and draw a little rectangle (using fillRect method) on the screen for each of the squares, with the color depending on the net charge.

After this point, it's not so complicated.

Q: Can I have more hints?
A: My next office hours are 3-5pm on Monday, and the extra office hours are:
Tuesday, May 22: 1 PM - 4 PM (Daniel)
Wednesday, May 23: 10 AM - 1 PM (Mock)

Dr Jacobson added that:

"It is ok to get a 0 on this project. Not everyone in the class is a CS
major. Not everyone is expected to be able to do every project. Just DON'T
COPY anyone's work, do your best, and remember, the class is curved."
:)

No comments: