Date: Thu, 27 Mar 2003 13:15:03 -0600 (CST) From: Mark Jacobson To: 810-061-02@uni.edu Subject: How to do the line for Boxball group exercise... Hi Java students, Three different approaches came out of the SASP (Solve A Simpler Problem), exercise in today's class. First, let me describe the "simpler, but related problem" we worked on: Note: Please look at the Boxball game assignment link at the class web page, at http://www.cns.uni.edu/~jacobson/061/applets/ver2Boxball/Boxball.html from http://www.cns.uni.edu/~jacobson/061/BoxBallGame.html linked from the class web page at http://www.cns.uni.edu/~jacobson/061 Then you will see how the click above the line game is a simpler but related problem: Approach #1: Use a Line to implement the horizontal clicking line that the user either clicks above or doesn't click above. How does this effect the need to raise the line's height by 5 or 10 or 20 units each time the user clicks inside a FilledRect with a Text message saying "Raise the Line" or whatever? ----------------------------------- <==== Line user clicks above Your last click was BELOW the line. Try again. -------------------- | Raise the line | -------------------- Approach #2: Use a FilledRect or a FramedRect with a height of only 1, which looks exactly like a Line object, but adds the extra capabilities of 2-D objects from objectdraw.jar package of William's College. Since .getX() and .getY() are NOT allowed as methods for objects of the Line class, but are OK for Rect objects, this will save us having to have an extra variable keeping track of the theYforLine, for example. Hooray! ----------- This approach is a different way of thinking about the problem, which does offer some convenience to the Java programmer, not that approach #1 is bad. But the creativity of thinking of this approach is very useful, and its always great to try to think of another way to solve a problem. Approach #3: Use a FramedRect object on top of or after the first FramedRect, which would be maybe called gameBoundary. FramedRect gameBoundary, clickAreaAboveLine, raiseHeightButton; Now all you have to do is see if the clickAreaAboveLine FramedRectangle .contains( pointWhereClicked ) and your just need to change the height of the clickAreaAboveLine rectangle with the appropriate method to make the line appear to raise up higher on the game board or game canvas. 2 S P or SSP or SASP can be an acronym for solve a simpler problem. - - - - - - - Its a useful approach. Now look over your assignment and see how this simpler problem relates the the entire project for the Boxball game and get it working that far before Tuesday's class, and you will be well on the way to getting the project working by Friday of next week. SASP is a very useful problem solving strategy to use. Mark