Forum > Beginners
Problems making a Hangman game in Pascal
mathex14:
Hi! i'm new here....
Here is the deal, im making a hangman game in pascal, but im with some problems, well, i want someone to tell me, how do i do that lines below, i mean like if the word has 5 letters then there would be 5 lines, i have made this using for, but the real problem is, to make a line become a letter, i was capable of making a code write the lines(however im not sure if its possible to change the lines to letters with it), i also made it appear a letter if digited, and if its on the word(if i put "m", when the word "monkey" is the word then "m" will appear, but not in the correct places and the lines continue there).
Here is the part of the code:
ch:=length(animals[vp]);
writeln('');
sentenca:= ' _ ';
for tam:=1 to ch do
begin
write(sentenca);
end;
writeln('');
word:= animals[vp];
read(try);
for tam:=1 to ch do
begin
if (word[tam] = tentativa) then
writeln(word[tam]);
end;
____________
I just dont know how to make the word appear where the line is, or if i should make the lines in a different way.... could someone please help me? maybe give me some tips of what should i use to fix the problem?
Sorry if my english is bad, it's not my first language.
taazz:
the easiest way out is to use a string. Then use the fillchar procedure to fill it with the underscore character and use it as an array to replace the underscore with you letter. Easy and fast.
mathex14:
--- Quote from: taazz on June 08, 2014, 04:08:11 pm ---the easiest way out is to use a string. Then use the fillchar procedure to fill it with the underscore character and use it as an array to replace the underscore with you letter. Easy and fast.
--- End quote ---
Thanks for helping me Taazz, but im not very good at pascal yet, and i didnt understood what you said very well, i mean, could you explain a little better, i tried in her search for the fillchar procedure, and i used it and stuff, but i couldnt do what i needed, because i think i dont know the logic to substitute tha line("_") for the correspondent char, so if you could explain me in a more detailed it would be cool, and if someone else could help me as well, i would appreciate :D
taazz:
Every string variable can be accessed as an array of characters eg
--- Code: ---var
MyVar : String;
begin
MyVar := 'This is a test';
MyVar[2] :='_';
MyVar[3] :='_';
writeln(MyVar);
end;
--- End code ---
So if you have a string filled with underscores you can simple say MyString[12] := 'a'; changing the 12th underscore to a; after that you need to writeln the new data on the screen so the user can see what he got right if anything.
mathex14:
--- Quote from: taazz on June 09, 2014, 08:59:11 am ---Every string variable can be accessed as an array of characters eg
--- Code: ---var
MyVar : String;
begin
MyVar := 'This is a test';
MyVar[2] :='_';
MyVar[3] :='_';
writeln(MyVar);
end;
--- End code ---
So if you have a string filled with underscores you can simple say MyString[12] := 'a'; changing the 12th underscore to a; after that you need to writeln the new data on the screen so the user can see what he got right if anything.
--- End quote ---
I did it! Thanks a lot, one more question, to upgrade the doll(making his arms appear and stuff) and letters, i should use clrscr right?
Navigation
[0] Message Index
[#] Next page