Options screen work started.

master
Ben Burlingham 9 years ago
parent 7c23267c98
commit 8500c8be25
  1. 5
      App.js
  2. 6
      actions/mode.actions.js
  3. 8
      actions/options/options.actions.js
  4. 25
      components/options/option.component.js
  5. 26
      components/options/options.component.js
  6. 2
      components/welcome/new-game.component.js
  7. 6
      controllers/grid.controller.js
  8. 4
      controllers/titlebar.controller.js
  9. 4
      index.js
  10. 14
      models/equality.model.js
  11. 42
      models/factors.model.js
  12. 42
      models/inequality.model.js
  13. 42
      models/multiples.model.js
  14. 2
      reducers/mode.reducer.js
  15. 19
      reducers/options/options.reducer.js
  16. 30
      sass/options/options.scss

@ -3,8 +3,9 @@ import { connect } from 'react-redux';
import * as ModeActions from './actions/mode.actions'; import * as ModeActions from './actions/mode.actions';
import Board from './components/board/board.component';
import Welcome from './components/welcome/welcome.component'; import Welcome from './components/welcome/welcome.component';
import Options from './components/options/options.component';
import Board from './components/board/board.component';
export class App extends Component { export class App extends Component {
render() { render() {
@ -13,6 +14,8 @@ export class App extends Component {
switch (this.props.mode) { switch (this.props.mode) {
case ModeActions.WELCOME: case ModeActions.WELCOME:
return <Welcome />; return <Welcome />;
case ModeActions.OPTIONS:
return <Options />
case ModeActions.BOARD: case ModeActions.BOARD:
return <Board />; return <Board />;
} }

@ -1,6 +1,7 @@
// Game mode actions and action creators. // Game mode actions and action creators.
export const MODE_ACTION = 'MODE_ACTION'; export const MODE_ACTION = 'MODE_ACTION';
export const WELCOME = 'MODE_WELCOME'; export const WELCOME = 'MODE_WELCOME';
export const OPTIONS = 'MODE_OPTIONS';
export const BOARD = 'MODE_BOARD'; export const BOARD = 'MODE_BOARD';
export const welcome = () => ({ export const welcome = () => ({
@ -8,6 +9,11 @@ export const welcome = () => ({
action: WELCOME action: WELCOME
}); });
export const options = () => ({
type: MODE_ACTION,
action: OPTIONS
});
export const board = () => ({ export const board = () => ({
type: MODE_ACTION, type: MODE_ACTION,
action: BOARD action: BOARD

@ -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>
);
};
};

@ -27,7 +27,7 @@ export default class NewGame extends Component {
handleKeydown(e) { handleKeydown(e) {
if (e.keyCode === 32) { if (e.keyCode === 32) {
this.props.dispatch(ModeActions.board()); this.props.dispatch(ModeActions.options());
} }
}; };

@ -1,5 +1,5 @@
import * as GridActions from '../actions/board/grid.actions'; import * as GridActions from '../actions/board/grid.actions';
import ValuesCtrl from './values.controller'; import MultiplesModel from '../models/multiples.model';
import SETTINGS from '../AppSettings'; import SETTINGS from '../AppSettings';
let values; let values;
@ -10,12 +10,12 @@ const GridCtrl = {
getValues: () => values, getValues: () => values,
generateValues: (level) => { generateValues: (level) => {
values = ValuesCtrl.generate(SETTINGS.GRID_WIDTH * SETTINGS.GRID_HEIGHT, level); values = MultiplesModel.generate(SETTINGS.GRID_WIDTH * SETTINGS.GRID_HEIGHT, level);
dispatch(GridActions.update(values)); dispatch(GridActions.update(values));
}, },
isCompleted: (level) => { isCompleted: (level) => {
return ValuesCtrl.checkComplete(values, level) return MultiplesModel.checkComplete(values, level)
}, },
hideValue: (index) => { hideValue: (index) => {

@ -1,5 +1,5 @@
import * as TitlebarActions from '../actions/board/titlebar.actions'; import * as TitlebarActions from '../actions/board/titlebar.actions';
import ValuesCtrl from './values.controller'; import MultiplesModel from '../models/multiples.model';
let dispatch; let dispatch;
@ -7,7 +7,7 @@ const TitlebarCtrl = {
setDispatch: d => dispatch = d, setDispatch: d => dispatch = d,
setTitle: (level) => { setTitle: (level) => {
const title = ValuesCtrl.getTitle(level); const title = MultiplesModel.getTitle(level);
dispatch(TitlebarActions.update(title)); dispatch(TitlebarActions.update(title));
} }
}; };

@ -13,6 +13,7 @@ import scorebarReducer from './reducers/board/scorebar.reducer';
import messageReducer from './reducers/board/message.reducer'; import messageReducer from './reducers/board/message.reducer';
import troggleReducer from './reducers/board/troggle.reducer'; import troggleReducer from './reducers/board/troggle.reducer';
import titlebarReducer from './reducers/board/titlebar.reducer'; import titlebarReducer from './reducers/board/titlebar.reducer';
import optionsReducer from './reducers/options/options.reducer';
const reducers = combineReducers({ const reducers = combineReducers({
mode: modeReducer, mode: modeReducer,
@ -22,7 +23,8 @@ const reducers = combineReducers({
message: messageReducer, message: messageReducer,
troggles: troggleReducer, troggles: troggleReducer,
grid: gridReducer, grid: gridReducer,
titlebar: titlebarReducer titlebar: titlebarReducer,
options: optionsReducer
}); });
const store = createStore(reducers); const store = createStore(reducers);

@ -1,8 +1,4 @@
const validate = function(value, level) { const MultiplesModel = {
return ((value || -1) % (level + 2) === 0);
};
const ValuesCtrl = {
// Anagrams, multiples, equality // Anagrams, multiples, equality
generate(n, level) { generate(n, level) {
const values = []; const values = [];
@ -13,7 +9,7 @@ const ValuesCtrl = {
values.push({ values.push({
value: v, value: v,
show: true, show: true,
valid: validate(v, level) valid: this.validate(v, level)
}); });
}; };
@ -37,6 +33,10 @@ const ValuesCtrl = {
return true; return true;
} }
validate(value, level) {
return ((value || -1) % (level + 2) === 0);
};
}; };
export default ValuesCtrl; 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,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;

@ -1,6 +1,6 @@
import * as ModeActions from '../actions/mode.actions'; import * as ModeActions from '../actions/mode.actions';
const initial = ModeActions.WELCOME; const initial = ModeActions.OPTIONS;
const reducer = (state = initial, action) => { const reducer = (state = initial, action) => {
if (action.type !== ModeActions.MODE_ACTION) { if (action.type !== ModeActions.MODE_ACTION) {

@ -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…
Cancel
Save