Computer Science Canada Hangman Game |
Author: | hossack [ Wed Mar 25, 2009 9:02 am ] | ||
Post subject: | Hangman Game | ||
So when I restart the game, and I guess a letter wrong, it doesn't start drawing the stickman. To me it should because the procedure restarts, but it doesn't work any advice?
|
Author: | hossack [ Thu Mar 26, 2009 7:20 am ] | ||
Post subject: | RE:Hangman Game | ||
I got this to work. but I can only replay it once. Any reason?
|
Author: | DemonWasp [ Thu Mar 26, 2009 7:46 am ] |
Post subject: | RE:Hangman Game |
Calling MainGame from MainGame to do repetition is a recipe for disaster. Instead, what you should do is have a loop around your game code; if the player wants to continue, you allow the loop to do its thing, if not then you can just exit the loop. Alternately, you could have your game in a procedure called MainGame, but then your "Continue? (Y/N)" question should be asked in a main loop that knows to exit if the player is done playing. |
Author: | hossack [ Thu Mar 26, 2009 7:53 am ] |
Post subject: | RE:Hangman Game |
It works when I lose, but not when I win. I can only replay it once if I win off the start, but if I lose and then win and try to replay it doesn't work |
Author: | hossack [ Thu Mar 26, 2009 8:44 am ] |
Post subject: | RE:Hangman Game |
Also it doesn't replay if you win and then replay and then lose and try to replay again |
Author: | hossack [ Thu Mar 26, 2009 9:16 am ] |
Post subject: | RE:Hangman Game |
K so forget all that. I keep getting an error saying Attempt to read psat eof. How can I fix that? |
Author: | hossack [ Thu Mar 26, 2009 9:42 am ] | ||
Post subject: | RE:Hangman Game | ||
forget that too. Everything is working, its just when I hit N to exit it doesn't exit
|
Author: | DemonWasp [ Thu Mar 26, 2009 9:53 am ] |
Post subject: | RE:Hangman Game |
This one you get to fix on your own, but I'll point you in the right direction: 1. What does it mean when it says that you're trying to read past eof (eof means "end of file")? 2. When do you open a file? What do you read from it? 3. Why doesn't that always work, particularly if you replay? |
Author: | hossack [ Thu Mar 26, 2009 9:55 am ] |
Post subject: | RE:Hangman Game |
Why ask me questions? 1. Fixed That 2. Thats good 3. Im stuck and have no idea |
Author: | DemonWasp [ Thu Mar 26, 2009 10:23 am ] |
Post subject: | RE:Hangman Game |
I'm not asking you questions, I'm providing the series of questions you're supposed to ask yourself to figure out the problem on your own. It's a learning exercise to get you to the point where you can figure out what questions to ask yourself to solve the problem on your own. Think more carefully about what happens in your program. Here's an outline: 1. Opens a file for reading. 2. Read a random number of lines from the file. 3. Play the game with the last line read. 4. Replay? If yes, go to 2. Think about how many lines are in the file and how many lines are consumed in step #2. Do you see the problem yet? |
Author: | Tallguy [ Thu Mar 26, 2009 11:05 am ] |
Post subject: | RE:Hangman Game |
zip ur files so we can have the .txt file |
Author: | hossack [ Thu Mar 26, 2009 12:36 pm ] |
Post subject: | Re: Hangman Game |
Heres the zip |
Author: | hossack [ Fri Mar 27, 2009 7:14 am ] |
Post subject: | RE:Hangman Game |
anyone know how I could fix this? edit: I tried using the return thing instead of using MainGame to replay it, but it started it from the very start of the game. |
Author: | DemonWasp [ Fri Mar 27, 2009 8:05 am ] |
Post subject: | RE:Hangman Game |
I've already given you how to find the error, but since you don't seem to be interested in figuring it out yourself, I'll supply the answer: 1. You have x lines in the file. It doesn't particularly matter what the value of x is. 2. You keep reading lines from the file, heedless of the fact that you will eventually hit the end of file. You have no code path for dealing with this eventuality. 3. When your program gets to the end of the file, it does exactly what you would expect and says "attempt to read past end of file!" To solve this, it's probably easiest to just read all of the possible strings into an array of strings at the beginning of the program, then choose a random string from the array every time you want to play the game. |
Author: | hossack [ Fri Mar 27, 2009 8:13 am ] |
Post subject: | RE:Hangman Game |
My teacher hasn't taught us Array's and I had to learn proc on my own. Ill try to find out how to use Array's by reading the help thing in turing. Thanks |
Author: | hossack [ Fri Mar 27, 2009 9:16 am ] |
Post subject: | RE:Hangman Game |
hmm it seems to be working fine now. I didn't change anything and it hasn't error'd out. I don't understand array's so i guess its working |
Author: | DemonWasp [ Fri Mar 27, 2009 10:02 am ] | ||
Post subject: | RE:Hangman Game | ||
Arrays are simple. Here's a primer: An array is just a set of variables that you refer to in some order. So you could have line1, line2, line3, etc. Or, you could have an array called line, with elements line(1), line(2), line(3). What I was suggesting goes like this:
|