-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- using functional component definition for Board react component.
- Loading branch information
1 parent
c94adc5
commit c4ec5dc
Showing
4 changed files
with
31 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
|
||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import Square from './Square' | ||
import '../styles/board.css' | ||
|
||
export default class Board extends Component { | ||
files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | ||
ranks = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
const files = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; | ||
const ranks = [1, 2, 3, 4, 5, 6, 7, 8]; | ||
|
||
getPiece(f, r) { | ||
return this.props.squares[this.ranks.indexOf(r)* 8 + this.files.indexOf(f)].piece; | ||
} | ||
function getPiece(squares, f, r) { | ||
return squares[ranks.indexOf(r)* 8 + files.indexOf(f)].piece; | ||
} | ||
|
||
render() { | ||
return ( | ||
<table className="chess-board"> | ||
<tbody> | ||
{this.ranks.slice().reverse().map(r => | ||
<tr key={"tr" + r.toString()}> | ||
{this.files.map(f => | ||
<td key={"td"+f+r.toString()} onClick={() => this.props.handleClick(f+r)}> | ||
<Square key={f+r.toString()} | ||
file={f} | ||
rank={r} | ||
piece={this.getPiece(f, r)} | ||
selected={this.props.selected && this.props.selected.startsWith(f+r)} | ||
threatened={typeof this.props.threatenedSquares[0] !== "undefined" ? this.props.threatenedSquares[0].filter(square => square.file===f && square.rank === r).length : false} /> | ||
</td>)} | ||
</tr>)} | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
export default function Board(props) { | ||
return ( | ||
<table className="chess-board"> | ||
<tbody> | ||
{ranks.slice().reverse().map(r => | ||
<tr key={"tr" + r.toString()}> | ||
{files.map(f => | ||
<td key={"td"+f+r.toString()} onClick={() => props.handleClick(f+r)}> | ||
<Square key={f+r.toString()} | ||
file={f} | ||
rank={r} | ||
piece={getPiece(props.squares, f, r)} | ||
selected={props.selected && props.selected.startsWith(f+r)} | ||
threatened={typeof props.threatenedSquares[0] !== "undefined" ? props.threatenedSquares[0].filter(square => square.file===f && square.rank === r).length : false} /> | ||
</td>)} | ||
</tr>)} | ||
</tbody> | ||
</table> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters