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

Username:   Password: 
 RegisterRegister   
 Hang Man!!!!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
C00733




PostPosted: Thu Jun 01, 2006 8:28 pm   Post subject: Hang Man!!!!!!

I'm trying to figure out how to put out the alphabet and then cross out the letters they chose. Please give some pointers!!!!!!!!!! I also want to know how to keep an array of words!!! I also need help on how to keep track of how many guesses they take!!!

%%%%%%%%%%%%%%%%%%%%%%
%Variable Decloration%
%%%%%%%%%%%%%%%%%%%%%%

var word : string %variable for the word
var guess : string %their guess
var s : int %to find out if they guessed a letter in the word
word := "shark" % the word they have to guess

%%%%%%%%%%%%%%%%%%%%%%%
%%%Main Body Program%%%
%%%%%%%%%%%%%%%%%%%%%%%

put "This program is to see if you the user can guess the word!" %instructions
put skip %skips a line
put "The first word is always a capital letter!!" %instructions
put skip %skips a line
put "This word has : 5 letters!" %instructions
put skip %skips a line
put "Guess the letters for the 5 letter word!" % instructions
loop %loop
get guess %their guess
s := 0
for i : 1 .. length (word)% loops until they pick all the right letters
if guess = word (i .. i) then %if they guess a certian letter
put "You guessed letter # ", i, "!" %tells them that they guessed the certain letter
s := 1
end if %ends if
end for %ends for
if s = 0 then %if they didn't guess the letter
put "You did not guess the letter!!" %if they didn't guess the letter it will say
end if %ends the if
end loop %ends the loop
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Jun 01, 2006 8:36 pm   Post subject: (No subject)

Hello and welcome.

To start things off, please use [ code] tags in the future when posting code. Also, please Indent your code.

For information on how to create and use arrays, consult the [Turing Walkthrough]. It will guide you through the process quite well.
As for the letters, I would advise using an array as well. Since it looks like you're using text-only, an easy way to indicate which letters have been selected is to change their colour, perhaps to blue or red.

A general pointer about your code:
code:

if guess = word (i .. i) then

% Is equivalent to:

if guess = word (i) then

The variable 's' is not descriptively named. Teachers are notorious for cracking down on this - and for good reason. Badly named variables leads to confusion in their use, and hence buggy code.

When you get your programme working, may I suggest improving things a litte:
- create a list of possbile words to select, perhaps storing them in an array. Use Rand.Int() to randomly select one of the words, and assign this to 'word'. This will add more complexity and interactivity to your game.
- improve upon your interface. The text if fine, but to make it look good, add some locates and colours.
XeroX




PostPosted: Fri Jun 02, 2006 7:32 pm   Post subject: (No subject)

in order to keep track of the guesses, simply add to the value of an integer right after they enter their guess. you may want to limit their guesses, display a message such as "You have 5 guesses left" as well, it would be really cool if you actually made a hangman picture that got rid of a limb every time you don't get the correct letter
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: