Computer Science Canada Need help with turing game |
| Author: | guy88 [ Thu May 19, 2011 8:27 pm ] |
| Post subject: | Need help with turing game |
I want to put invalid input in this potential game, but it doesn't seem to work. Also, if you can, can you help with the arrays? Also, I have a similar copy of the game except in case statements. I need help in putting case statements in case statements. I need help please, I'm not very good at turing and this is due tommorow. I tried everything When I run the program,and i try to put an invalid option, it gives me 4 of the same error message. For the arrays, it doesn't work after the second time I press "n". I tried else, elsif, if choice= (something not needed) var choice : array 1 .. 10 of string put "You walk down the hall, there is a fleshy substance on the walls" put "What do you want to do?" loop get choice (1) cls if choice (1) = "n" then put "You continue walking down the hall" put "what do you want to do?" get choice (2) else put "You cannot do that" end if if choice (1) = "s" then put "there is a expanding layer of flseh on the walls. You probably shouldn't go this way." put "What do you want to do?" get choice (1) else put "You cannot do that" end if if choice (1) = "w" then put "There is a door here. but it's locked. You cannot go there" put "What do you want to do?" get choice (1) else put "You cannot do that" end if if choice (1) = "e" then put "You see the fleshy substance expanding rapidly on the walls. You cannot go there" put "What do you want to do?" get choice (1) else put "You cannot do that" end if if choice (2) = "n" then put "The hall extends further" put "What do you want to do?" get choice (3) else put "You cannot do that" if choice (2) = "s" then put "For a mysterious reason, the door has locked behind you. The fleshy substance has manifested itself across it." put "What do you want to do?" get choice (2) else put "You cannot do that" if choice (2) = "w" then put "The wall is covered by the fleshy substance. You cannot go there" put "What do you want to do?" get choice (2) else put "You cannot do that" if choice (2) = "e" then put "The wall is covered by the fleshy substance. You cannot go there" put "What do you want to do?" get choice (2) else put "You cannot do that" end if if choice (3) = "n" then put "You get a very uncomfortable feeling about the things behind this door. It'd be best if you avoid this for now." put "What do you want to do?" get choice (3) if choice (3) = "s" then put "The ground has been contaminated by the fleshy substance. You can no longer go back" put "What do you want to do?" get choice (3) if choice (3) = "w" then put "You see a cupboard here. There is a peice of paper here." put "What do you want to do?" get choice (4) if choice (3) = "e" then put "This part of the room is blocked off by debris. You are not strong enough to move them." put "What do you want to do" get choice (3) end if end if end if end if end if end if end if end loop I'm using Turing 4.1.1 btw. thanks for the help! |
|
| Author: | Tony [ Thu May 19, 2011 8:41 pm ] | ||
| Post subject: | Re: Need help with turing game | ||
guy88 @ Thu May 19, 2011 8:27 pm wrote: When I run the program,and i try to put an invalid option, it gives me 4 of the same error message. How many times does your code contain
part? guy88 @ Thu May 19, 2011 8:27 pm wrote: end if end if end if end if end if end if end if That looks like some kind of a problem in the making. As for arrays, there are tutorials linked to from The Turing Walkthrough |
|||
| Author: | guy88 [ Thu May 19, 2011 8:48 pm ] |
| Post subject: | Re: Need help with turing game |
if choice (1) = "n" then put "You continue walking down the hall" put "what do you want to do?" get choice (2) When I put something other than "n,s,w,e", it shows You cannot do that You cannot do that You cannot do that You cannot do that Thanks for your consideration. |
|
| Author: | crossley7 [ Thu May 19, 2011 8:58 pm ] |
| Post subject: | RE:Need help with turing game |
Move those end ifs to the actual end of the if. it looks like you are checking the same character within an if and so will result false every time for most of the ifs. press F2 in your program to indent it and it may help you understand where to put those end ifs instead of the very end of the program |
|
| Author: | guy88 [ Thu May 19, 2011 9:08 pm ] |
| Post subject: | Re: Need help with turing game |
I did that, and when I used an invalid input, it ends the program and shades the part of the program saying get choice (2). l oop get choice (1) cls if choice (1) = "n" then put "You continue walking down the hall" put "what do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (2) else put "You cannot do that" end if if choice (1) = "s" then put "there is a expanding layer of flseh on the walls. You probably shouldn't go this way." put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (1) else put "You cannot do that" end if if choice (1) = "w" then put "There is a door here. but it's locked. You cannot go there" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (1) else put "You cannot do that" end if if choice (1) = "e" then put "You see the fleshy substance expanding rapidly on the walls. You cannot go there" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (1) else put "You cannot do that" end if if choice (2) = "n" then put "The hall extends further" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (3) else put "You cannot do that" end if if choice (2) = "s" then put "For a mysterious reason, the door has locked behind you. The fleshy substance has manifested itself across it." put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (2) else put "You cannot do that" end if if choice (2) = "w" then put "The wall is covered by the fleshy substance. You cannot go there" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (2) else put "You cannot do that" end if if choice (2) = "e" then put "The wall is covered by the fleshy substance. You cannot go there" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (2) else put "You cannot do that" end if if choice (3) = "n" then put "You get a very uncomfortable feeling about the things behind this door. It'd be best if you avoid this for now." put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (3) else put "You cannot do that" end if if choice (3) = "s" then put "The ground has been contaminated by the fleshy substance. You can no longer" put "go back" put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (3) else put "You cannot do that" end if if choice (3) = "w" then put "You see a cupboard here. There is a peice of paper here." put "What do you want to do?" put "n- north" put "s- south" put "e- east" put "w- west" get choice (4) else put "You cannot do that" end if if choice (3) = "e" then put "This part of the room is blocked off by debris. You are not strong enough to move them." put "What do you want to do" put "n- north" put "s- south" put "e- east" put "w- west" get choice (3) else put "You cannot do that" end if end loop |
|
| Author: | Tony [ Thu May 19, 2011 9:21 pm ] |
| Post subject: | Re: Need help with turing game |
You are just describing various symptoms of problems. Do you have some questions about them? guy88 @ Thu May 19, 2011 9:08 pm wrote: it ends the program and shades the part of the program saying
get choice (2). Shading usually means a run-time error. What does the error message say? |
|
| Author: | guy88 [ Thu May 19, 2011 9:36 pm ] |
| Post subject: | Re: Need help with turing game |
Thanks for the help. I changed my method. it should work now. |
|
| Author: | HRI [ Fri May 20, 2011 8:01 am ] |
| Post subject: | RE:Need help with turing game |
Just a hint for the future, look how many times you repeat "What do you want to do? n-north w-west e-east s-south". Consider making a procedure to write these 5 lines for you, so that when you need them you only need to put one line of code to call the procedure. |
|