CS代写 Problem Overview

Problem Overview
You are required to design an application model for a pool table game. The pool game is played on a rectangular table with different colour of balls on it. This pool table has 6 pockets into which the balls can fall. All the balls are randomly placed on the table at the beginning of the game. Among all balls, there is a ball being the white cue ball. A player can only hit the white cue ball with the cue stick. If the balls approach the side of the table, they will bounce back. Balls also bounce off other balls. This is a single player game and is won when all the balls,
other than the cue ball, are in the pockets. Game is lost when the white cue ball falls into any of the pockets. The score is calculated when a ball falls into a pocket. Duration of the game is clocked until all balls are in the pocket.
Q: What is a pool table game?

Copyright By PowCoder代写 加微信 powcoder

A: Some real-world examples could be found here (Links to an external
site.) and here (Links to an external site.).
Assignment 2 Requirement
In assignment 2, you are going to implement your pool game and refactor your UML class diagram according to your code. You will need to ensure that your application is configurable with a JSON text file. You must use the GoF design patterns in your implementation as requested below:
• The configuration reader must use the Factory Method pattern with a
factory for each section of the JSON file.
• The balls must be created using the Builder pattern.
• Behaviour of balls after falling into a pocket will be controlled using
the Strategy pattern.
Please find the detailed tasks below:
Implementation Task
You will use the Java Programming Language to implement the UML class diagram you designed in assignment 1. In this assignment, you are now responsible for the implementation of the entire application code.
What we provide to you
• JSON file: an example JSON file format is provided to
you here Download herethat you can start with for your
implementing. A sample configuration reader is also
provided here Download herefor your consideration.

• gradle file: a sample build.gradle file is provided to
you here Download here.
• Collision Function: it may be helpful for you in your implementation.
o The following collision function allows your program to
calculate the resulting velocity changes after detecting a
collision between balls of arbitrary masses. You do not
need to understand how the mathematical works but you
will have to understand the initial properties and then
apply the resulting changes in velocities to the respective
* This is an updated collision calculation function for 2 balls colliding in
2D space. You may use it however
* you wish for your assignment.
* This uses the optimised physics algorithm discussed here:
* http://www.gamasutra.com/view/feature/3015/pool_hall_lessons_fast_accur
ate_.php?page=3
* which has been converted into Java/JavaFX
* @param positionA The coordinates of the centre of ball A
* @param velocityA The delta x,y vector of ball A (how much it moves
* @param massA The mass of ball A (for the moment this should always
be the same as ball B)
* @param positionB The coordinates of the centre of ball B
* @param velocityB The delta x,y vector of ball B (how much it moves
* @param massB The mass of ball B (for the moment this should always
be the same as ball A)
* @return A Pair in which the first (key) Point2D is t
he new delta x,y vector for ball A, and the second (value) Point2D is the ne
w delta x,y vector for ball B.
public static Pair calculateCollision(Point2D positionA, Poi
nt2D velocityA, double massA, Point2D positionB, Point2D velocityB, double m
// Find the angle of the collision – basically where is ball B relative to
ball A. We aren’t concerned with
// distance here, so we reduce it to unit (1) size with normalize() – th

is allows for arbitrary radii
Point2D collisionVector = positionA.subtract(positionB);
collisionVector = collisionVector.normalize();
// Here we determine how ‘direct’ or ‘glancing’ the collision was for e
double vA = collisionVector.dotProduct(velocityA);
double vB = collisionVector.dotProduct(velocityB);
// If you don’t detect the collision at just the right time, balls might c
ollide again before they leave
// each others’ collision detection area, and bounce twice.
// This stops these secondary collisions by detecting
// whether a ball has already begun moving away from its pair, and r
eturns the original velocities
if (vB <= 0 && vA >= 0) {
return new Pair<>(velocityA, velocityB);
// This is the optimisation function described in the gamasutra link. Ra
ther than handling the full quadratic
// (which as we have discovered allowed for sneaky typos)
// this is a much simpler – and faster – way of obtaining the same re
double optimizedP = (2.0 * (vA – vB)) / (massA + massB);
// Now we apply that calculated function to the pair of balls to obtai
n their final velocities
Point2D velAPrime = velocityA.subtract(collisionVector.multiply(optimized
P).multiply(massB));
Point2D velBPrime = velocityB.add(collisionVector.multiply(optimizedP).m
ultiply(massA));
return new Pair<>(velAPrime, velBPrime);
What we expect from you
Your pool game is now expected to support the following features in your code:
• The poor table can be created in different sizes, colour and friction
which must be configurable, defined in and read from the sample JSON
configuration file. The colour, initial position (as an x-y coordinate),
velocity and mass of a ball must be configurable, specified in and read
from the sample JSON configuration file.

• The Ball
o All balls must be able to bounce (e.g., bounce off the slides
of the table, and each other), and collide with realistic
o All balls will be slow down due to the friction of the
table. Friction can be implemented in any way, e.g. constant deceleration or deceleration proportional to velocity, as long as the balls come to rest.
o A single white ball, known as the cue ball. The velocity
(speed and direction) imparted on the cue ball should be controlled using the mouse. The cue ball is to be clicked, then the mouse dragged to control the direction and power of the shot. This should be accompanied by some visual cue, releasing the mouse button then fires the cue ball. The cue ball can only be hit if it is at rest, but not if it is still moving.
o At the current stage, we only consider red and blue coloured balls with 2 for each. After falling into the pocket, this red ball will disappear whereas the blue ball will be back to its initial position reading from the JSON file. If its initial position is occupied by another ball at the time when it is putting back to the table, it will disappear. Once the blue ball falls into the pocket for the second time, it will disappear.
• If the cue ball falls into a pocket, the game just resets back to the
beginning; whereas if all the coloured balls fall into the pocket and
there is only the while cue ball left on the table, the game just stops by
outputting “win and bye” either on the screen or on the terminal.
Attention Please: You are only allowed to implement the above features in your
current assignment, and you should not include any other features. Mark
deduction will be applied otherwise.
Report Task
You are allowed a maximum of 1000 words report in this assignment which must concisely cover the followings:
2. A discussion on each design pattern you have used including
1. A discussion on how your design (i.e., class diagram) for assignment 1
helped or hindered your design made in this assignment
o Rationalise changes you have made to your assignment 1
o Where you used it (be explicit as to what classes are
involved and in what roles)

o What this pattern does for your code in terms of SOLID/GRASP principles
o What overall benefits this pattern provides (be specific to your code, not the pattern in general)
o What drawbacks this pattern causes (be specific to your code, not the pattern in general)
3. The UML class diagram describing your whole system, including
design patterns.
4. Any acknowledgement/reference required.
Submission Details
You are required to submit all assessment items by the due date listed on Canvas.
Submit your UML class diagram and your report as
a SINGLE pdf document on this portal. If your UML diagram is too
large, then you need to 1) include the whole UML diagram; AND 2)
include enlarged versions of the key components when you refer to
• Code. Submitted separately by using this link. Your code should be
submitted as a zip file containing only your src folder, build.gradle, sample json configuration file, and readme.txt.
Attention Please: the sample json configuration file must be
put into the resources folder of main under the src folder.
Mark deduction will be applied if the location is wrong.
o The readme,txt file will cover any point you would like your marker to know
▪ how to run your code (e.g., any quirks to run
your application)
▪ which files and classes are involved in each
design pattern implemented

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com