-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task "Task js oop" #499
Task "Task js oop" #499
Conversation
Hey! Congratulations on your PR! 😎😎😎 Let's do some self-checks to fix most common issues and to make some improvements to the code before reviewers put their hands on the code. Go through the requirements/most common mistakes linked below and fix the code as appropriate. If you have any questions to requirements/common mistakes feel free asking them here or in Students' chat. When you genuinely believe you are done put a comment stating that you have completed self-checks and fixed code accordingly. Also, be aware, that if you would silently ignore this recommendation, a mentor can think that you are still working on fixes. And your PR will not be reviewed. 😒 Please, make sure that your code follows the requirements Universal recommendations:
By the way, you may proceed to the next task before this one is reviewed and merged. Sincerely yours, |
add: added configurate objects for characters.
Hi. I update app.js file following the requirements. Interesting Your opinion about it. Please, review. |
Hi. I tried refactoring with the base class, which is extended using prototype syntax. Please, review. |
naming isFreeze.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DmitryHniezdilov quite a decent job.
A couple of important changes and we are done.
player.y === this.y && | ||
player.x <= Math.floor(this.x) + this.BLOCK_WIDTH / 1.3 && | ||
player.x >= Math.floor(this.x) - this.BLOCK_WIDTH / 1.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requirements address this case specifically.
Please find it, post here as a comment and fix code accordingly.
This is also applicable to other global variables with the exception of constants as described in the requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find it, post here as a comment and fix code accordingly.
"Requirements regarding Constants:
i. All numbers like block dimensions, initial locations are defined as constants.";
ii. Every number that has a semantic purpose (like those listed above) should be defined as constants; think of how your code reads - the closer to plain English the better."
I missed adding this number as a constant in the config object. Done.
Enemy.prototype.createEnemies = function (config) { | ||
const { ENEMIES_CONF, STATE, ORIGIN_COORDINATE_CHARACTERS, BLOCK_HEIGHT } = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a factory pattern, but mixed with the class itself.
This could be a static method of the class. Otherwise it looks weird when we create an instance to create other instances.
If you are not sure of how to implement a static method in prototype
syntax, just implement a global function outside class definition to create enemies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order not to change the game control function Character.prototype.endOfGame, I initialized a config object in Character and created a function EnemiesFactory, which inherits this and .prototype from Enemy. After initializing the EnemiesFactory, I was able to use the enemy control methods as static methods (enemiesFactory.createEnemies();).
I haven't found a better way to update this code.
Hello. I tried to refactor this code on the prototype syntax. Thanks for the advice just implement global function outside class definition to create enemies. In this case it doesn't work. It was a good practice to understand OOP. Please, review. |
e466db7
to
f7b3e0e
Compare
implemented a global function to create enemies; created class for restart game; added variable isFreeze to Character.
f7b3e0e
to
6b0e025
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DmitryHniezdilov very good job!
A couple of improvements and we are done.
!this.isFreeze && | ||
((this.x += this.speed * dt), | ||
this.x > this.FIELD_WIDTH && (this.x = -this.BLOCK_WIDTH), | ||
this.checkCollision()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid syntax, yet not really readable.
Ol' good if
would work better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
player.y === this.y && | ||
player.x <= | ||
Math.floor(this.x) + this.BLOCK_WIDTH / this.ENEMIES_CONF.overlapRatio && | ||
player.x >= | ||
Math.floor(this.x) - this.BLOCK_WIDTH / this.ENEMIES_CONF.overlapRatio; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See item 4.iii of the requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DmitryHniezdilov great job done!
Thank you! |
Object Oriented JS
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.