t0ri-make-school-coursework / breakout Goto Github PK
View Code? Open in Web Editor NEWMDN Break Out Tutorial for FEW 1.2 at Make School.
MDN Break Out Tutorial for FEW 1.2 at Make School.
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L17
Should be passing ctx as a parameter here.
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L12
Depending on external global variable ctx not good practice. If you're class needs a reference to this pass it as a parameter on instantiation, if you only need it for a subroutine pass it as a parameter in that function. If you only need a piece of info from an object like the width or height, pass those numbers in.
These are best practices you should apply them everywhere!
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L333
Did you reassign these variables to another object? Probably not.
Were you intending to do that? Probably not
If you did would it break things? It might
For all of these reasons these should all be const!
And you also get the added bonus of signaling your intent with the code. These values are not supposed to change anyone can read that clearly when you use const. With let and var it's not clear.
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L1
Great code quality good work on the comments and formatting.
Your game looks good. Looks like you solved many of the challenges!
Your readme looks good, thanks!
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L10
Great job here. Putting the background drawing routines in a class is a good idea. It makes this portable (more on this in a moment), and encapsulates this functionality in one place. It allows you to easily expand on this in the future. You can add a feature that changes the background be sending a message to the instance of this class.
You missed the concept of dependency injection. This is an important concept that you should apply here.
What's wrong? Your classes rely on an external global variable: ctx. If you were use these classes in another project it's obvious that you'd need this global variable, and even then it relies on the name ctx which might not be available.
Better, pass this dependency in as a parameter. This way the requirement is obvious it's a parameter, while the parameter is named ctx externally you can use any name.
Here you defined ctx:
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L5
You should pass ctx in here as a parameter:
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L17
Here you should pass ctx as a parameter:
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L351
You should follow this pattern for all of your classes!
https://github.com/t0ri/breakout/blob/5372aad6ecb7a401198b52814b844b7a41fc0d18/js/script.js#L27
Using canvas here is not best practice. Looks like you really only need the width and height.
You need to get rid of the dependance on canvas here. Choose your route:
Some of these solutions are better than others. Study them closely. Run a simulation. Apply the calipers and slide rule. I expect a report on my desk Monday morning! Or at the very least apply one of the solutions to your work.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.