Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need some help to improve my game in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Anastasia




PostPosted: Sun May 22, 2011 4:33 pm   Post subject: Need some help to improve my game in turing

Hi guys!
I'm trying to make a game in turing based on Zork game. ( But much simpler)
Have some problems though...don't know how to get rid of them...

like in the part where it says "You're facing the east of the house. There is a cracked window. If you want to open and enter the window enter 'in'"
and when I enter 'in' first time the program says "I don't understand" and when I enter it second time the program says what I want for it to say the first time.

PLEASE HELP.....

[b]SORRY FOR ANY GRAMMAR MISTAKES....ENGLISH IS NOT MY FIRST LANGUAGE

Here is what I've got so far.....

Turing:


%outside of the house
%north
procedure northSideOfHouse
    put ""
    put "You're facing the north side of the house."
    put "There are two windows. Both window are boarded and cannot be open."
end northSideOfHouse

%south
procedure southSideOfHouse
    put "You're facing the south side of the house."
    put "The door and the two windows are boarded and cannot be open."
end southSideOfHouse

%east
procedure eastSideOfHouse
    put "You're facing the east of the house."
    put "There is a cracked window. If you want to open and enter the window enter 'in'"
end eastSideOfHouse

%west
procedure westSideOfHouse
    put "You're facing the west side of the house."
    put "There is three boarded windows that cannot be open."
end westSideOfHouse

%kitchen
procedure kitchenOfHouse
    put "You are in the kitchen of the Dark House."
    put "A table seems to have been used for the preparation of food."
    put "A passage leads to the west."
    put "To the east is a small window which is open."
    put "On the table is an elongated brown sack, smelling of hot peppers."
    put "To go west enter 'w'"
end kitchenOfHouse

%living room
procedure livingRoom
    put "You are in the living room. There is a door to the east."
    put "To the south is a wooden door with strange gothic lettering,"
    put "which appears to be nailed shut."
    put "To the west is a big closet door, with a key in it."
    put "In the center of the room is a large oriental rug."
    put "There is a trophy case here."
    put "On hooks above the mantelpiece hangs an elvish sword of great antiquity."
    put "A battery-powered brass lantern is on the trophy case."
    put "There is an issue of 'Toronto Star' dated 11-MAR-02 here."
    put "(choose the direction)"
end livingRoom

%south
procedure livingRoomSouth
    put "The wooden door with stange gothic lettering, is nailed shut, and cannot be open"
end livingRoomSouth

%west
procedure livingRoomWest
    put "In front of you is a big closet door, with a key in it. To open the closet type in 'key'"
end livingRoomWest

% Open Closet
procedure closet
    put "The closet door is open and you can see a dark tunnel leading towards a"
    put "faint light. To enter the close and go through the tunnel enter 'go'"
end closet

% inside the closet
procedure twoDoors
    put "You entered the closet and went though the tunnel."
    put "You are standing in a small room, dimly light by one bulb."
    put "You see two doors. One to your right and one to your lefgt."
    put "Behind the right door, you can hear the scweecking of rats."
    put "Behind the left door, you don't hear anything but you can feel"
    put "that something and behind that door. It is hard desision for"
    put "you to make which door you need to open. "
end twoDoors


% dont understand
procedure doNotUnderstand
    put "I don't understant"
end doNotUnderstand


% Start of the game
colourback (black)
cls
colour (white)
put "Welcome!"

colour (white)
put "You're standing to the south side of the Dark House."
colour (white)

put "There is a note at your feet. To read the note, type in 'read'"

%variables
var action : string
var actionTwo : string
var actionThree : string
var actionFour : string
var actionFive : string


%read the note
put ""
colour (white)
get action
if action = "read" then
    put "Hi there! (Rules of the game) choose the direction: to go north type in 'n',"
    put "to go south type in 's', to go west typein 'w', and to go east type in 'e'"

else
    put "Read the note!"
end if

loop
    % outside of the house
    put ""
    colour (white)
    get actionTwo

    if actionTwo = "n" then
        northSideOfHouse

    elsif actionTwo = "e" then
        eastSideOfHouse

    elsif actionTwo = "w" then
        westSideOfHouse


    elsif actionTwo = "s" then
        southSideOfHouse

    else
        doNotUnderstand

        %kitchen of the house
        put ""
        get actionThree

        if actionThree = "in" then
            kitchenOfHouse

        else
            doNotUnderstand
        end if

        %living room of the house
        put ""
        get actionThree

        if actionThree = "w" then
            livingRoom

        else
            doNotUnderstand

            put ""
            get actionFour

            if actionFour = "s" then
                livingRoomSouth

            elsif actionFour = "w" then
                livingRoomWest

            elsif actionFour = "e" then
                kitchenOfHouse
            else
                doNotUnderstand
            end if

            % Closet
            put ""
            get actionFive

            if actionFive = "key" then
                closet
            else
                doNotUnderstand
            end if
        end if
    end if
end loop



It is not finished....
Also, I would appreciate any suggestions on how to improve my game.

Thanks in advance... Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun May 22, 2011 4:48 pm   Post subject: Re: Need some help to improve my game in turing

Anastasia @ Sun May 22, 2011 4:33 pm wrote:
and when I enter it second time the program says what I want for it to say the first time.

You are handling first and second inputs with different get statements; so your second answer is for a different part of the code, so it's handled differently.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zren




PostPosted: Sun May 22, 2011 4:49 pm   Post subject: RE:Need some help to improve my game in turing

Open up a new program and type break. Run that program. The editor will now enter a sort of debuging mode. Checkmark trace execution. Go back to your origional application and run it. Watch how the logic runs. To exit the debuging mode, you have to close and reopen Turing.

That should hint at your error.

Hint:
- You need a variable to distinguish where you are.
Anastasia




PostPosted: Tue May 24, 2011 10:28 am   Post subject: RE:Need some help to improve my game in turing

To Zren:
ok I did what you said....
still don't understand how change it.....

I don't really understand what you mean by
"You need a variable to distinguish where you are."
Tony




PostPosted: Tue May 24, 2011 10:50 am   Post subject: Re: RE:Need some help to improve my game in turing

Anastasia @ Tue May 24, 2011 10:28 am wrote:
I don't really understand what you mean by
"You need a variable to distinguish where you are."

Right now that information is encoded in the structure of your if-statements (and you leave comments for yourself). You could also track that location (where the character is) in a variable, which makes some things much easier to do. E.g.
code:

put "kitchen of the house" % which could be generalized to 'put character_location'
        put ""
        get actionThree

Not as a part of the final game, but just for the development process. A common approach are flags to turn this information on/off
code:

if DEBUG_MODE then
   put character_location
end if

This gives you two pieces of information:
1. What state you've set your character in.
2. What line of code is executing at the time.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Anastasia




PostPosted: Tue May 24, 2011 5:36 pm   Post subject: RE:Need some help to improve my game in turing

OK
that makes sense
Thanks!
Anastasia




PostPosted: Tue May 24, 2011 5:44 pm   Post subject: Re: Need some help to improve my game in turing

I have a question.....

if want to use an "exit when" statement
can I wright it like that?

Turing:

loop
    put ""
    get actionThree
    if actionThree = "go" then
        twoDoors
       
    else
        doNotUnderstand
         exit when actionThree = "go"
    end if
end loop
Zren




PostPosted: Tue May 24, 2011 5:51 pm   Post subject: RE:Need some help to improve my game in turing

Infinite loop. You never exit because you're contradicting yourself. When a3 is not "go" then you enter the else statement. Then you exit if it does equal "go", which isn't possible since you already filtered out that it isn't "go".

An exit when is pretty much a combined if statement + exit.

Turing:


loop
    exit when true
end loop


loop
    if true then
        exit
    else

    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Anastasia




PostPosted: Tue May 24, 2011 6:00 pm   Post subject: RE:Need some help to improve my game in turing

ok but what if i need to have statement that says: " there are 2 doors" and then exit?
like in my example

should I put exit when at the end or like that:

Turing:

loop
    put ""
    get actionThree
    if actionThree = "go" then
       put  "there are 2 doors"
 exit when actionThree = "go"
       
    else
        doNotUnderstand
       
    end if
end loop


where exit when follows the 'put' statement?
Zren




PostPosted: Tue May 24, 2011 6:03 pm   Post subject: RE:Need some help to improve my game in turing

That's correct. Just going to point out again, don't need to check if it's "go" again, as you already know that when you entered the if statement. Using just exit works the same.

Turing:
loop
    put ""
    get actionThree
    if actionThree = "go" then
        put "there are 2 doors"
        exit
    else
        doNotUnderstand
    end if
end loop
Anastasia




PostPosted: Tue May 24, 2011 6:06 pm   Post subject: RE:Need some help to improve my game in turing

oh OK...

I got it now thanks so much! Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: