-
-
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
frogger-game #158
frogger-game #158
Conversation
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.
@KonstantinOkhorzin good start!
A few improvements are required tho.
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; |
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.
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.
const enemy1 = new Enemy(-100, 60, 100); | ||
const enemy2 = new Enemy(-50, 140, 150); | ||
const enemy3 = new Enemy(-150, 230, 200); |
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.
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.
I fixed all. Please, check the changes. |
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.
This comment remains unadressed: #158 (comment)
What are all these magic numbers?
I redid without magic numbers. Please, check the changes. |
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.
@KonstantinOkhorzin well done! Now the code reads almost in plain English.
Yet one thing to make the code OOP/SOLID compliant.
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; |
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.
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
I fixed this bug. Please, check the changes. |
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.
@KonstantinOkhorzin great job!
Object Oriented JS
Demo |
Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.