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

My PR Classic Frogger Game #516

Merged
merged 3 commits into from
Oct 2, 2022
Merged

Conversation

Nik3264
Copy link
Contributor

@Nik3264 Nik3264 commented Sep 11, 2022

Classic Frogger Game

Demo |
Code base

The code is submitted in a dedicated feature branch.

Only code files are submitted.

Please, review.

@github-actions
Copy link

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 😺

@Nik3264
Copy link
Contributor Author

Nik3264 commented Sep 12, 2022

I've looked at the code and everything seems to be working. Please, review.

1 similar comment
@Nik3264
Copy link
Contributor Author

Nik3264 commented Sep 15, 2022

I've looked at the code and everything seems to be working. Please, review.

@Nik3264
Copy link
Contributor Author

Nik3264 commented Sep 17, 2022

Please, review.

@OleksiyRudenko OleksiyRudenko added the self-check-done Student confirmed that self-checks against requirements/common-mistakes are done label Sep 20, 2022
@OleksiyRudenko OleksiyRudenko self-assigned this Oct 1, 2022
@Nik3264
Copy link
Contributor Author

Nik3264 commented Oct 1, 2022

I saw comments from other students and made changes. I removed the constants in the properties of the Game class.

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.

@Nik3264 good progress.
A few issues yet to resolve though.

Comment on lines 29 to 30
if ( (this.x > player.x-50 && this.x < player.x+50) &&
(this.y > player.y-40 && this.y < player.y+40) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Refers to global variable, see item 4.iii of the requirements.
Mystery numbers, see item 3 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.

i fixed it

}
break;
case "down":
if(this.y<383){
Copy link
Member

Choose a reason for hiding this comment

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

Mystery number.
Check all numbers across the code base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i fixed it

this.x = game.frontierForEnemiesLeft;
}
if (this.isCollision()) {
player.start();
Copy link
Member

Choose a reason for hiding this comment

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

Item 4.iii of the requirements says:

Classes do 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 instance of a game object (or objects) as an argument to other game objects they need to interact with.

It is relevant to this line of code and other methods where global variable player is referred to.

Same problem is with variable game. Besides, why do you need to refer to a specific instance of class Game within methods of that class? I mean you perfectly fine use this to refer to the properties of class Game and suddenly start using specific instance of the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the player object as a parameter

Comment on lines 82 to 91
if (
this.x > player.x - game.collisionX &&
this.x < player.x + game.collisionX &&
this.y > player.y - game.collisionY &&
this.y < player.y + game.collisionY
) {
return true;
} else {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Redundant.
if's condition resolves to either true or false and based on that then or else part of if is executed.
You may simply return the values testing condition here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was so obvious, but I didn't notice it! Thank you

Comment on lines 102 to 103
this.x = game.PLAYER_X_START;
this.y = game.PLAYER_Y_START;
Copy link
Member

Choose a reason for hiding this comment

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

Item 4.iii of the requirements. Here and everywhere in classes definitions across the code.

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 152 to 156
if (this.y <= 0) {
return true;
} else {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Similar to isCollision. this.y <= 0 already resolves to true or false.

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 170 to 172
const bug1 = new Enemy({ x: 0, y: 140, speed: 100 });
const bug2 = new Enemy({ x: 0, y: 50, speed: 50 });
const bug3 = new Enemy({ x: 0, y: 230, speed: 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 I am tasked to add 50 more enemies.
I would appreciate if the code here was DRYer.
bug1 ... bug50 is a no-go. We have arrays and Array methods to handle this sort of situations.
Besides, what number should I use for y if I want to add an enemy to the 4th row?
Can we have something that would translate row numbers to pixel counts? There must be some correlation between row number and cellHeight.

Computers are invented specifically to make calculations and help people operate with comprehensible things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I liked this part the most! ))
I tried to fix everything according to the requirements
Thank you.

@Nik3264
Copy link
Contributor Author

Nik3264 commented Oct 2, 2022

I added inheritance and got rid of magic numbers.
Thank you a lot

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.

@Nik3264 great job done!

Comment on lines +173 to +177
const arrOfEnemies = [];
for (let i = 0; i < numberOfEnemies; i++) {
arrOfEnemies.push(i);
}
return arrOfEnemies;
Copy link
Member

Choose a reason for hiding this comment

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

Bonus: one of the methods to create an array knowing its length and pre-fill it with some values based on index is
Array.from({length: numberOfEnemies}, (_, index) => index)
Prepend with return and call it a day.
Still worth having a function for this one-liner as function provides a semantic meaning to the action.

Comment on lines +185 to +186
game: game,
player: player,
Copy link
Member

Choose a reason for hiding this comment

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

There is legal shortcut to create object properties from variables where key will have the name same as the variable in use.

{
  variableName,
}
// ..is equivalent to...
{
  variableName: variableName,
}

@OleksiyRudenko OleksiyRudenko merged commit a7107c2 into kottans:main Oct 2, 2022
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 Stage0.1 task-Frogger
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants