Due Date: Monday, September 23rd, 11:59 pm EST
Watch the demo here!
Silly Premise
Collaboration Policy Reminder
New Concepts Covered
Helpful Resources
Installing Stencil Code
Grading
Coding Incrementally
Compiling and Running Your Code
Suggested Order for Incremental Coding
Saving Your Work on GitHub
**Minimum Functionality Requirements**
Full Functionality Requirements
Stencil Code vs. Support Code
Stencil Methods
**Javadocs**
Boolean Type
Tip: Printlines
Writing a Helper Method
Association
Aang and his old friend Bumi had a game that they loved to play back in the good ol' days in Omashu. It involved a paddle and a cabbage that they would hit back and forth, using airbending. That was over 100 years ago, so Aang wonders if there is any way to modernize his favorite game. Instead of airbending, you'll be using Java to power your very own game of Pong.
Reference: Avatar the Last Airbender, Nickelodeon
If you ever have questions about the collaboration policy, refer to the collaboration policy or ask a TA!
Click here to get the stencil from GitHub - refer to the CS15 GitHub Guide for help with GitHub and GitHub Classroom. Once you have the URL of your personal GitHub repository, open the IntelliJ terminal. Move into the src/
folder, then use the command git clone <URL>
Once you’ve cloned your personal repository from GitHub, you’ll need to rename the folder from pong-<yourGitHubLogin>
to just pong
. You will have issues running your code until you make the change.
The grade for this assignment will be determined by functionality (60%), design (25%), and style (15%). An ‘A’ project would meet mostly all full functionality requirements with good design and style.
Watching the demo will give you a better understanding of your task; we strongly recommend you do this as soon as you can.
For this assignment you’ll implement a version of one of the earliest arcade video games: Pong! The 2-player game consists of 2 CS15Paddle
s and a CS15Ball
that bounces across the screen. When the ball collides with a paddle, the ball rebounds in the opposite direction.
The left player controls the left paddle by using the W key for up and the S key for down. The right player controls the right paddle by using the Up arrow key for up and the Down arrow key for down.
Whenever the ball moves offscreen, the player on the opposite side from which the ball exited gets one point (i.e., if the ball moves off the right side, the left player gets one point, and vice versa). The next round then starts immediately with a new ball that moves toward the player who just received a point (e.g., if the ball moves off the right side, the new ball starts moving toward the left side, and vice versa).
Once one player reaches five points, that player wins and the game ends!
After you’ve watched the demo, thoroughly read this handout and the Javadocs in full to make sure you understand the project. Once you’re ready, start coding! It is important to code incrementally, meaning you completely accomplish one logical task before moving on to the next one.
Most importantly, incremental coding means that you run your code after each step to ensure it’s working as you want it to! Refer to the Rattytouille handout for more detailed instructions on how to compile and run your code. Here is a summary:
1. cd pong
2. javac *.java
3. cd ..
4. java pong.App
5. Repeat!
Step 1. Run the stencil code to see the empty game screen.
Step 2. Instantiate the top-level PongGame
class for the score labels to appear.
Step 3. Instantiate one paddle so that it appears on-screen. Make sure to import the necessary class!
Step 4. Make the paddle respond to key presses to move up and down.
Step 5. Repeat steps 3 and 4 for the other paddle.
Step 6. Add a ball to the game.
boolean
is fine!Step 7. Get the ball to move across the screen.
Step 8. Make each of the paddles check collisions with the ball so that the ball rebounds on contact.
Step 9. When the ball goes offscreen, you should update the score labels so that the opposite side receives one point, create a new ball that moves in the direction of the player who received a point, and check if a player has won.
Use the int
type. You can think of the score as a “property” of the game.
Refer to the CS15 GitHub Guide for more detailed instructions on how to save snapshots of your work to GitHub. We recommend doing this around once an hour to make sure you’re maintaining a copy of your code. Here is a summary:
git add -A
git commit -m “<some descriptive message>”
git push
MF Policy Summary: In order to pass CS15, you will have to meet minimum functionality requirements for all projects. If you don’t meet them the first time around, you may hand the project in again until you succeed, but you will keep your original grade. MF requirements are not the same as the requirements for full credit on the project. You should attempt the full requirements on every project to keep pace with the course material. An ‘A’ project would meet all of the requirements on the handout and have good design and code style.
To meet MF for Pong:
Beyond the minimum functionality requirements, the rest of the functionality grade will depend on the following criteria:
We provide you with both stencil code and support code.
Stencil code refers to incomplete or partially written classes and methods which comprise the skeleton/framework of the program. You should never delete code that was given to you as stencil code — it is there to help you! You will be adding your own code to the stencil code that we provide. For this project, the stencil classes that you should fill out are App
and PongGame
.
On the other hand, support code is “black box” code that you must use but won’t be able to change and whose internals you won’t even be able to see. In other words, we’ve written “invisible” classes and methods for you that you should use according to the Javadocs provided! Some classes (PongGame
) have support code methods that you should call from methods within those classes (like MazeSolver
in AndyBot!). There are also entire support classes that are “invisible” to you (CS15Paddle
and CS15Ball
), but you will have to create instances of those classes (like CS15Robot
). The Javadocs describe what the support code does and how to utilize it. More on Javadocs below!
In short, we’ve written most of the code for a pong game to operate in the support code. Your job is to connect all the pieces together by filling in the stencil code.
Very Important: You should never rewrite support code. It is pre-written (and “invisible”) so that you can use it without worrying about how it actually works. It’s the ✨ magic ✨ we love!
The stencil methods in PongGame
are automatically called by the support code for you in specific scenarios. That means for this project, you should never call any of the stencil methods yourself! Again, because each of these 7 methods is called by the support code, you should not call the methods. You should just define these methods. You can find which methods are specifically stencil methods in the Javadocs.
The Javadocs have a list of all the classes and what they do, including support classes and methods, which you cannot see but must use! The Javadocs contain information that you cannot find in this handout - you will have much trouble implementing this project if you haven’t thoroughly read the Javadocs. When in doubt, first check the handout, then the Javadocs.
Notice that since CS15Paddle
and CS15Ball
are support classes, they have no stencil methods at all. Also notice that both the CS15Paddle
and CS15Ball
constructors are considered support methods since you should instantiate those classes yourself.
In computer science, the data type known as boolean
refers to a piece of data that can either have the value true
or false
. Just like we can declare and initialize a variable of type integer like:
int x = 3;
int numObstacles = 20;
We can similarly declare and initialize a variable of type boolean like:
boolean x = false;
boolean playerIsAlive = true;
You’ll notice that the constructor of both the CS15Paddle
and CS15Ball
require an argument of type boolean
, to denote left or right! The Javadocs provide more guidance on exactly when to use true
or false
.
We’ll learn more about the boolean
type later in the semester during the “Math and Making Decisions” lecture.
If you find yourself confused about when a particular method is called by the support code, fill the method body with a printline! By using the System.out.println()
method, you can see what’s printed in the terminal to understand when particular methods are called.
When implementing the functionality for starting the next round of Pong, you’ll notice there will be a few lines of code repeated in the ballOffScreenLeft
and ballOffScreenRight
methods (creating a new ball, updating the score labels, and checking for a winner). A good coding practice is to factor out repeated lines of code into “helper methods”. Although not used to avoid repeating code, the solveRoadblock
method from AndyBot is one example of a helper method.
To practice writing your own methods, for this project you must write a helper method as part of the round restart functionality, and you must call the method from the ballOffScreenLeft
and ballOffScreenRight
methods.
The method may need to take in a parameter to indicate in which direction the next ball should start moving. Think about what parameter type the CS15Ball
and CS15Paddle
constructors use to denote left or right.
Refer to the coding incrementally step 9 about specifically what should happen to start the next round.
The use of this helper method (and avoiding redundantly repeating lines of code) will be factored into the “design” portion of the grade.
Later in the course, you’ll have to plan your own design for programs, using concepts we cover in these early projects. One of those most important concepts is association! For this assignment, there is a correct way to implement the hierarchical structure of your program (since we provide you with support code that simulates most of the game), but soon the modeling and delegation decisions will be up to you!
As practice for future projects, you’ll need to create a class diagram that represents the design of this program and submit it in your final submission. Be sure to include both stencil classes and support classes in the diagram. This diagram will be factored into the “design” portion of the grade.
To make your diagram, we recommend using Google Docs/Slides/Drawing or paper and pencil. Be sure to upload your diagram to your GitHub repository. In your Pong GitHub repository, choose Add file and then Upload Files. Upload your diagrams here. Make sure your diagram is a .pdf, .jpg/.jpeg, or .png file. If you submit a different file format, it may be unsupported by Gradescope so you will receive no credit for the diagram.
Refer to the CS15 Style Guide for the specific style guidelines along which your code will be graded for the “style” portion.
Starting with this assignment, you should add method comments for all public methods as well as class comments for all classes. We’ve provided class comments for App
and PongGame
, as well as a method comment for onWPressed
, which you can use as an example for your own method comments. Be sure to read the CS15 Style Guide in order to apply proper comment formatting!
In CS15, you’re required to hand in a README file (must be named README) that documents any notable design choices or known bugs in your program. Remember that clear, detailed, and concise READMEs best allow your TAs to understand your thought process, helping them better understand your project as well.
You are expected to create your own README file. Please refer to the README guide for information on how to create a README, what information your README should contain, and how you must format it.
At the bottom of your README, add the approximate number of hours you spent on this homework. This will be used only to average how long the homeworks are taking students this semester, and it is completely anonymous.
To hand in your assignment, follow these steps:
pong
folder as if you were about to compile your coderm *.class
(Mac) or del *.class
(Windows)
.class
files that are created when compiling so that your submission only includes .java
code files.Please do not include any identifying information on your hand-in (name, login, Banner ID) as we grade anonymously. Including identifying information will result in a deduction from your assignment. If you submit before the deadline and again after the deadline, the submission will be counted as late.