QT代写:COMP4799 Assignment 2 Extend someone else’s implementation of a simple pool game

 

Assignment 2

Due May 11 by 18:00 Points 15 Submitting a file upload Available Apr 20 at 18:50 ­ Jun 8 at 18:00 about 2 months

Assignment 2

Extend someone else’s implementaon of a simple pool game.

You can make slight changes to the code you have received, this includes bug fixes, slight changes to method declarations and definitions. However you cannot change the overall structure of the program. In addition if your program is provided a config file that would be a valid config file for assignment 1 it should behave identically (minus any bugs). The following additions are only valid if stage2 is defined as true in the config file.

The table now has pockets.

The table can have any number of pockets defined. The definition of a pocket is its radius and location. Pockets can be centered on or off the table and do not need to intersect the edge of the table, however pockets cannot exist entirely off the table. The pockets must be drawn on the table. When a ball is fully encompassed by a pocket it is removed from the game. Other than this you may model the interaction of balls and pockets in any way you like.

The cue ball can be hit when it is at rest.

The player can interact with the cue ball which is the first white ball in the balls array. It can be hit if it is at rest, but not if it is still moving. 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.

Balls can be composed of mulple other balls.

Balls can contain other balls within them, which themselves can contain balls ad infinitum. Contained balls are not visible whilst contained, their position is relative to the center of their parent ball, and their velocity is zero. These inner balls must be fully contained within their parent (e.g. their radius+distance from center must not be greater than the radius of their parent), but are allowed to overlap. The effective mass of a ball is the sum of its own mass and the mass of its children. If a ball composed of other balls is hit hard enough it

Su

bmit Assignment

https://canvas.sydney.edu.au/courses/4799/assignments/50110 1/6

20/04/2018 Assignment 2

breaks apart and the contained balls are released onto the table at a position relative to their parent defined by the config file. The default colour of contained balls is the colour of the parent

You must use the composite design paern and one addional paern of your choosing.

The composite design pattern must be used somewhere within this assignment as well as another additional design pattern. This additional design pattern cannot be a Singleton, Iterator, Abstract Factory, Factory Method or Builder. This does not mean that all other patterns are suitable and marks will only be awarded for suitable use of a design pattern. This also does not mean that you can’t use these design patterns to facilitate good overall design of the code, just that they won’t count as your additional design pattern.

Config file

All properties need to have a default value provided if it is not provided in the config file. If the key is provided but the value is invalid then a warning message should be printed and the default value should be used. The config file format along with the defaults are as follows

stage2 false table

size
x 600.0

y 300.0
colour “green” friction “0.01” pockets empty array

position
x pocket ignored, warning message y pocket ignored, warning message

radius 15.0
balls just the white ball with default values except positioned at the center of the table

colour “white” or the colour of the parent ball if contained mass 1.0
balls empty array
strength infinity

radius 10.0 position

x0

y0 velocity x 0.0 y 0.0

If any part of a ball is placed off the table or outside its parent ball print a warning message and ignore that ball.

https://canvas.sydney.edu.au/courses/4799/assignments/50110 2/6

20/04/2018

An example config file is provided here

 {
 "stage2" : true,
 "table" : {
  "colour":"green",
  "size":{
  "x":600,
  "y":300
  },
  "friction":0.01,
  "pockets": [
  {"position":{"x":5,"y":5}},
  {"position":{"x":595,"y":295}},
  {"position":{"x":-595,"y":5}},
  {"position":{"x":5,"y":295}},
  {"position":{"x":200,"y":200},"radius":20}
  ]

},
“balls” : [

  {"position":{"x":50,"y":50},"velocity":{"x":100,"y":10},"mass":1},
  {"colour":"red","position":{"x":150,"y":60},"mass":1,"radius":10},
  {"colour":"blue","position":{"x":150,"y":40},"velocity":{"x":-100,"y":0},"ra
 dius":10},
  {"colour":"#123456","position":{"x":250,"y":70},"mass":1,"radius":20,"streng
 th":1e5,
  "balls":[
  {"colour":"red","position":{"x":-10,"y":0},"velocity":{"x":100,"y":10},"mas
 s":1,"radius":10},
  {"colour":"red","position":{"x":10,"y":0}},
  {"colour":"red","position":{"x":0,"y":-10}},
  {"position":{"x":0,"y":10}, "mass":2,"strength":1e4,
  "balls":[
  {"colour":"blue","strength":1e3,
  "balls":[
  {"colour":"red", "strength":1e4}
  ]
  }]
  }]
  }]

}

Physics of breaking a ball

https://canvas.sydney.edu.au/courses/4799/assignments/50110 3/6

Assignment 2

20/04/2018 Assignment 2

A ball will break if the kinetic energy of a collision is greater than the strength of a ball.

The kinetic energy of a collision is equal to i.e. the mass of the ball multiplied by the square of the change in velocity.

This change in velocity can be due to hitting another ball or bouncing off a wall (the walls of this pooltable are made of marble, not felt).

When the ball breaks any balls contained will eplode away from the point of impact each with an equal share of the total kinetic energy of the impact.

      float ballMass;
      float ballStrength;
      float ballRadius;
      QVector2D preCollisionVelocity;
      QVector2D deltaV;
      float energyOfCollision = ballMass*deltaV.lengthSquared();
      if(ballStrength<energyOfCollision)
      {
          float energyPerBall = energyOfCollision/numComponentBalls;
          QVector2D pointOfCollision((-deltaV.normalize())*ballRadius);
          //for each component ball
          QVector2D componentBallVelocity = preCollisionVelocity + sqrt(energyPerBall/componentBallMass)*
  (componentBallPosition-pointOfCollision).normalize();
      }

Marking
There are two segments to this assignment: The code which is worth 10 and the essay which is worth 5.

The marking (out of 10 marks) for the code section is as follows: Compiling and running on the lab machines. (5%)
The config file is read from as described. (10%)
Balls can break apart and contain other balls. (10%)

The cue ball can be hit with velocity controlled by mouse (10%)
Balls can fall in pockets and are removed from the game completely (10%)

Appropriate use of design patterns: Use of composite design pattern and at least one other design pattern. (30%)

Sensible / appropriate OO design (Extensible code design, clear separation of responsibility, etc). (10%) Clear code: meaningful variable and method names. (5%)

https://canvas.sydney.edu.au/courses/4799/assignments/50110 4/6

20/04/2018 Assignment 2

Documentation: Doxygen comments for methods/classes as well as in­code comments where appropriate. (10%)

The marking (out of 5 marks) for the essay section is as follows

Recieved code:

How well designed was the code for extensions, what particular elements aided or hindered extensabilty? (10%)

How well documented was the code with respect to both external documentation and comments? (10%) Was the coding well done? What would you have done differently? What was good/bad about the

implementation? (10%)
Comment on the style of the code. Were names, layout, code clichés consistent? (10%)
Your code:
Explain the application of the design patterns for your code. (20%)
Explain advantage and disadvantages of the design patterns used with respect to your code. (20%) All code:
Graphical visualisation in UML of the code. (20%)

Academic honesty

While the University is aware that the vast majority of students and staff act ethically and honestly, it is opposed to and will not tolerate academic dishonesty or plagiarism and will treat all allegations of dishonesty seriously.

Further information on academic honesty, academic dishonesty, and the resources available to all students can be found on the academic integrity pages on the current students website: https://sydney.edu.au/students/academic­integrity.html (https://sydney.edu.au/students/academic­ integrity.html) .

Compliance statement

In submitting this work, I acknowledge I have understood the following:

I have read and understood the University of Sydney’s Academic Honesty in Coursework Policy 2015 (https://sydney.edu.au/policies/showdoc.aspx?recnum=PDOC2012/254&RendNum=0) .
The work is substantially my own and where any parts of this work are not my own I have indicated this by acknowledging the source of those parts of the work and enclosed any quoted text in quotation marks.

https://canvas.sydney.edu.au/courses/4799/assignments/50110 5/6

20/04/2018 Assignment 2

The work has not previously been submitted in part or in full for assessment in another unit unless I have been given permission by my unit of study coordinator to do so.
The work will be submitted to similarity detection software (Turnitin) and a copy of the work will be retained in Turnitin’s paper repository for future similarity checking.

Engaging in plagiarism or academic dishonesty will, if detected, lead to the University commencing proceedings under the Academic Honesty in Coursework Policy 2015 (https://sydney.edu.au/policies/showdoc.aspx?recnum=PDOC2012/254&RendNum=0) and the Academic Honesty Procedures 2016 (http://sydney.edu.au/policies/default.aspx? mode=glossary&word=Academic+honesty) .

Engaging another person to complete part or all of the submitted work will, if detected, lead to the University commencing proceedings against me for potential student misconduct under the University of Sydney (Student Discipline) Rule 2016 (http://sydney.edu.au/policies/showdoc.aspx? recnum=PDOC2017/441&RendNum=0) .

https://canvas.sydney.edu.au/courses/4799/assignments/50110 6/6