-
Notifications
You must be signed in to change notification settings - Fork 233
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
base: master
Are you sure you want to change the base?
Conversation
Change rotation so it looks more like the Tetris everyone knows. Added a new Game button + Score on the top.
Press P to pause Game
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.
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> |
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.
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 | |||
|
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.
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); |
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.
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] | ||
|
||
|
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.
Not sure why the 0
's are necessary here?
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.
For centering the objects and understanding
js/tetris.js
Outdated
newGame(); | ||
return false; | ||
|
||
if(!pause) { |
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.
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"); |
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 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(); |
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.
Move to renderer
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.
Not sure how to move this to renderer without creating a reference anyway, since renderer doesn´t get information about a new Game or ?
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.
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;} |
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.
Mind your coding style
style.css
Outdated
border: 1px solid black;} | ||
|
||
div.container p { | ||
font-family: Arial; |
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.
Good to include a generic fallback font; sans-serif?
style.css
Outdated
} | ||
|
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.
Since you're making CSS changes, a screenshot will assist in the code review. Could you please provide one?
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.
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. |
Cleaned up the code except the score reset. |
var score = 0; | ||
var pause = false; | ||
var button = document.getElementById( "newgame" ); | ||
button.addEventListener( "click", newGame ); |
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.
Use single quotes to be consistent with the rest of the coding style.
++currentY; | ||
|
||
if(pause) { | ||
return; | ||
} |
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.
Please be consistent in your indentation method
if ( valid( 0, 1 ) ) { | ||
++currentY; | ||
|
||
if(pause) { |
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.
Use a space after if
newCurrent[y] = []; | ||
for (var x = 0; x < 4; ++x) { | ||
newCurrent[y][x] = current[3 - x][y]; | ||
} | ||
} |
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.
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(); |
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.
use single quotes
return newCurrent; | ||
} | ||
|
||
// check if any lines are filled and clear them | ||
function clearLines() { | ||
|
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.
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 ) { |
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 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(); |
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.
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 { |
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.
lower-case button
@@ -3,3 +3,19 @@ canvas { | |||
margin: auto; | |||
border: 1px solid black; | |||
} | |||
|
|||
div{ |
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.
space after div
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! |
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. |
Change Models so it looks more like the Tetris everyone knows.
Added a new Game button + Score on the top.