/** * Helper method to determine if any cubes are neighboured */ bool Phonemic::noNeighbors() { for(CubeID cube: CubeSet::connected()) { Neighborhood hood = Neighborhood(cube); if(hood.hasCubeAt(LEFT) || hood.hasCubeAt(RIGHT)) return false; } return true; }
/** * Helper method to locate the leftmost cube * in a series of neighboured cubes. */ unsigned Phonemic::leftmostNeighbor(unsigned id) { // Find leftmost cube Neighborhood hood = Neighborhood(id); CubeID leftmostID = id; while(hood.hasCubeAt(LEFT)) { leftmostID = hood.cubeAt(LEFT); hood = Neighborhood(leftmostID); } return leftmostID; }
/** * Helper method to decide if a series of cubes * spells the current word. */ void Phonemic::checkForWord(unsigned id) { // Find leftmost cube CubeID nextID = leftmostNeighbor(id); Neighborhood hood = Neighborhood(nextID); // Find the sequence of symbols spelled by // the sequence of cubes int wordAttempt[MAX_WORD_SIZE]; wordAttempt[0] = cubes[nextID].symbol; int i = 1; while(hood.hasCubeAt(RIGHT)) { nextID = hood.cubeAt(RIGHT); hood = Neighborhood(nextID); wordAttempt[i] = cubes[nextID].symbol; i++; } wordAttempt[i] = -1; // Check for a match bool match = true; for(int i = 0; i < /*MAX_WORD_SIZE*/ length; i++) { if(/*order[i]*/ wordFamilies[level].phonemes[word][i] != wordAttempt[i]) { match = false; break; } //if(wordFamilies[level].phonemes[word][i] == -1) break; } // Recognize match if(match) { //sounding.play(SfxChime); //sounding.play(SfxCat); sounding.play(/*SfxChime*/ *wordFamilies[level].words[word].sound); allSmiles(); System::paint(); state = WORD_FOUND; } }
/** * Helper method to sounds out the sequence of cubes. */ void Phonemic::soundOut(unsigned id) { // Wait for audio channel to be clear if(sounding.isPlaying()) return; // Highlight the current cube cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[1]); System::paint(); System::finish(); // Play the current cube's sound sounding.play(*cubes[id].sound); while(sounding.isPlaying()) { System::yield(); } // Return the cube to its normal appearance cubes[id].vid.bg0.image(vec(0,0), *cubes[id].images[0]); // Play any cube connected to the right Neighborhood hood = Neighborhood(id); if(hood.hasCubeAt(RIGHT)) soundOut(hood.cubeAt(RIGHT)); }