Hi all,
Okay, so now I'm wondering if I should put all my functions like keyboard practice etc into separate includes for easier management, but I know there's one brace I have to remove in this code. I fixed the while loop for exit now adding a left brace, but somewhere there's a brace that must be removed and I can't figure out which one.
Here is my code, again. Is it regarding the code that I just recently added for speech manager? I suppose I'll save the file under a different name and remove different braces although that wouldn't do me any good and only would mess me up even more.
#include "dynamic_menu.bgt"
#include "speech_manager.bgt"
//Sounds
sound music; //The music sound.
sound error_sound; // The sound for an incorrect sequence.
sound[] tone(4); // The four sequence tone sounds.
speech_manager speech; //The global variable to call the speech manager methods from.
void main()
{
speech.init("Config.dat", "310021561");
tone[0].load("sounds/1.wav");
tone[0].volume = -10;
tone[1].load("sounds/2.wav");
tone[1].volume = -10;
tone[2].load("sounds/3.wav");
tone[2].volume = -10;
tone[3].load("sounds/4.wav");
tone[3].volume = -10;
// Load error sound.
error_sound.load("sounds/error.wav");
tts_voice v;
show_game_window("Memory Train Deluxe");
dynamic_menu menu;
menu.set_speech_mode(speech.mode);
menu.set_tts_object(speech.sapi);
menu.add_item_tts("Start Game");
menu.add_item_tts("Keyboard Practice");
menu.add_item_tts("Speech Options");
menu.add_item_tts("Exit Game");
int choice; //This variable stores the players choice for menu options.
do
{
music.stream("sounds/music/menu.ogg");
music.volume=-10;
music.play_looped();
speech.speak_wait("Welcome to Memory Train Deluxe!");
choice = menu.run("Use the arrow keys to navigate the menu, enter to activate an option.", true);
if(choice==1)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
play_round();
}
else if(choice==2)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
keyboard_practice();
}
else if(choice==3)
{
speech.configure();
}
{
while(choice!=0 and choice!=4);
speech.speak_wait("See ya later!");
}
void keyboard_practice()
{
tts_voice v;
speech.speak_wait("Press any arrow key to find out which tone it is associated with.");
speech.speak_wait("Press Escape to exit keyboard practice.");
while(!key_pressed(KEY_ESCAPE))
{
if(key_pressed(KEY_LEFT))
{
play_tone(0);
}
else if(key_pressed(KEY_DOWN))
{
play_tone(1);
}
else if(key_pressed(KEY_RIGHT))
{
play_tone(2);
}
else if(key_pressed(KEY_UP))
{
play_tone(3);
}
wait(5);
}
}
void play_tone(int i)
{
tone[i].stop();
tone[i].play();
}
void play_round()
{
bool game_over = false; //Game will progressively get harder if this remains false.
int[] sequence; //The running sequence of tones to remember sequencially.
int seqlength = 0;
float tbt = 500; // The speed at which tones are played after one another.
float tbi = 2000; //Gives the player two seconds to choose a tone from a sequence.
do
{
seqlength++;
sequence.resize(seqlength);
sequence[seqlength-1] = random(0,3);
output_sequence(@sequence, tbt);
game_over = input_sequence(@sequence, tbi);
if((seqlength%5) == 0)
{
tbi = tbi*0.9;
if(tbi < 150)
{
tbi = 150;
}
}
}
while(!game_over);
int score = seqlength-1;
tts_voice v;
speech.speak_wait("Your final score is " + score);
}
void output_sequence(int[]@ sequence, float tbi)
{
timer clock;
int current;
for(uint i=0; i<sequence.length(); i++)
{
if(i>0)
{
clock.restart();
while(clock.elapsed < tbi)
{
wait(5);
}
}
current = sequence[i];
play_tone(current);
while(tone[current].playing)
{
wait(5);
}
}
bool input_sequence(int[] @sequence, float tbi)
{
timer clock;
for(uint i=0; i<sequence.length(); i++)
{
clock.restart();
int input = -1; // Set it to something invalid.
while(clock.elapsed < tbi)
{
if(key_pressed(KEY_LEFT))
{
input = 0;
}
else if(key_pressed(KEY_DOWN))
{
input = 1;
}
else if(key_pressed(KEY_RIGHT))
{
input = 2;
}
else if(key_pressed(KEY_UP))
{
input = 3;
}
if(input>=0)
{
break; // Stop waiting because something was typed.
}
wait(5);
}
if(input!=sequence[i])
{
error_sound.play_wait();
return true;
}
play_tone(input);
}
clock.restart();
while(clock.elapsed < 1000)
{
wait(5);
}
return false;
}
}