Giter Site home page Giter Site logo

breakout's People

Contributors

t0ri avatar victoriamurray avatar

Watchers

 avatar

breakout's Issues

Why not const?

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.

Overall

Your game looks good. Looks like you solved many of the challenges!

Your readme looks good, thanks!

Use dependency injection

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!

Depends on external global var

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:

  1. pass canvas as a parameter
  2. pass the width and height as a parameters
  3. Get the width and height from ctx
  4. add a property that has a reference to canvas to the class
  5. Add properties for width and height to the class

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.