@@ -5,6 +5,7 @@ import * as WordMod from "./Word";
55import { Word } from "./Word" ;
66import * as LetterMod from "./Letter" ;
77import { SuccessStatus } from "./SuccessStatus" ;
8+ import { Letter } from "./Letter" ;
89
910export interface Board {
1011 words : Word [ ] ;
@@ -35,15 +36,24 @@ export function clone(board: Board): Board {
3536}
3637
3738export function generateWords ( amount : number ) : Word [ ] {
38- const gameWords = [ ] ;
39+ const gameWords : Word [ ] = [ ] ;
3940
4041 for ( let i = 0 ; i < amount ; i += 1 ) {
4142 const nextWord = getRandomItem ( wordBank ) ;
4243 const nextGameWord = WordMod . init ( nextWord ) ;
4344 gameWords . push ( nextGameWord ) ;
4445 }
4546
46- return gameWords ;
47+ const first = gameWords . shift ( ) ;
48+
49+ const gameWordsWithSpaces = gameWords . reduce (
50+ ( all , word ) => {
51+ return [ ...all , WordMod . init ( " " ) , word ] ;
52+ } ,
53+ [ first ] as Word [ ]
54+ ) ;
55+
56+ return gameWordsWithSpaces ;
4757}
4858
4959export function moveByKey ( char : string , code : KeyCode , board : Board ) : Board {
@@ -55,7 +65,9 @@ export function moveByKey(char: string, code: KeyCode, board: Board): Board {
5565 return moveBackward ( board ) ;
5666 }
5767
58- if ( code === KeyCode . Space ) {
68+ const currLetter = getCurrentLetter ( board ) ;
69+
70+ if ( code === KeyCode . Space && currLetter . char !== " " ) {
5971 if ( board . currentWordLetterIndex === 0 ) {
6072 return board ;
6173 }
@@ -216,3 +228,10 @@ export function getLetterSuccessAmount(board: Board) {
216228 return wordsAcc + wordSum ;
217229 } , 0 ) ;
218230}
231+
232+ function getCurrentLetter ( board : Board ) : Letter {
233+ const currWord = board . words [ board . currentWordIndex ] ;
234+ const currLetter = currWord . letters [ board . currentWordLetterIndex ] ;
235+
236+ return currLetter ;
237+ }
0 commit comments