This file contains hidden or 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
    
  
  
    
  | updateScore = (key) => { | |
| let { dice } = this.props; | |
| let { scores } = this.state; | |
| let entry = scores.find( d => d.name === key ); | |
| if (entry.value) { | |
| entry.score = singles(entry.value, dice); | |
| } else if (entry.addAll) { | |
| entry.score = addAllDice(dice); | |
| } else { | |
| entry.score = staticScore(entry.name); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | state = { | |
| scores: [ | |
| { section: 'upper', name: 'Ones', score: null, value: 1 }, | |
| { section: 'upper', name: 'Twos', score: null, value: 2 }, | |
| { section: 'upper', name: 'Threes', score: null, value: 3 }, | |
| { section: 'upper', name: 'Fours', score: null, value: 4 }, | |
| { section: 'upper', name: 'Fives', score: null, value: 5 }, | |
| { section: 'upper', name: 'Sixes', score: null, value: 6 }, | |
| { section: 'lower', name: 'Three Of A Kind', score: null, addAll: true }, | |
| { section: 'lower', name: 'Four Of A Kind', score: null, addAll: true }, | 
  
    
      This file contains hidden or 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
    
  
  
    
  | export const singles = (value, dice) => { | |
| return dice.filter( d => d === value ).reduce( (total, val) => { | |
| return total + value; | |
| }, 0); | |
| } | |
| export const addAllDice = (dice) => { | |
| return dice.reduce( (total, val) => { | |
| return total + val; | |
| }, 0); | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import React from 'react'; | |
| const ScoreRow = ({ name, score }) => ( | |
| <li className="collection-item"> | |
| <div> | |
| {name} | |
| { score !== null ? | |
| <span className="secondary-content">{score}</span> : | |
| <i style={styles.icon} className="secondary-content material-icons">play_circle_filled</i> | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import React from 'react'; | |
| import ScoreRow from './ScoreRow'; | |
| const total = (score, label) => ( | |
| <li | |
| key={label} | |
| className="collection-item" | |
| > | |
| <div> | |
| {label} | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import React from 'react'; | |
| import ScoreSection from './ScoreSection'; | |
| class ScoreCard extends React.Component { | |
| state = { | |
| scores: [ | |
| { section: 'upper', name: 'Ones', score: null }, | |
| { section: 'upper', name: 'Twos', score: null }, | |
| { section: 'upper', name: 'Threes', score: null }, | |
| { section: 'upper', name: 'Fours', score: null }, | 
  
    
      This file contains hidden or 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
    
  
  
    
  | toggleKept = (i) => { | |
| let { keep } = this.state; | |
| let updatedKeep; | |
| if (keep.includes(i)) | |
| updatedKeep = keep.filter( k => k !== i ) | |
| else | |
| updatedKeep = [...keep, i] | |
| this.setState({ keep: updatedKeep }) | 
  
    
      This file contains hidden or 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
    
  
  
    
  | rollDice = () => { | |
| let { keep } = this.state; | |
| let dice = this.state.dice.map( (el, i) => { | |
| if (keep.includes(i)) | |
| return el | |
| return Math.floor(Math.random() * 6) + 1 | |
| }); | |
| this.setState( (state) => { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import React from 'react'; | |
| import Board from './Board'; | |
| import ScoreCard from './ScoreCard'; | |
| class Game extends React.Component { | |
| state = { roll: 0, dice: [...new Array(5)], keep: [] }; | |
| rollDice = () => { | |
| let dice = this.state.dice.map( (el, i) => { | |
| return Math.floor(Math.random() * 6 ) + 1 | 
  
    
      This file contains hidden or 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
    
  
  
    
  | import React from 'react'; | |
| import d1 from './images/d1.png'; | |
| import d2 from './images/d2.png'; | |
| import d3 from './images/d3.png'; | |
| import d4 from './images/d4.png'; | |
| import d5 from './images/d5.png'; | |
| import d6 from './images/d6.png'; | |
| const images = { d1, d2, d3, d4, d5, d6 }; |