Skip to content
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

Merged

Conversation

DmitryHniezdilov
Copy link
Contributor

Object Oriented JS

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

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:

  • Make sure your code follows General Requirements
  • Use common sense or seek for an advice whenever requirements look ambiguous or unclear.

By the way, you may proceed to the next task before this one is reviewed and merged.

Sincerely yours,
Submissions Kottachecker 😺

add: added configurate objects for characters.
@DmitryHniezdilov
Copy link
Contributor Author

Hi. I update app.js file following the requirements. Interesting Your opinion about it.

Please, review.

@DmitryHniezdilov
Copy link
Contributor Author

Hi. I tried refactoring with the base class, which is extended using prototype syntax.

Please, review.

@OleksiyRudenko OleksiyRudenko added the self-check-done Student confirmed that self-checks against requirements/common-mistakes are done label Sep 20, 2022
Copy link
Member

@OleksiyRudenko OleksiyRudenko left a 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.

Comment on lines 139 to 141
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
Copy link
Member

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.

Copy link
Contributor Author

@DmitryHniezdilov DmitryHniezdilov Sep 21, 2022

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.

Comment on lines 164 to 165
Enemy.prototype.createEnemies = function (config) {
const { ENEMIES_CONF, STATE, ORIGIN_COORDINATE_CHARACTERS, BLOCK_HEIGHT } =
Copy link
Member

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.

Copy link
Contributor Author

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.

@OleksiyRudenko OleksiyRudenko self-assigned this Sep 20, 2022
@DmitryHniezdilov
Copy link
Contributor Author

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.

implemented a global function to create enemies;
created class for restart game;
added variable isFreeze to Character.
Copy link
Member

@OleksiyRudenko OleksiyRudenko left a 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.

Comment on lines 97 to 100
!this.isFreeze &&
((this.x += this.speed * dt),
this.x > this.FIELD_WIDTH && (this.x = -this.BLOCK_WIDTH),
this.checkCollision());
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 105 to 110
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;

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a 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!

@OleksiyRudenko OleksiyRudenko merged commit 3105d92 into kottans:main Sep 26, 2022
@DmitryHniezdilov
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
self-check-done Student confirmed that self-checks against requirements/common-mistakes are done task-Frogger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants