![]() I'd create methods of the conditions: instead of writing else if (y game. In this class the update method looks rather confusing with all the if-statements and the math in their conditions. I won't go into this with any more detail, but you should think this through and read about it. The logic of the game stays the same no matter how fancy or crude the game actually looks, and this should be reflected in the design so that the classes with the logic should not change when the appearance of the game changes. The ball and the rackets should not need to know how they are rendered, the user interface should take care of that. This is against the principle of separating the business logic and the presentation logic. ![]() The problem with the method is that it asks the ball and the players for them to paint themselves. :)Īt the end of the class there's the paintComponent method that correctly does have the annotation. It requires to install JDK version 1.3 or more before installing BlueJ. It is a free Java environment started in 1999 by Michael Kolling and John Rosenberg at Monash University, Australia, as a successor to Blue. Remember, bits and bytes aren't expensive to store, you can use as many of them as is required to get clear and self explaining method names. Practice BlueJ is a windows based platform for Java Development Kit (JDK). Contrast that with increaseScore(PlayerId.TWO), or perhaps with even renaming the method: increaseScoreForPlayer(PlayerId.TWO). This would also make the increaseScore method more readable, as currently increaseScore(2) looks like you'd increase the score by two points, whereas actually you are increasing the score for player two. Public class PongPanel extends JPanel implements ActionListener, KeyListener next to the class fields, and change the method signatures from something like getPlayer(int playerNo) to getPlayer(PlayerId player). Private final static int WIDTH = 700, HEIGHT = 450 ![]() ![]() I have recently written the following Pong game in Java: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |