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

frogger-game #158

Merged
merged 5 commits into from
Aug 22, 2022
Merged

frogger-game #158

merged 5 commits into from
Aug 22, 2022

Conversation

KonstantinOkhorzin
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.

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.

@KonstantinOkhorzin good start!
A few improvements are required tho.

Comment on lines 12 to 20
if (this.x > 510) {
this.x = -50;
this.speed = Math.round(Math.random() * 100 + 100);
};

if (player.x < this.x + 80 && player.x + 80 > this.x &&
player.y < this.y + 60 && 60 + player.y > this.y) {
player.x = 200;
player.y = 400;
Copy link
Member

Choose a reason for hiding this comment

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

As a peer developer that needs to contribute to this project I want to understand semantics behind all these magic numbers here and below in the code.

Also apparently update method doesn't just updates position but also has some more of business logic. We need to separate concerns. Please move checks to a different method.

Comment on lines 68 to 70
const enemy1 = new Enemy(-100, 60, 100);
const enemy2 = new Enemy(-50, 140, 150);
const enemy3 = new Enemy(-150, 230, 200);
Copy link
Member

Choose a reason for hiding this comment

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

As a peer developer on the project I am tasked to add 100 more rows to the field and 100 more enemies. There should be a way to do it programmatically rather than by adding another 100 lines of code.

@OleksiyRudenko OleksiyRudenko self-assigned this Aug 15, 2022
@KonstantinOkhorzin
Copy link
Contributor Author

I fixed all. Please, check the changes.

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.

This comment remains unadressed: #158 (comment)

What are all these magic numbers?

@KonstantinOkhorzin
Copy link
Contributor Author

I redid without magic numbers. Please, check the changes.

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.

@KonstantinOkhorzin well done! Now the code reads almost in plain English.

Yet one thing to make the code OOP/SOLID compliant.

Comment on lines 41 to 46
if(player.x < this.x + config.canvas.blockWidth &&
player.x + config.canvas.blockWidth > this.x &&
player.y < this.y + config.canvas.blockHeight &&
config.canvas.blockHeight + player.y > this.y) {
player.x = config.player.initialPositionOnX;
player.y = config.player.initialPositionOnY;
Copy link
Member

Choose a reason for hiding this comment

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

Classes should not refer to any global variables, like global variable player, which is an instance of Player class (referring to global constants and globals provided by the gaming platform like Resources is OK); Hint: pass Player instance as an argument to every enemy

@KonstantinOkhorzin
Copy link
Contributor Author

I fixed this bug. Please, check the changes.

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.

@KonstantinOkhorzin great job!

@OleksiyRudenko OleksiyRudenko merged commit 383dd21 into kottans:main Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants