View Full Version : Help: TurboC++
Sallyqq
13-08-2009, 10:24 PM
Hello people,
I need help on turbo c++
I am writing a memory game program. I am stuck. I am making example Led1 Led2 light up then you have to enter the sequence Led1=A key
and Led2=B key. I only know how to make it when Led1 light up and someone press wrong press the B key then the program will tell him/her wrong. If program light up Led 1 then Led 2. Then the person has to press A then B. I dont know how to make the program tell him/her if the person press A then A again.
Anyone can enlighten me? With any tutorial or so.
thank you.
Kiwi8
13-08-2009, 10:34 PM
Hello people,
I need help on turbo c++
I am writing a memory game program. I am stuck. I am making example Led1 Led2 light up then you have to enter the sequence Led1=A key
and Led2=B key. I only know how to make it when Led1 light up and someone press wrong press the B key then the program will tell him/her wrong. If program light up Led 1 then Led 2. Then the person has to press A then B. I dont know how to make the program tell him/her if the person press A then A again.
Anyone can enlighten me? With any tutorial or so.
thank you.
Your program should first generate the sequence to be displayed.
Depending on whether u need to save memory space or easier implemention, an example is to use bits.
For example, long integer allows u to have sequence of at least 32 bits, ie 32 LEDs.
U can also use array to store the status of the LEDs.
Sallyqq
14-08-2009, 07:28 PM
Your program should first generate the sequence to be displayed.
Depending on whether u need to save memory space or easier implemention, an example is to use bits.
For example, long integer allows u to have sequence of at least 32 bits, ie 32 LEDs.
U can also use array to store the status of the LEDs.
Thank for the reply. I know how to make it generate in sequence already. For people to answer correctly/wrongly with more than 2answer, I dont know how to make.
Kiwi8
14-08-2009, 08:35 PM
Thank for the reply. I know how to make it generate in sequence already. For people to answer correctly/wrongly with more than 2answer, I dont know how to make.
U can run a do-while loop.
In the loop, capture the user's input (one at a time per loop).
Compare this input to the relevant generated LED status (either the array index or the bit mask).
If the same, just repeat the loop using the next index. Otherwise just exit with a message that the user has failed the LED input sequence.
Sallyqq
15-08-2009, 10:04 AM
I will try on that. This is one part of my program.
for the game part is something like this. The Led blinks follow by the person entering the key then the program telling the person right/wrong. Sorry for the late reply. And thank for the reply.
Note: frequency of sound is not properly set yet.
Game2:
{
putc((char)8,stdprn); //display LEDs 00100000
delay(300);//300ms
putc((char)0,stdprn); //all LEDs off 00000000
delay(300);//300ms
putc((char)4,stdprn); //display LEDs 00000001
delay(300);//300ms
putc((char)0,stdprn); //all LEDs off 00000000
delay(300);//300ms
putc((char)8,stdprn); //display LEDs 00010000
delay(300);//300ms
putc((char)0,stdprn); //all LEDs off 00000000
delay(300);//300ms
printf("\nWhich 3 Leds light up? in sequence:");
scanf("%s",&data);
if (data=='C'||data=='c') <--- first key right, how about telling the person second key and third is right?
{
printf("\n you are so smart");
{
sound(500);
delay(500);
sound(500);
delay(500);
sound(500);
delay(500);
sound(500);
delay(500);
nosound();
}
}
else if (data!='C' || data!='c'); <-- first key wrong. how about telling the person second and third key wrong?
{
printf("\nYour memory fail!");
{
sound(500);
delay(500);
sound(500);
delay(500);
sound(500);
delay(500);
sound(500);
delay(500);
nosound();
}
}
printf("\nPress Y to go next level, N to play again");
printf("\nTo quit press Q");
scanf("%s",&data);
violentk
13-09-2009, 11:05 PM
i cant remember... scan %s takes in string and wait for the carriage return right? i though u can
char data[2]
if (data[0] == 'c' && data[1] == 'b' && data=[2] == 'c'
{
// correct
}
else
{
// try again
}
vBulletin® v3.6.8, Copyright ©2000-2010, Jelsoft Enterprises Ltd.