import React, { Component, PropTypes } from 'react';
import styled from 'styled-components';

import Grid from './Grid';

class Game extends Component {
  static propTypes = {
    numbers: PropTypes.arrayOf(PropTypes.number).isRequired,
    tileSize: PropTypes.number,
    gridSize: PropTypes.number,
  };

  static defaultProps = {
    tileSize: 90,
    gridSize: 4,
  };

  constructor(props) {
    super(props);

    const tiles = [];
    this.props.numbers.forEach((number, index) => {
      tiles[index] = {
        ...this._getTileCoords(index),
        tileId: index,
        width: this.props.tileSize,
        height: this.props.tileSize,
        number,
      };
    });

    this.state = {
      tiles,
      gameState: Symbol('GAME_IDLE'),
    };

    this.onTileClick = this.onTileClick.bind(this);
  }

  render() {
    return (
      <div className={this.props.className}>
        <div className="content">
          <Grid tiles={this.state.tiles} onTileClick={this.onTileClick} />
        </div>
      </div>
    );
  }

  _getTileCoords(index) {
    const column = index % this.props.gridSize;
    const row = Math.floor(index / this.props.gridSize);

    return {
      column,
      row,
      left: column * this.props.tileSize,
      top: row * this.props.tileSize,
    };
  }

  _isGameOver() {
    return false;
  }

  onTileClick(tileIndex) {
    if (this.state.gameState === Symbol('GAME_OVER')) {
      return;
    }

    const { row, column } = this._getTileCoords(tileIndex);

    // Find index of 0 tile
    const zeroTileIndex = this.state.tiles.findIndex(t => t.number === 0);
    const { row: zeroRow, column: zeroColumn } = this._getTileCoords(
      zeroTileIndex,
    );

    // Is this tale neighbouring the zero tile? If so, switch them.
    if (
      row === zeroRow && Math.abs(column - zeroColumn) === 1 ||
      column === zeroColumn && Math.abs(row - zeroRow) === 1
    ) {
      let t = Array.from(this.state.tiles);
      const sw = t[zeroTileIndex].number;
      t[zeroTileIndex].number = t[tileIndex].number;
      t[tileIndex].number = sw;

      this.setState({ tiles: t });
    }
  }
}

export default styled(Game)`
  width: ${props => props.tileSize * props.gridSize}px;
  height: ${props => props.tileSize * props.gridSize}px;
  position: relative;
`;

@@ -1776,37 +1776,109 @@
     
-if (%0A      row === zeroRow &&
+const sameRow = row === zeroRow;%0A    const sameColumn = column === zeroColumn;%0A    const diffColumn =
  Mat
@@ -1913,42 +1913,29 @@
 == 1
- %7C%7C%0A      column === zeroColumn &&
+;%0A    const diffRow =
  Mat
@@ -1960,21 +1960,170 @@
 w) === 1
+;
 %0A    
+const sameRowDiffColumn = sameRow && diffColumn;%0A    const sameColumnDiffRow = sameColumn && diffRow;%0A    if (sameRowDiffColumn %7C%7C sameColumnDiffRow
 ) %7B%0A    

Change expression due to Prettier