Object-Oriented Language Development Company

Similar documents
Express Yourself. Writing Your Own Classes

CS 170 Java Programming 1. Week 12: Creating Your Own Types

Programming via Java User interaction

ICS 61 Game Systems and Design Introduction to Scratch

Lab 8. An Introduction to Objects

CS 134 Programming Exercise 3:

CISC 1600, Lab 2.3: Processing animation, objects, and arrays

Pong in Unity a basic Intro

[ the academy_of_code] Senior Beginners

1 Getting started with Processing

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

BSc (Hons) Computer Science with Network Security/ BSc (Hons) Software Engineering/ BSc (Hons) Web Technologies. Examinations for 2016 Semester 1

Creating Breakout - Part 2

Name CMPS 5J Final March 17, 2009 This is a closed notes, closed book exam.

Basic Computer Programming (Processing)

Assignment #3 Breakout!

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

10.2 Basic Concepts of Limits

Programming Project 1

XNA (2D) Tutorial. Pong IAT410

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

Assignment A7 BREAKOUT CS1110 Spring 2011 Due Fri 6 May 1

Platform Games Drawing Sprites & Detecting Collisions

University of Palestine. Mid Exam Total Grade: 100

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Collisions/Reflection

Pong Pong Revolution: Project Proposal

1. Defining Procedures and Reusing Blocks

Slide 1 CS 170 Java Programming 1

1 Getting started with Processing

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

Lecture Set 4: More About Methods and More About Operators

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

CS 1510: Intro to Computing - Fall 2017 Assignment 8: Tracking the Greats of the NBA

Coursework summary. Using Microsoft Visual Studio document Game framework. Wraps up SDL (Simple DirectMedia Layer)

Lesson 18: Animation. Computer Programming is Fun!

Instructions. Objectives:

Adapted from slides by Brahm Capoor. Breakout YEAH hours. Michael (Chung Troute)

Visual C# Program: Simple Game 3

Load your files from the end of Lab A, since these will be your starting point.

Detailed instructions for video analysis using Logger Pro.

G51PRG: Introduction to Programming Second semester Applets and graphics

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

CSE 1102 Fall 2009 Lab Assignment 2

Pong. CSEE 4840 Spring 2012 Project Deisgn. 1 Introduction. Bo Li(bl2438) Jihong Zou (jz2428) Cong Liu (cl2991) Zuyang Cao (zc2220)

JFrame In Swing, a JFrame is similar to a window in your operating system

Pong. Prof Alexiei Dingli

Slide 1 CS 170 Java Programming 1 Testing Karel

Structured Programming Using C++ Lecture 10 : Graphics Programming with the Dark GDK Library. Dr. Amal Khalifa. Lecture Contents:

Overview of Computer Graphics

1.00 Lecture 8. Using An Existing Class, cont.

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

S3 Scratch Programming

Velocity: A Bat s Eye View of Velocity

Objects and Classes (1)

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

CS 115 Exam 3, Spring 2011

CS Problem Solving and Object-Oriented Programming

CS61B Lecture #3. Homework: Please see Homework #1 on the lab page. Last modified: Wed Sep 10 20:34: CS61B: Lecture #3 1

COMP 111. Introduction to Computer Science and Object-Oriented Programming. Week 3

To Measure a Constant Velocity. Enter.

Derived and abstract data types. TDT4205 Lecture 15

Lab 9: Creating a Reusable Class

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Introduction to Computers and Java

Breakout YEAH hours. Brahm Capoor & Jared Wolens

3. Text to Speech 4. Shake it

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods

The Projection Matrix

Java GUI Test #1 Solutions 7/10/2015

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

CS 463 Project 1 Imperative/OOP Fractals

CISC 1600, Lab 2.1: Processing

2IS45 Programming

5.1. Examples: Going beyond Sequence

CompSci 230 Software Construction

Public-Service Announcement

1. Complete these exercises to practice creating user functions in small sketches.

CIS March 1, 2018

CS 134 Programming Exercise 9:

Constants are named in ALL_CAPS, using upper case letters and underscores in their names.

COMP 40 Assignment: Interfaces, Implementations, and Images

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

COMPUTER APPLICATIONS

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

CS 305j Midterm 1 Fall 2006

Iteration in Programming

Graphical User Interfaces 2

Create a memory DC for double buffering

Introduction to Game Programming

Using the API: Introductory Graphics Java Programming 1 Lesson 8

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

CS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java

Understanding an App s Architecture

Making use of other Applications

CSE 142 Su 02 Homework 4

Creating Java Programs with Greenfoot

2.4 Input and Output. Input and Output. Standard Output. Standard Output Abstraction. Input devices. Output devices. Our approach.

Transcription:

Object-Oriented Language Development Company The OLD Co Pong Game: Executive Summary The Object-Oriented Language Development Company (OLD Co.) has begun development of a radically new computer game, with the wholly original name of Pong. Pong is a two player game in which each player attempts to prevent the pong-ball from reaching the wall behind his pong-paddle. A player deflects the pong-ball before it reaches the wall by placing his pong-paddle into path of the pong-ball. This causes the ball to bounce off of the paddle in the opposite direction. If the ball reaches the wall behind a player's paddle, then the opponent scores. The number of points scored is dependent on the region of the wall contacted by the ball. The closer to the center of the wall the greater the number of points scored. The high-paid software engineers at OLD Co. have spent years designing the Pong program. They have identified the classes that describe the objects the program will use. They have carefully defined the public interfaces of each of the objects. The specifications for these classes were handed off to the programmers who completed the majority of the implementation. However, just before the project was completed, all of the programmers were offered huge salaries by Google and they simply quit on the spot! I've agreed to write these classes for OLD Co. But being, ever the educator, I decided that writing these classes would be a good experience for you. Of course, I get to keep the check from OLD Co!) The remainder of this document describes the classes you'll need to write to complete the Pong game.

The PongBall Class: Description: The PongBall class describes the object which the Pong application uses to represent the ball that bounces around the screen. The following class diagram illustrates the information and operations that are defined by the PongBall class. When the Pong application is executed it creates a new PongBall object that is positioned at the center of the playing field. Approximately every 10th of a second the Pong application calls the move() method on its PongBall object causing the ball to update its position. Following the call to move() the Pong application uses the getx() and gety() methods to find the new location of the ball. If the Pong application determines that the ball would have collided with a wall or a paddle it will invoke the bouncex() or the bouncey() method to change the horizontal or vertical direction of the ball. Finally, the Pong application will draw the ball on the screen at its new location and the process will be repeated again in another 10th of a second. Implementation: To implement the PongBall class you will need to define instance data for the x and y position of the ball as well as the velocity of the ball in the x and y directions. Your implementation of the PongBall class must meet these specifications, so please study them carefully. Constructor: construct a new PongBall with the specified initial position and velocity. Construction Parameters: initx - the initial X position of the new PongBall. inity - the initial Y position of the new PongBall. initxvel - the initial velocity of the new PongBall in the X direction. inityvel - the initial velocity of the new PongBall in the Y Direction. Public Interface Specification: void bouncex() - Reverse the X direction of this PongBall. This method is invoked by the Pong application each time this PongBall collides with a vertical obstruction such as a wall or paddle. The X direction can be reversed by changing the sign of the X velocity. void bouncey() - Reverse the Y direction of this PongBall. This method is invoked by the Pong application each time this PongBall collides with a horizontal

obstruction such as a wall or the top/bottom edge of paddle. The Y direction can be reversed by changing the sign of the Y velocity. int getx() - Return the current X position of this PongBall. int gety() - Return the current Y position of this PongBall. void move() - Move this PongBall according to its current velocity. This method is invoked at a regular rate by the Pong application in order to update the position of the ball. The X position changes by the velocity in the X direction and the y position changes by the velocity in the Y direction. Testing: Before we accept your code, we must be certain that it meets the specification. Since you do not know precisely how the Pong application uses the PongBall class, it would be very difficult to determine simply by watching the Pong application if the PongBall class behaves correctly in every situation. Thus, before adding the PongBall class to the Pong application you will need to test its behavior independently by passing a unit test. To test the PongBall class you will need to write a class named PongBallTest that contains a main method. The main method in the PongBallTest class should create several PongBall objects and test their instance methods by comparing the expected state of the object with the actual state. For example, the following snippet of code will create a PongBall object and test the getx(), gety() and move() methods: public class PongBallTest { public static void main(string[] args) { PongBall ball = new PongBall(10,20,2,4); System.out.println("x should be 10, x is: " + ball.getx()); System.out.println("y should be 20, y is: " + ball.gety()); ball.move(); System.out.println("x should be 12, x is: " + ball.getx()); System.out.println("y should be 24, y is: " + ball.gety()); } } ball.move(); System.out.println("x should be 14, x is: " + ball.getx()); System.out.println("y should be 28, y is: " + ball.gety());

Notice that the output of the test program indicates both the correct values and the actual values that are computed. Writing your test programs in this way makes it easy to tell if the class you are testing is working correctly. You will need to add additional code to the PongBallTest class to test the bouncex() and bouncey() methods. Integration: Once you have fully tested your PongBall class you can integrate it into the Pong application. To integrate your PongBall into the Pong application copy PongBall.class from your working directory into the Pong directory, overwriting the old, non-functional PongBall.class. (If your program becomes non-functional, you can copy a fresh version of the Pong game from the Q: drive.) Now when you open the Pong project in BlueJ and start the problem, press the "B" key on the keyboard and the ball should begin bouncing around the playing field. The PongScore Class: Description: The PongScore class describes the object that the Pong application uses to keep track of the score for each player. The following class diagram illustrates the information and operations that are defined by the PongScore class. When the Pong application is executed it creates two PongScore objects, one for the blue player and one for the green player. Each time the ball contacts the end wall behind the blue paddle, the scorepoints(...) method of the green player's PongScore object is invoked, and vice versa. When invoking the scorepoints(...) method, the Pong application passes it an argument (or parameter) corresponding to the number of points indicated in the region of the wall that was contacted. The Pong application will then invoke the getscore() method to determine the score to be displayed beside the player's name below the playing field. Implementation: Implement the PongScore class in the file PongScore.java in your working directory. Your implementation must meet the specifications given below.

Constructor: construct a new PongScore with an initial score of zero points. There are no construction parameters. Public Interface Specification: int getscore() - Return the current score of this PongScore object. void scorepoints(int points) - Increase the current score of this PongScore object by points. o points - the number of points to add to the score. Testing: To test the PongScore class you ll use the Unit Testing framework called JUnit, which is built in to BlueJ. Create a test class named PongScoreTest. In your test fixture, you ll need to create at least one PongScore object. Your test methods should examine both the initial state of the object after construction, as well as calling the scorepoints(...) method with several different arguments. Use assertions to compare the values that you expect your PongScore object to contain with its actual values. Correct your implementation if the two values are different. Integration: Once you have fully tested your PongScore class you can integrate it into the Pong application by copying the PongScore.class file from your working directory into the Pong project, overwriting the old, non-functional PongScore.class. When you open the Pong project in BlueJ, run the Pong application and press the "B" key, the ball will again begin to bounce around the playing field. However, now each time the ball contacts the end wall the opponent's score will be incremented by the appropriate number of points. The PongPaddle Class: Description: The PongPaddle class describes the objects that the Pong application uses to keep track of the size and location of the pong paddles. The following class diagram illustrates the information and operations that are defined by the PongPaddle class. Each PongPaddle has an (x,y) position that indicates the position of the top-left corner of the paddle. Each PongPaddle also has a width and a height. When the Pong application is run it creates two new PongPaddle objects: one for the blue player positioned at the left end of the

playing field, the other for the green player positioned at the right end of the playing field. When the blue player presses the "A" key, the Pong application invokes the moveup(...) method of the blue player's PongPaddle object. Conversely, when the blue player presses the "Z" key the Pong application invokes the movedown(...) method. Similar actions are taken using the green player's PongPaddle object when the "M" and "K" keys are pressed. The Pong application then uses the getleftx(), gettopy(), getrightx() and getbottomy() methods to determine where on the screen the blue and green paddles should be drawn. These methods are also used by the Pong application to determine when the ball collides with one of the paddles. Implementation: Implement the PongPaddle class in the file PongPaddle.java in your lab5 directory. Your implementation must meet the specifications given below. Constructor: Construct a new PongPaddle at the specified position with the specified width and height. Construction Parameters: top - the Y coordinate of the top left corner of the new PongPaddle. left - the X coordinate of the top left corner of the new PongPaddle. w the width of the new PongPaddle, measured in pixels. h the height of the new PongPaddle, measured in pixels. Public Interface Specification: int getbottomy() - Return the Y coordinate of the bottom edge of this PongPaddle. int getleftx() - Return the X coordinate of the left edge of this PongPaddle. int getrightx() - Return the X coordinate of the right edge of this PongPaddle. int gettopy() - Return the Y coordinate of the top edge of this PongPaddle. void movedown(int pixels) - Move the position of this PongPaddle down by the specified number of pixels.. o pixels - the number of pixels to move down. void moveup(int pixels) - Move the position of this PongPaddle up by the specified number of pixels.. o pixels - the number of pixels to move up.

Testing: To test the PongPaddle class write a class named PongPaddleTest using BlueJ s JUnit testing facility. Be sure to create several PongPaddle objects and to call all of the instance methods several times with several different arguments (when appropriate). Integration: Once you have tested your PongPaddle class you can integrate it into the Pong application by copying the PongPaddle.class file from your working directory into your Pong directory. When the Pong application is run from BlueJ, pressing the "B" key begins the ball bouncing as before. However, now when the "A" or "Z" keys are pressed the blue paddle will move up or down. Similarly, when the "K" or "M" keys are pressed the green paddle will move up or down. Congratulations! You now have a complete working Pong application!