diff --git a/src/Scarf.js b/src/Scarf.js index 6ab4e9f..11bc275 100644 --- a/src/Scarf.js +++ b/src/Scarf.js @@ -64,10 +64,14 @@ export default class Scarf extends Component { Array.from(pattern).forEach((value, index) => { const crochet = Scarf.createCrochet(index, y); - if (value === 'v') { - this.white += crochet; - } else { - this.red += crochet; + switch (value) { + case 'v': + this.white += crochet; + break; + case 'x': + break; + default: + this.red += crochet; } }); } diff --git a/src/pattern/Generator.js b/src/pattern/Generator.js index 99953cc..26b9301 100644 --- a/src/pattern/Generator.js +++ b/src/pattern/Generator.js @@ -39,7 +39,7 @@ export default class Generator { * * @return {String} */ - static messUp(line, errors = LINE / 10) { + static messUp(line, errors = LINE / 10, holes = 2) { const messedUp = Array.from(line); for (let i = 0; i < errors; i++) { @@ -48,6 +48,14 @@ export default class Generator { messedUp[index] = messedUp[index] === 'v' ? ' ' : 'v'; } + for (let i = 0; i < errors; i++) { + const index = Math.floor(Math.random() * messedUp.length); + + if (Math.random() < 0.2) { + messedUp[index] = 'x'; + } + } + return messedUp.join(''); }