Computer Science Canada lights game (help) |
Author: | turing91 [ Fri Jan 12, 2007 11:08 pm ] | ||||
Post subject: | lights game (help) | ||||
i am writing a program using the parallel port for my computers class and i got myself stuck. For the program, we needed to use 1 button an 8 LED lights. My program flashes random led lights, and you need to press the key on the keyboard that corresponds to the light shown before the next light appears. i have 3 main parts, the button, random lights, and keyboard commands. the part i need help with is connecting the keyboard commands with the flashing lights, such as
or something along that line. My full code is:
please help me cause my teachers is too lazy to help anyone in the class. |
Author: | Ultrahex [ Sat Jan 13, 2007 2:38 pm ] | ||||||
Post subject: | Re: lights game (help) | ||||||
You have 3 infinite loops, the first one is never left, so i would recommend combining them otherwise code after will never be read, or exiting loops under a condition. when you have:
you could replace with:
but since you want to check whether or not its the right light, you should be doing something like:
this will check whether or not the a character is pressed, and the no1 which corresponds to the last output to the board (which is the number of the led im guessing if i look at your code) Hope This Helps. |
Author: | turing91 [ Sat Jan 13, 2007 7:14 pm ] | ||
Post subject: | Re: lights game (help) | ||
ok i tired the statement, and it works, but i'm trying to make it if you press it at the wrong time the procedure ends or process ends if possible. this code puts random numbers, but it puts "you lose" after every number, also without the else statement, i have to wait a certain amount of time before the letter shows up, is it because of the delay?
|
Author: | turing91 [ Sun Jan 14, 2007 12:02 pm ] |
Post subject: | RE:lights game (help) |
can some please help me, i am really stuck. I know some of you know how to help me. |
Author: | Ultrahex [ Sun Jan 14, 2007 1:14 pm ] | ||
Post subject: | Re: lights game (help) | ||
This is a very rough way to do it, i do not recommend doing it this way, but by looking at this way i hope you can find a better way to do it, the idea is the same, just its not the correct way to do.
|
Author: | turing91 [ Sun Jan 14, 2007 2:05 pm ] | ||||
Post subject: | Re: lights game (help) | ||||
thanks a lot, it actually works now, but how would you make it where if you get the letter wrong it stops the game instead of saying "you lose"? i tried this but it still
|
Author: | Ultrahex [ Sun Jan 14, 2007 2:15 pm ] | ||
Post subject: | Re: lights game (help) | ||
Well the easiest way would be to actually make a boolean called isEndofGame or isGameOver. the reason why i put is before is to make sure its boolean in terms of reading the code. set it to false on start, and then make a exit when isGameOver in the outer infinite loop ontop of that exit.
|
Author: | turing91 [ Sun Jan 14, 2007 3:54 pm ] | ||
Post subject: | Re: lights game (help) | ||
ok i'm confused. what kind of variable should gameover be? boolean? i tried this but it doesnt change anything...
god dammit i want to finish this project already ![]() |
Author: | Ultrahex [ Sun Jan 14, 2007 4:39 pm ] | ||
Post subject: | Re: lights game (help) | ||
Something like this.....
|
Author: | turing91 [ Sun Jan 14, 2007 5:40 pm ] | ||
Post subject: | Re: lights game (help) | ||
alright, i finished it! My final game is... i hope it works if you change the put Rand.Int, with parallelput Rand.Int, or i'm screwed XD thanks for the help Hltrahex!
|
Author: | Clayton [ Sun Jan 14, 2007 6:19 pm ] |
Post subject: | Re: lights game (help) |
I'm not too sure, as I haven't dealt with peripherals in Turing, but I believe parallelput takes an integer argument, so Rand.Int should be okay to pass... Also, his name is Ultrahex, not Hltrahex ![]() |
Author: | turing91 [ Mon Jan 15, 2007 6:32 pm ] | ||
Post subject: | RE:lights game (help) | ||
yeah, i tested it out at school and i needed to add another var so the button ends and the actual game starts.
and sorry bout the misspelling, i was typing fast. |