diff --git a/index.html b/index.html index 294d04f..a84d1b3 100755 --- a/index.html +++ b/index.html @@ -13,50 +13,6 @@

Keep Talking and Nobody Explodes

-
-

Simon Says

- -
- - - -
- -
-
-
 
 
-
-
-
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

Who's on First

diff --git a/ktane.js b/ktane.js index 63a0b21..8b892c8 100755 --- a/ktane.js +++ b/ktane.js @@ -39,46 +39,6 @@ $('section').each(function () { id && $('#navList').append($('
  • ').append($a)); }); -(function () { - /** - * Simon - */ - var $checkbox = $('#simonVowel'), - $strikeButtons = $('#sectionSimon input[name="simonStrikes"]'), - $arrows = [], - mappings = [ // (hasVowel, strikes) -> list of visible arrows by ID - // No vowel - [ - ['RB', 'BY', 'YR'], - ['GY', 'YG'], - ['RY', 'BG', 'GB', 'YR'] - ], - // Vowel - [ - ['RB', 'BR', 'GY', 'YG'], - ['RY', 'BG', 'GB', 'YR'], - ['RG', 'BR', 'GY', 'YB'] - ] - ]; - - $('#simonBoard').find('.arrow').each(function (i, arrow) { - $arrows[arrow.id.replace(/^.*(?=..$)/, '')] = $(arrow); - }); - - $('#sectionSimon input').on('change', function () { - var hasVowel = +$checkbox.prop('checked'), - strikes = $strikeButtons.filter(':checked').val(); - - for (var id in $arrows) { - $arrows[id].removeClass('active'); - } - - $.each(mappings[hasVowel][strikes], function (i, id) { - $arrows[id].addClass('active'); - }); - }).first().trigger('change'); -})(); - (function () { /** * Who's on First diff --git a/src/App.css b/src/App.css index b0381a2..c18ff2c 100755 --- a/src/App.css +++ b/src/App.css @@ -108,127 +108,6 @@ nav { padding: 0.1em 0.5em; } -#simonInputs { - float: left; - margin-right: 5em; -} -.collapsed #simonBoard { - display: none; -} -#simonBoard { - display: inline-block; - padding-bottom: 40px; /* Compensate for height increase as a result of rotation */ - position: relative; - transform: rotate(45deg); -} -#simonBoard > div > div { - border: 2px solid black; - display: inline-block; - height: 64px; - width: 64px; -} -#simonBoard > .simonRow:first-child > div { - border-top-width: 4px; -} -#simonBoard > .simonRow:first-child + div > div { - border-bottom-width: 4px; -} -#simonBoard > .simonRow > div:first-child { - border-left-width: 4px; -} -#simonBoard > .simonRow > div:last-child { - border-right-width: 4px; -} -.simonRed { - background: radial-gradient(#fb9a9a, #fc7373, red); -} -.simonYellow { - background: radial-gradient(#fbfb9a, #fcfc73, yellow); -} -.simonBlue { - background: radial-gradient(#9a9afb, #7373fc, blue); -} -.simonGreen { - background: radial-gradient(#98c998, #72b772, green); -} - -.arrow { - background-color: black; - height: 10px; - width: 50px; - opacity: 0; - position: absolute; -} -.arrow::after { - content: ''; - border-top: 10px solid transparent; - border-left: 20px solid black; - border-bottom: 10px solid transparent; - height: 0; - width: 0; - margin-left: 50px; - position: absolute; - top: -5px; -} -#arrowRB { - top: 70px; - left: 10px; - transform: rotate(-90deg); -} -#arrowBR { - top: 60px; - left: 10px; - transform: rotate(90deg); -} -#arrowBY { - top: 30px; - left: 45px; -} -#arrowYB { - top: 30px; - left: 45px; - transform: rotate(180deg); -} -#arrowYG { - top: 60px; - left: 80px; - transform: rotate(90deg); -} -#arrowGY { - top: 70px; - left: 80px; - transform: rotate(-90deg); -} -#arrowGR { - top: 100px; - left: 45px; - transform: rotate(180deg); -} -#arrowRG { - top: 100px; - left: 45px; -} -#arrowRY { - top: 66px; - left: 44px; - transform: rotate(-45deg); -} -#arrowYR { - top: 66px; - left: 44px; - transform: rotate(135deg); -} -#arrowBG { - top: 64px; - left: 44px; - transform: rotate(45deg); -} -#arrowGB { - top: 64px; - left: 44px; - transform: rotate(-135deg); -} - #sectionWof { white-space: nowrap; } diff --git a/src/App.js b/src/App.js index 435656e..cd96d74 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React from 'react'; import './App.css'; import ButtonModule from "./components/ButtonModule"; import KeypadsModule from "./components/KeypadsModule"; +import SimonSaysModule from "./components/SimonSaysModule"; import WiresModule from "./components/WiresModule"; function App() { @@ -14,6 +15,7 @@ function App() { + ); } diff --git a/src/components/KeypadsModule.js b/src/components/KeypadsModule.js index c7473c9..fc6d12c 100644 --- a/src/components/KeypadsModule.js +++ b/src/components/KeypadsModule.js @@ -114,10 +114,6 @@ export default class KeypadsModule extends KtaneModule { ) } - resetState() { - this.setState(this.getInitialState()); - } - toggleHighlight(event) { this.keyColumnMap = this.keyColumnMap || this.computeKeyColumnMap(); diff --git a/src/components/SimonSaysModule.js b/src/components/SimonSaysModule.js new file mode 100644 index 0000000..a470150 --- /dev/null +++ b/src/components/SimonSaysModule.js @@ -0,0 +1,87 @@ +import KtaneModule from "./KtaneModule"; +import React from "react"; +import "../css/SimonSaysModule.css"; + +export default class SimonSaysModule extends KtaneModule { + constructor(props) { + super(props); + + this.arrowsWithoutVowel = [ + ["RB", "BY", "YR"], + ["GY", "YG"], + ["RY", "BG", "GB", "YR"], + ]; + this.arrowsWithVowel = [ + ["RB", "BR", "GY", "YG"], + ["RY", "BG", "GB", "YR"], + ["RG", "BR", "GY", "YB"], + ]; + + this.setStrikes = this.setStrikes.bind(this); + this.toggleVowel = this.toggleVowel.bind(this); + } + + computeArrowsShown(state) { + return (state.hasVowel ? this.arrowsWithVowel : this.arrowsWithoutVowel)[this.state.strikes]; + } + + getInitialState() { + return { + hasVowel: false, + strikes: 0 + }; + } + + getTitle() { + return "Simon Says"; + } + + mainRender() { + return ( + <> +
    + + +
      + { + [...Array(3).keys()].map(i => ( +
    • + +
    • + )) + } +
    +
    + +
    +
    +
     
    +
     
    +
    +
    +
     
    +
     
    +
    + { + this.computeArrowsShown(this.state).map(arrow => ( +
    + )) + } +
    + + ) + } + + setStrikes(event) { + this.setState({strikes: parseInt(event.currentTarget.value, 10)}) + } + + toggleVowel(event) { + this.setState(state => ({hasVowel: !state.hasVowel})); + } +} diff --git a/src/css/SimonSaysModule.css b/src/css/SimonSaysModule.css new file mode 100644 index 0000000..45e2d97 --- /dev/null +++ b/src/css/SimonSaysModule.css @@ -0,0 +1,119 @@ +#simonInputs { + float: left; + margin-right: 5em; +} +.collapsed #simonBoard { + display: none; +} +#simonBoard { + display: inline-block; + padding-bottom: 40px; /* Compensate for height increase as a result of rotation */ + position: relative; + transform: rotate(45deg); +} +#simonBoard > div > div { + border: 2px solid black; + display: inline-block; + height: 64px; + width: 64px; +} +#simonBoard > .simonRow:first-child > div { + border-top-width: 4px; +} +#simonBoard > .simonRow:first-child + div > div { + border-bottom-width: 4px; +} +#simonBoard > .simonRow > div:first-child { + border-left-width: 4px; +} +#simonBoard > .simonRow > div:last-child { + border-right-width: 4px; +} +.simonRed { + background: radial-gradient(#fb9a9a, #fc7373, red); +} +.simonYellow { + background: radial-gradient(#fbfb9a, #fcfc73, yellow); +} +.simonBlue { + background: radial-gradient(#9a9afb, #7373fc, blue); +} +.simonGreen { + background: radial-gradient(#98c998, #72b772, green); +} + +.arrow { + background-color: black; + height: 10px; + width: 50px; + position: absolute; +} +.arrow::after { + content: ''; + border-top: 10px solid transparent; + border-left: 20px solid black; + border-bottom: 10px solid transparent; + height: 0; + width: 0; + margin-left: 50px; + position: absolute; + top: -5px; +} +#arrowRB { + top: 70px; + left: 10px; + transform: rotate(-90deg); +} +#arrowBR { + top: 60px; + left: 10px; + transform: rotate(90deg); +} +#arrowBY { + top: 30px; + left: 45px; +} +#arrowYB { + top: 30px; + left: 45px; + transform: rotate(180deg); +} +#arrowYG { + top: 60px; + left: 80px; + transform: rotate(90deg); +} +#arrowGY { + top: 70px; + left: 80px; + transform: rotate(-90deg); +} +#arrowGR { + top: 100px; + left: 45px; + transform: rotate(180deg); +} +#arrowRG { + top: 100px; + left: 45px; +} +#arrowRY { + top: 66px; + left: 44px; + transform: rotate(-45deg); +} +#arrowYR { + top: 66px; + left: 44px; + transform: rotate(135deg); +} +#arrowBG { + top: 64px; + left: 44px; + transform: rotate(45deg); +} +#arrowGB { + top: 64px; + left: 44px; + transform: rotate(-135deg); +}