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

Username:   Password: 
 RegisterRegister   
 Glitch help in my program!
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TerranceN




PostPosted: Wed Jan 13, 2010 7:33 pm   Post subject: Re: Glitch help in my program!

getch works like this:

Turing:
var input : string (1)

getch (input)

if (input = 'a') then
    put "b"
else
    put "c"
end if


Notice that this stops the program and waits for the user to press a key

Input.KeyDown() works like this:

Turing:
var input : array char of boolean

loop

    Input.KeyDown(input)
   
    if (input('a')) then
        put "b"
    else
        put "c"
    end if

end loop


Notice that it has to be looped because it does not wait for the user to press a key, instead it checks what keys are pressed the moment it is called.

You can use either method, but hopefully now you understand how they work.

Also, what if the user does not press escape? (just a hypothetical question to get you thinking about all the possibilities for input, I'm not looking for an answer)
Sponsor
Sponsor
Sponsor
sponsor
Ktomislav




PostPosted: Wed Jan 13, 2010 7:35 pm   Post subject: Re: Glitch help in my program!

Turing:
Input.KeyDown (key)
if key (KEY_ESC) then
...
end if
xBalmungx




PostPosted: Wed Jan 13, 2010 7:48 pm   Post subject: Re: Glitch help in my program!

Well THANK YOU SOOOOOOOO MUCH OMG THAT ALMOST KILLED ME Razz
THAT HELPS SOOOo MUCH YESSSSSSSSSSSS
lol, um now I need help with a battle sequence in the program,

i was thinking of doing something with

the variables

var z:string <<<<Zombie/Monster
var z_maxhealth :int:=10<<<The zombies/monsters maximum health
var z_defense :int := 1 <<<<<The defense which will deduct your attack by its value
var z_attack :int := 2<<<<<<What the zombie/monster will hit you
var z_health:int<<<<Zombie/monster health after damage result
var maxHealth: int :=100<<<<Your maximum health
var health:int<<<Your health after damage result
var knife1:string<<<<The code for accessing the weapon
var knife1_att : int :=5 <<<< Your weapons attack, which will be deducted by the enemies defense, and will deduct the enemies health
var knife1_def:int :=1 <<<<<Defensive properties of the weapon, same as the monster/zombies defense
var damage:int<<<<<If necessary
TerranceN




PostPosted: Wed Jan 13, 2010 8:18 pm   Post subject: Re: Glitch help in my program!

For the battle sequence I would recommend using a function/procedure, if you don't know what that is check out Cervantes' Functions and Procedures Tutorial

This will allow you to to call it anytime (so you don't have to copy and paste large chunks of code over the place), and if you pass a boolean to it, you can choose whether to just show the results of the battle, or show turn by turn (I believe you asked for this in another thread, correct me if I'm wrong). Also, try to have the function not interfere with any global variables, so it could be easily reused if you ever make another project like this.

Almost all of those values could be either randomly generated in the function or passed to the function. Aim for something like this:

Turing:
% Parameters:
%---------------
% true, therefore only show results of battle
% health, to let the function know our health before the battle

% Return value: our health after the battle
health := RandomEncounter(true, health)


As for specifically how to code it, that is up to you.
xBalmungx




PostPosted: Wed Jan 13, 2010 8:36 pm   Post subject: Re: Glitch help in my program!

Do I have to use the function/procedure, or can i just write the code in it? I just really need an example to base my code off of, basically how a program would look like using those variables, I just need a "guide" if you will, I can figure out the rest and stuff
TheGuardian001




PostPosted: Wed Jan 13, 2010 8:48 pm   Post subject: Re: Glitch help in my program!

You can write the code in, but then it would only happen once and only at a specific time...

As for a guide, Only you know what you want out of this. Write it out, step by step, in plain English, and then think of what you need to do to make Turing do that.
TerranceN




PostPosted: Wed Jan 13, 2010 8:54 pm   Post subject: Re: Glitch help in my program!

You could just write the code, but it could get kinda messy, and imo its always a good time to learn code organization, but its your choice.

I will help debug and fix what you write, but you have to write it. I am not going to create your program logic for you. My suggestion though is to start out really simple, maybe each turn decrease your health by one, but the enemies by 5 (so use constant values to start), and just use "enemy" for the name. Once you understand how to get that working, adding features will be much easier than trying to do it all at once.
xBalmungx




PostPosted: Wed Jan 13, 2010 9:37 pm   Post subject: Re: Glitch help in my program!

Alright so this is what I have so far, I have to go to sleep now, but, I think it's a good start. Didn't get a chance to test it though...

if command = "Attack" then
loop
z_health := z_maxhealth + z_defense - knife1_att
health := maxHealth + knife1_def - z_attack

put "Your sucessfully hit the enemy, and reduce his health to ",z_health,"."
put "The enemy has made a counter hit! and has reduced your health to ",health,"."
exit when z_health <=0
exit when health <=0
end loop
else
if command = "Rest" then
put "Rest"
end if
end if
Sponsor
Sponsor
Sponsor
sponsor
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 2 of 2  [ 23 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: