parent
7c23267c98
commit
8500c8be25
16 changed files with 261 additions and 16 deletions
@ -0,0 +1,8 @@ |
||||
export const OPTIONS_ACTION = 'OPTIONS_ACTION'; |
||||
export const UPDATE = 'OPTIONS_UPDATE'; |
||||
|
||||
export const update = (selected) => ({ |
||||
type: OPTIONS_ACTION, |
||||
action: UPDATE, |
||||
selected: selected |
||||
}); |
@ -0,0 +1,25 @@ |
||||
import { Component } from 'react'; |
||||
import { connect } from 'react-redux'; |
||||
|
||||
export class Option extends Component { |
||||
render() { |
||||
const className = ['option']; |
||||
console.log(this.props.selected + ' ' + this.props.index) |
||||
|
||||
if (this.props.selected === this.props.index) { |
||||
className.push('selected'); |
||||
} |
||||
|
||||
return ( |
||||
<div className={className.join(' ')}>{this.props.value}</div> |
||||
); |
||||
}; |
||||
}; |
||||
|
||||
const select = (state) => { |
||||
return { |
||||
selected: state.options |
||||
}; |
||||
}; |
||||
|
||||
export default connect(select)(Option); |
@ -0,0 +1,26 @@ |
||||
require('../../sass/options/options.scss'); |
||||
|
||||
import { Component } from 'react'; |
||||
import Option from './option.component'; |
||||
|
||||
export default class Options extends Component { |
||||
render() { |
||||
const values = ['Multiples', 'Factors', 'Equality', 'Inequality']; |
||||
const optionsElements = []; |
||||
|
||||
values.map((v, i) => { |
||||
optionsElements.push(<Option value={v} index={i} key={i} />); |
||||
}); |
||||
|
||||
return ( |
||||
<div className='options'> |
||||
<div className='line'>Which game would you like to play?</div> |
||||
<hr /> |
||||
<div className='line'>Use the arrow keys to move.</div> |
||||
<div className='line'>Press spacebar to select.</div> |
||||
<hr /> |
||||
{optionsElements} |
||||
</div> |
||||
); |
||||
}; |
||||
}; |
@ -0,0 +1,42 @@ |
||||
const MultiplesModel = { |
||||
// Anagrams, multiples, equality
|
||||
generate(n, level) { |
||||
const values = []; |
||||
let v; |
||||
|
||||
for (let i = 0; i < n; i++) { |
||||
v = Math.ceil(Math.random() * 1000); |
||||
values.push({ |
||||
value: v, |
||||
show: true, |
||||
valid: this.validate(v, level) |
||||
}); |
||||
}; |
||||
|
||||
return values; |
||||
}, |
||||
|
||||
getTitle(level) { |
||||
return `Multiples of ${level + 2}`; |
||||
}, |
||||
|
||||
getError(value, level) { |
||||
return `Oops! ${value} is not a multiple of ${level + 2}.`; |
||||
}, |
||||
|
||||
checkComplete(values, level) { |
||||
for (let i = 0; i < values.length; i++) { |
||||
if (values[i].valid === true && values[i].show === true) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
}, |
||||
|
||||
validate(value, level) { |
||||
return ((value || -1) % (level + 2) === 0); |
||||
} |
||||
}; |
||||
|
||||
export default MultiplesModel; |
@ -0,0 +1,42 @@ |
||||
const MultiplesModel = { |
||||
// Anagrams, multiples, equality
|
||||
generate(n, level) { |
||||
const values = []; |
||||
let v; |
||||
|
||||
for (let i = 0; i < n; i++) { |
||||
v = Math.ceil(Math.random() * 1000); |
||||
values.push({ |
||||
value: v, |
||||
show: true, |
||||
valid: this.validate(v, level) |
||||
}); |
||||
}; |
||||
|
||||
return values; |
||||
}, |
||||
|
||||
getTitle(level) { |
||||
return `Multiples of ${level + 2}`; |
||||
}, |
||||
|
||||
getError(value, level) { |
||||
return `Oops! ${value} is not a multiple of ${level + 2}.`; |
||||
}, |
||||
|
||||
checkComplete(values, level) { |
||||
for (let i = 0; i < values.length; i++) { |
||||
if (values[i].valid === true && values[i].show === true) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
}, |
||||
|
||||
validate(value, level) { |
||||
return ((value || -1) % (level + 2) === 0); |
||||
} |
||||
}; |
||||
|
||||
export default MultiplesModel; |
@ -0,0 +1,42 @@ |
||||
const MultiplesModel = { |
||||
// Anagrams, multiples, equality
|
||||
generate(n, level) { |
||||
const values = []; |
||||
let v; |
||||
|
||||
for (let i = 0; i < n; i++) { |
||||
v = Math.ceil(Math.random() * 1000); |
||||
values.push({ |
||||
value: v, |
||||
show: true, |
||||
valid: this.validate(v, level) |
||||
}); |
||||
}; |
||||
|
||||
return values; |
||||
}, |
||||
|
||||
getTitle(level) { |
||||
return `Multiples of ${level + 2}`; |
||||
}, |
||||
|
||||
getError(value, level) { |
||||
return `Oops! ${value} is not a multiple of ${level + 2}.`; |
||||
}, |
||||
|
||||
checkComplete(values, level) { |
||||
for (let i = 0; i < values.length; i++) { |
||||
if (values[i].valid === true && values[i].show === true) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
}, |
||||
|
||||
validate(value, level) { |
||||
return ((value || -1) % (level + 2) === 0); |
||||
} |
||||
}; |
||||
|
||||
export default MultiplesModel; |
@ -0,0 +1,19 @@ |
||||
const Immutable = require('immutable'); |
||||
|
||||
import * as OptionsActions from '../../actions/options/options.actions'; |
||||
|
||||
const initial = 0; |
||||
|
||||
const reducer = (state = initial, action) => { |
||||
if (action.type !== OptionsActions.OPTIONS_ACTION) { |
||||
return state; |
||||
} |
||||
|
||||
if (action.action === OptionsActions.UPDATE) { |
||||
return action.selected; |
||||
} |
||||
|
||||
return state; |
||||
}; |
||||
|
||||
export default reducer; |
@ -0,0 +1,30 @@ |
||||
.options { |
||||
$w: 600px; |
||||
|
||||
.line { |
||||
line-height:50px; |
||||
margin:5px auto; |
||||
text-align:center; |
||||
width:$w; |
||||
} |
||||
|
||||
hr { |
||||
border:0; |
||||
border-top:1px #ccc solid; |
||||
margin:50px auto; |
||||
width:$w; |
||||
} |
||||
|
||||
.option { |
||||
border:1px solid #444; |
||||
height:50px; |
||||
line-height:50px; |
||||
margin:5px auto; |
||||
text-align:center; |
||||
width:$w; |
||||
} |
||||
|
||||
.selected { |
||||
background:rgba(17, 250, 87, 0.5); |
||||
} |
||||
} |
Loading…
Reference in new issue