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

Username:   Password: 
 RegisterRegister   
 Killing a process?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Naga




PostPosted: Sat Jan 13, 2007 5:58 pm   Post subject: Killing a process?

Is there any way to stop a process from running?

I'm doing this game where there's a counter. The counter counts down from 30. However, I want a way to stop it. The game, which is what it's for, has the user move away from an enemy, and you have 30 seconds to do this. If you get hit, the counter has to stop and it loads a small questionnaire, which is like punishment for being caught. I have the counter in a separate process. Is there a way to kill that process once the player gets hit?
Sponsor
Sponsor
Sponsor
sponsor
Prince Pwn




PostPosted: Sat Jan 13, 2007 6:54 pm   Post subject: Re: Killing a process?

If you press F10 and look up condition it teaches you how to "make a process sleep":
Turing:

% The "condition" program.
monitor resource
    export request, release

    var available : boolean := true
    var nowAvailable : condition

    procedure request (name : string)
        if available then
            put "Worker ", name, " needs the pickaxe and it is available"
        else
            put "Worker ", name, " needs the pickaxe and must wait"
            wait nowAvailable           % Go to sleep
        end if
        put "Worker ", name, " now has the pickaxe"
        assert available
        available := false              % Allocate resource
    end request

    procedure release (name : string)
        assert not available            % Resource is allocated
        available := true               % Free the resource
        put "Worker ", name, " is now finished with the pickaxe"
        signal nowAvailable             % Wake up one process
        % If any are sleeping
    end release

end resource

process worker (name : string)
    loop
        put "Worker ", name, " is working without the pickaxe"
        delay (Rand.Int (1000, 3000))
        resource.request (name)                % Block until available
        put "Worker ", name, " is using the pickaxe"
        delay (Rand.Int (1000, 3000))
        resource.release (name)
    end loop
end worker

setscreen ("text")
put "Several workers are digging a pit.  Often they need a pickaxe, but"
put "they only brought one.  Thus they must share it.", skip
fork worker ("A")               % Activate one worker
fork worker ("B")               % Activate another worker
fork worker ("C")               % Activate another worker
neufelni




PostPosted: Sat Jan 13, 2007 6:54 pm   Post subject: RE:Killing a process?

First of all, you shouldn't be using a process for your counter. You shouldn't be using processes at all, since they are not very good in Turing. Just put the counter in your main loop or in the procedure where your enemy attack is. And it would probably be a good idea to have a boolean variable to tell if you've been hit. Then just add an if statement. You would then have something like this:
pseudo:
var hit : boolean := false
var count : int := 30
...
if enemy hits you then
    hit := true
end if

if not hit then
    count -= 1
end if

And then when the user is done answering the question, you set the variable hit back to true and reset your count variable to 30.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: