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

Change Models, new Game Button and Score #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Change Models, new Game Button and Score #4

wants to merge 7 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 19, 2017

Change Models so it looks more like the Tetris everyone knows.
Added a new Game button + Score on the top.

Change rotation so it looks more like the Tetris everyone knows.
Added a new Game button + Score on the top.
@ghost ghost changed the title Change rotation, new Game Button and Score Change Models, new Game Button and Score Jun 19, 2017
JohannesKnecht added 2 commits June 20, 2017 18:40
Press P to pause Game
Copy link
Owner

@dionyziz dionyziz left a comment

Choose a reason for hiding this comment

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

Thank you for taking the time to add these features. These are not bad changes and I would like to see them merged. Please check my comments in the code.

index.html Outdated



<center>
Copy link
Owner

Choose a reason for hiding this comment

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

Use CSS to center

README.md Outdated
@@ -1,5 +1,7 @@
A very simple HTML5 version of Tetris, for educational purposes, made in 45 minutes.

//Added Score, Pause, new Game and changed the rotation of shapes

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need this comment in the README

js/tetris.js Outdated
var pause = false;

var button = document.getElementById("newgame");
button.addEventListener ("click", newGame);
Copy link
Owner

Choose a reason for hiding this comment

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

Please keep code formatting according to the rest of the codebase: Single quotes, space after ,, no space before (, and so on

0,1,0,0,
1,1,1,0]


Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why the 0's are necessary here?

Copy link
Author

@ghost ghost Jul 6, 2017

Choose a reason for hiding this comment

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

For centering the objects and understanding

js/tetris.js Outdated
newGame();
return false;

if(!pause) {
Copy link
Owner

Choose a reason for hiding this comment

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

Better use an early fail condition with return to avoid indentation level:

if (pause) {
    return;
}

js/tetris.js Outdated
var score = 0;
var pause = false;

var button = document.getElementById("newgame");
Copy link
Owner

Choose a reason for hiding this comment

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

This should be part of the rendering file.

@@ -175,6 +213,8 @@ function valid( offsetX, offsetY, newCurrent ) {
}

function newGame() {
score = 0;
document.getElementById("score").innerHTML = "Score: " + score.toString();
Copy link
Owner

Choose a reason for hiding this comment

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

Move to renderer

Copy link
Author

@ghost ghost Jul 6, 2017

Choose a reason for hiding this comment

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

Not sure how to move this to renderer without creating a reference anyway, since renderer doesn´t get information about a new Game or ?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, you need to create a reference. The score variable will need to live in tetris.js, but the HTML update will need to be in render.js. This makes for better architecture and modularity.

style.css Outdated
@@ -1,5 +1,16 @@
canvas {
display: block;
margin: auto;
border: 1px solid black;
border: 1px solid black;}
Copy link
Owner

Choose a reason for hiding this comment

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

Mind your coding style

style.css Outdated
border: 1px solid black;}

div.container p {
font-family: Arial;
Copy link
Owner

Choose a reason for hiding this comment

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

Good to include a generic fallback font; sans-serif?

style.css Outdated
}

Copy link
Owner

Choose a reason for hiding this comment

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

Since you're making CSS changes, a screenshot will assist in the code review. Could you please provide one?

Copy link
Author

Choose a reason for hiding this comment

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

tetris

@dionyziz
Copy link
Owner

I did not make any changes in the code – just left comments of recommended changes for you to make before I can merge. Please make these changes and I will review your code again. Once you make the changes, you can push to your branch so that they are reflected in this Pull Request without opening a new one.

@ghost
Copy link
Author

ghost commented Jul 6, 2017

Cleaned up the code except the score reset.

var score = 0;
var pause = false;
var button = document.getElementById( "newgame" );
button.addEventListener( "click", newGame );
Copy link
Owner

Choose a reason for hiding this comment

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

Use single quotes to be consistent with the rest of the coding style.

++currentY;

if(pause) {
return;
}
Copy link
Owner

Choose a reason for hiding this comment

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

Please be consistent in your indentation method

if ( valid( 0, 1 ) ) {
++currentY;

if(pause) {
Copy link
Owner

Choose a reason for hiding this comment

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

Use a space after if

newCurrent[y] = [];
for (var x = 0; x < 4; ++x) {
newCurrent[y][x] = current[3 - x][y];
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why you are making these changes? If you want to change the existing coding style into something else, please do so in a separate PR and do it across the whole project, not only incidentally.

@@ -109,6 +129,9 @@ function clearLines() {
}
}
if ( rowFilled ) {

score = score + 1;
document.getElementById("score").innerHTML = "Score: " + score.toString();
Copy link
Owner

Choose a reason for hiding this comment

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

use single quotes

return newCurrent;
}

// check if any lines are filled and clear them
function clearLines() {

Copy link
Owner

Choose a reason for hiding this comment

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

Do not begin a function with an empty line

++currentY;
}
break;
case 'rotate':
var rotated = rotate( current );
if ( valid( 0, 0, rotated ) ) {
if ( valid( 0, 0, rotated ) && !pause ) {
Copy link
Owner

Choose a reason for hiding this comment

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

This code can be made simpler by moving the check for a pause key to the beginning of the function before the switch is ran. Then you won't need to repeat yourself in each case, as you can return early.

@@ -175,6 +213,8 @@ function valid( offsetX, offsetY, newCurrent ) {
}

function newGame() {
score = 0;
document.getElementById("score").innerHTML = "Score: " + score.toString();
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, you need to create a reference. The score variable will need to live in tetris.js, but the HTML update will need to be in render.js. This makes for better architecture and modularity.

text-align: center;
}

Button {
Copy link
Owner

Choose a reason for hiding this comment

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

lower-case button

@@ -3,3 +3,19 @@ canvas {
margin: auto;
border: 1px solid black;
}

div{
Copy link
Owner

Choose a reason for hiding this comment

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

space after div

@dionyziz
Copy link
Owner

This is actually looking nice and I'm looking forward to merging it – but I have requested some more changes mostly pertaining to style. Thanks for your contribution!

@dionyziz
Copy link
Owner

dionyziz commented Jun 7, 2018

Are you interested in finishing these changes? I'd be very happy to merge them once you take care of the small issues I mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant