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

Tetris dueling #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Tetris dueling #2

wants to merge 1 commit into from

Conversation

ian-deans
Copy link
Owner

No description provided.


nextPositionIsRubble() {
const nextPos = this.fallingPiece.points()
.map( point => new Models.Point( point.row +1, point.col ))

Choose a reason for hiding this comment

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

Consider indenting this to increase readability.

Copy link
Owner Author

Choose a reason for hiding this comment

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

👍

const nextPos = this.fallingPiece.points()
.map( point => new Models.Point( point.row +1, point.col ))
return nextPos
.some( point => this.rubble

Choose a reason for hiding this comment

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

This formatting was a little tough for me to parse - consider reformatting to make it a little bit clearer what's going on here...

}
down() {
while (
!this.fallingPieceIsOutOfBounds() &&

Choose a reason for hiding this comment

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

Consider refactoring this into an intention revealing method:

while( this.pieceIsInValidPosition() ) {
  // etc
}

pieceIsInValidPosition() {
  return !this.fallingPieceIsOutOfBounds() && !this.fallingPieceOverlapsRubble()
}

On a related note, if it increases the readability of this code, De Morgan's Law states that ! a && ! b is equivalent to !( a || b )

@@ -97,7 +126,10 @@ export default class Game {
}

fallingPieceOverlapsRubble() {
return this.fallingPiece.points().some( p => this.rubble.some( r => r.sameAs(p) ) )
return this.fallingPiece.points()
.some( point => this.rubble

Choose a reason for hiding this comment

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

Same note as above, a little difficult to understand with this formatting.

<div className='border' style={{ width: this.props.game.cols*25,
height: this.props.game.rows*25}}>
<div>
<NextPieceView piece={this.props.game.game1.nextPiece} className='next1'/>

Choose a reason for hiding this comment

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

This line should be outdented to preserve consistent formatting.

state :
state = { 'game1': state.game1, 'game2': state.game2.down() }
case 'PAUSE':
pausedBoolean = ( pausedBoolean === false ) ? true : false

Choose a reason for hiding this comment

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

pausedBoolean = ! pausedBoolean


const ROTATIONS = ['N', 'E', 'S', 'W']

class Rotation {

Choose a reason for hiding this comment

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

Consider re-organizing into its own module


previous() {
return ROTATIONS[ ( this.index - 1 ) % 4 ]
}
}

export class Piece {

Choose a reason for hiding this comment

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

Consider re-organizing into its own module.

this.shape = shape
this.offset = offset
this.rotation = 'N'
this.classString = shape.classString
}

points() {
return this.shape.pointsRotated( this.rotation ).map( ( point, ix ) => point.add( this.offset ) );
return this.shape.pointsRotated( this.rotation )
.map( ( point, ix ) => point.add( this.offset ) );

Choose a reason for hiding this comment

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

Indent for clarity

this.shape = shape
this.offset = offset
this.rotation = 'N'
this.classString = shape.classString
}

points() {
return this.shape.pointsRotated( this.rotation ).map( ( point, ix ) => point.add( this.offset ) );
return this.shape.pointsRotated( this.rotation )

Choose a reason for hiding this comment

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

This feels like it may be another violation of the Law of Demeter (reaching through shape into another thing to perform an operation)...

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.

2 participants